ComponentDataProviderTests.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using NUnit.Framework;
  2. using UnityEngine;
  3. using LLM.Editor.Analysis;
  4. using System.Collections.Generic;
  5. namespace LLM.Editor.Tests.Unit
  6. {
  7. [TestFixture]
  8. public class ComponentDataProviderTests
  9. {
  10. private GameObject _testObject;
  11. private ComponentDataProvider _provider;
  12. [SetUp]
  13. public void SetUp()
  14. {
  15. _testObject = new GameObject("TestObject");
  16. _provider = new ComponentDataProvider();
  17. }
  18. [TearDown]
  19. public void TearDown()
  20. {
  21. if (_testObject != null)
  22. {
  23. Object.DestroyImmediate(_testObject);
  24. }
  25. }
  26. [Test]
  27. public void GetContext_WithValidComponent_ReturnsPropertyDictionary()
  28. {
  29. // Arrange
  30. const string qualifier = "UnityEngine.Transform";
  31. // Act
  32. var context = _provider.GetContext(_testObject, qualifier);
  33. // Assert
  34. Assert.IsInstanceOf<Dictionary<string, object>>(context);
  35. var data = (Dictionary<string, object>)context;
  36. // Check for some known, serialized properties of the Transform component.
  37. // The names (e.g., "m_LocalPosition") come from how Unity serializes them.
  38. Assert.IsTrue(data.ContainsKey("m_LocalPosition"));
  39. Assert.IsTrue(data.ContainsKey("m_LocalRotation"));
  40. Assert.IsTrue(data.ContainsKey("m_LocalScale"));
  41. }
  42. [Test]
  43. public void GetContext_WithNonExistentComponent_ReturnsErrorString()
  44. {
  45. // Arrange
  46. var qualifier = "UnityEngine.Rigidbody"; // This component is not on the object
  47. // Act
  48. var context = _provider.GetContext(_testObject, qualifier);
  49. // Assert
  50. Assert.IsInstanceOf<string>(context);
  51. Assert.IsTrue(((string)context).Contains("not found on GameObject"));
  52. }
  53. [Test]
  54. public void GetContext_WithInvalidTypeName_ReturnsErrorString()
  55. {
  56. // Arrange
  57. var qualifier = "Invalid.Component.Name";
  58. // Act
  59. var context = _provider.GetContext(_testObject, qualifier);
  60. // Assert
  61. Assert.IsInstanceOf<string>(context);
  62. Assert.IsTrue(((string)context).Contains("Component type 'Invalid.Component.Name' not found"));
  63. }
  64. [Test]
  65. public void GetContext_WithNonGameObjectTarget_ReturnsErrorString()
  66. {
  67. // Arrange
  68. var material = new Material(Shader.Find("Standard")); // A non-GameObject target
  69. // Act
  70. var context = _provider.GetContext(material, "UnityEngine.Transform");
  71. // Assert
  72. Assert.IsInstanceOf<string>(context);
  73. Assert.IsTrue(((string)context).Contains("Target must be a GameObject"));
  74. }
  75. }
  76. }