GetProjectSettingSchemaCommandTests.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections.Generic;
  2. using LLM.Editor.Commands;
  3. using LLM.Editor.Data;
  4. using NUnit.Framework;
  5. namespace LLM.Editor.Tests.Unit
  6. {
  7. [TestFixture]
  8. public class GetProjectSettingSchemaCommandTests
  9. {
  10. private CommandContext _context;
  11. [SetUp]
  12. public void SetUp()
  13. {
  14. _context = new CommandContext();
  15. }
  16. [Test]
  17. public void Execute_WithValidApiClass_ReturnsSuccessAndSchema()
  18. {
  19. // Arrange
  20. var command = new GetProjectSettingSchemaCommand { apiClassName = "UnityEngine.Time" };
  21. // Act
  22. var result = command.Execute(_context);
  23. // Assert
  24. Assert.AreEqual(CommandOutcome.Success, result);
  25. Assert.IsInstanceOf<Dictionary<string, object>>(_context.CurrentSubject);
  26. var schema = (Dictionary<string, object>)_context.CurrentSubject;
  27. Assert.IsTrue(schema.ContainsKey("fixedDeltaTime"));
  28. Assert.IsTrue(schema.ContainsKey("timeScale"));
  29. }
  30. [Test]
  31. public void Execute_WithInvalidApiClass_ReturnsError()
  32. {
  33. // Arrange
  34. var command = new GetProjectSettingSchemaCommand { apiClassName = "UnityEngine.NonExistentClass" };
  35. // Act
  36. var result = command.Execute(_context);
  37. // Assert
  38. Assert.AreEqual(CommandOutcome.Error, result);
  39. Assert.IsTrue(_context.ErrorMessage.Contains("Could not find a class named"));
  40. }
  41. [Test]
  42. public void Execute_WithNullApiClass_ReturnsError()
  43. {
  44. // Arrange
  45. var command = new GetProjectSettingSchemaCommand { apiClassName = null };
  46. // Act
  47. var result = command.Execute(_context);
  48. // Assert
  49. Assert.AreEqual(CommandOutcome.Error, result);
  50. Assert.IsTrue(_context.ErrorMessage.Contains("'apiClassName' is required"));
  51. }
  52. }
  53. }