/src/NzbDrone.Api.Test/ClientSchemaTests/SchemaBuilderFixture.cs

https://github.com/NzbDrone/NzbDrone · C# · 70 lines · 56 code · 14 blank · 0 comment · 43 complexity · 61baf55fb1d66cb519523c260a885c2d MD5 · raw file

  1. using FluentAssertions;
  2. using NUnit.Framework;
  3. using NzbDrone.Core.Annotations;
  4. using NzbDrone.Test.Common;
  5. using Sonarr.Http.ClientSchema;
  6. namespace NzbDrone.Api.Test.ClientSchemaTests
  7. {
  8. [TestFixture]
  9. public class SchemaBuilderFixture : TestBase
  10. {
  11. [Test]
  12. public void should_return_field_for_every_property()
  13. {
  14. var schema = SchemaBuilder.ToSchema(new TestModel());
  15. schema.Should().HaveCount(2);
  16. }
  17. [Test]
  18. public void schema_should_have_proper_fields()
  19. {
  20. var model = new TestModel
  21. {
  22. FirstName = "Bob",
  23. LastName = "Poop"
  24. };
  25. var schema = SchemaBuilder.ToSchema(model);
  26. schema.Should().Contain(c => c.Order == 1 && c.Name == "lastName" && c.Label == "Last Name" && c.HelpText == "Your Last Name" && (string)c.Value == "Poop");
  27. schema.Should().Contain(c => c.Order == 0 && c.Name == "firstName" && c.Label == "First Name" && c.HelpText == "Your First Name" && (string)c.Value == "Bob");
  28. }
  29. [Test]
  30. public void schema_should_have_nested_fields()
  31. {
  32. var model = new NestedTestModel();
  33. model.Name.FirstName = "Bob";
  34. model.Name.LastName = "Poop";
  35. var schema = SchemaBuilder.ToSchema(model);
  36. schema.Should().Contain(c => c.Order == 0 && c.Name == "name.firstName" && c.Label == "First Name" && c.HelpText == "Your First Name" && (string)c.Value == "Bob");
  37. schema.Should().Contain(c => c.Order == 1 && c.Name == "name.lastName" && c.Label == "Last Name" && c.HelpText == "Your Last Name" && (string)c.Value == "Poop");
  38. schema.Should().Contain(c => c.Order == 2 && c.Name == "quote" && c.Label == "Quote" && c.HelpText == "Your Favorite Quote");
  39. }
  40. }
  41. public class TestModel
  42. {
  43. [FieldDefinition(0, Label = "First Name", HelpText = "Your First Name")]
  44. public string FirstName { get; set; }
  45. [FieldDefinition(1, Label = "Last Name", HelpText = "Your Last Name")]
  46. public string LastName { get; set; }
  47. public string Other { get; set; }
  48. }
  49. public class NestedTestModel
  50. {
  51. [FieldDefinition(0)]
  52. public TestModel Name { get; set; } = new TestModel();
  53. [FieldDefinition(1, Label = "Quote", HelpText = "Your Favorite Quote")]
  54. public string Quote { get; set; }
  55. }
  56. }