Permalink
Browse files

Migration to XUnit (#580)

* Migrated to xunit test projects

* Fixed tests

* Added xunit test project

* Fixed test project

* Fixed unit test

* Added test script

* Updated tests

* Fixed tests

* Removed test project from demo

* Copy always

* Fixed unit tests

* Added ArrayBaseType and DictionaryBaseType

* Fixed unit tests

* Fixed unit tests

* Fixed unit tests
  • Loading branch information...
RSuter committed Dec 11, 2017
1 parent 44e7722 commit 1a251418bc25445acd8076194c33ed6ab7c01f53
Showing with 2,178 additions and 2,546 deletions.
  1. +2 −1 .gitignore
  2. +3 −0 build/04_RunTests.bat
  3. +5 −6 ...harp/AbstractGenerationTests.cs → NJsonSchema.CodeGeneration.CSharp.Tests/AbstractSchemaTests.cs}
  4. +43 −44 ...deGeneration.Tests/CSharp → NJsonSchema.CodeGeneration.CSharp.Tests}/AdditionalPropertiesTests.cs
  5. +245 −0 src/NJsonSchema.CodeGeneration.CSharp.Tests/AllOfTests.cs
  6. +4 −5 ...Schema.CodeGeneration.Tests/CSharp → NJsonSchema.CodeGeneration.CSharp.Tests}/AnnotationsTests.cs
  7. +160 −317 ...ma.CodeGeneration.Tests/CSharp → NJsonSchema.CodeGeneration.CSharp.Tests}/CSharpGeneratorTests.cs
  8. +79 −0 src/NJsonSchema.CodeGeneration.CSharp.Tests/DefaultPropertyTests.cs
  9. +56 −17 ....Tests/CSharp/CSharpEnumGeneratorTests.cs → NJsonSchema.CodeGeneration.CSharp.Tests/EnumTests.cs}
  10. +62 −63 ...deGeneration.Tests/CSharp → NJsonSchema.CodeGeneration.CSharp.Tests}/InheritanceInterfaceTests.cs
  11. +26 −0 src/NJsonSchema.CodeGeneration.CSharp.Tests/NJsonSchema.CodeGeneration.CSharp.Tests.csproj
  12. +106 −107 ...ropertyRequiredTests.cs → NJsonSchema.CodeGeneration.CSharp.Tests/ObjectPropertyRequiredTests.cs}
  13. +105 −107 ...ropertyRequiredTests.cs → NJsonSchema.CodeGeneration.CSharp.Tests/StringPropertyRequiredTests.cs}
  14. +14 −0 src/NJsonSchema.CodeGeneration.CSharp.Tests/UnitTest1.cs
  15. +3 −4 ...ema.CodeGeneration.Tests/CSharp → NJsonSchema.CodeGeneration.CSharp.Tests}/ValueGeneratorTests.cs
  16. +9 −0 src/NJsonSchema.CodeGeneration.CSharp/CSharpGeneratorSettings.cs
  17. +3 −1 src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs
  18. +0 −8 src/NJsonSchema.CodeGeneration.Tests/App.config
  19. +0 −110 src/NJsonSchema.CodeGeneration.Tests/CSharp/AllOfTests.cs
  20. +0 −50 src/NJsonSchema.CodeGeneration.Tests/CSharp/EnumTests.cs
  21. +7 −12 src/NJsonSchema.CodeGeneration.Tests/DefaultGenerationTests.cs
  22. +21 −23 src/NJsonSchema.CodeGeneration.Tests/DefaultValueGeneratorTests.cs
  23. +34 −38 src/NJsonSchema.CodeGeneration.Tests/EnumGenerationTests.cs
  24. +31 −32 src/NJsonSchema.CodeGeneration.Tests/InheritanceSerializationTests.cs
  25. +20 −152 src/NJsonSchema.CodeGeneration.Tests/NJsonSchema.CodeGeneration.Tests.csproj
  26. BIN src/NJsonSchema.CodeGeneration.Tests/NJsonSchema.snk
  27. +0 −36 src/NJsonSchema.CodeGeneration.Tests/Properties/AssemblyInfo.cs
  28. +7 −8 src/NJsonSchema.CodeGeneration.Tests/Samples/SampleTests.cs
  29. +4 −5 src/NJsonSchema.CodeGeneration.Tests/TypeScript/AbstractGenerationTests.cs
  30. +27 −28 src/NJsonSchema.CodeGeneration.Tests/TypeScript/ClassGenerationTests.cs
  31. +3 −4 src/NJsonSchema.CodeGeneration.Tests/TypeScript/ClassOrderTests.cs
  32. +9 −10 src/NJsonSchema.CodeGeneration.Tests/TypeScript/ConstructorInterfaceTests.cs
  33. +20 −21 src/NJsonSchema.CodeGeneration.Tests/TypeScript/DateCodeGenerationTests.cs
  34. +19 −20 src/NJsonSchema.CodeGeneration.Tests/TypeScript/DateTimeCodeGenerationTests.cs
  35. +20 −24 src/NJsonSchema.CodeGeneration.Tests/TypeScript/DictionaryTests.cs
  36. +23 −24 src/NJsonSchema.CodeGeneration.Tests/TypeScript/ExtensionCodeTests.cs
  37. +9 −14 src/NJsonSchema.CodeGeneration.Tests/TypeScript/NullabilityTests.cs
  38. +7 −8 src/NJsonSchema.CodeGeneration.Tests/TypeScript/TypeScriptDictionaryTests.cs
  39. +28 −30 src/NJsonSchema.CodeGeneration.Tests/TypeScript/TypeScriptGeneratorTests.cs
  40. +5 −6 src/NJsonSchema.CodeGeneration.Tests/TypeScript/TypeScriptObjectTests.cs
  41. +0 −4 src/NJsonSchema.CodeGeneration.Tests/packages.config
  42. +6 −19 src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj
  43. +0 −4 src/NJsonSchema.Demo/NJsonSchema.Demo.csproj
  44. +20 −21 src/NJsonSchema.Tests/Conversion/ArrayTypeToSchemaTests.cs
  45. +9 −10 src/NJsonSchema.Tests/Conversion/SchemaReferenceTests.cs
  46. +71 −72 src/NJsonSchema.Tests/Conversion/TypeToSchemaTests.cs
  47. +8 −9 src/NJsonSchema.Tests/Generation/AbstractGenerationTests.cs
  48. +33 −34 src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs
  49. +28 −29 src/NJsonSchema.Tests/Generation/AttributeGenerationTests.cs
  50. +14 −17 src/NJsonSchema.Tests/Generation/ContractResolverTests.cs
  51. +5 −7 src/NJsonSchema.Tests/Generation/DefaultReflectionServiceTests.cs
  52. +3 −4 src/NJsonSchema.Tests/Generation/DefaultTypeNameGeneratorTests.cs
  53. +25 −26 src/NJsonSchema.Tests/Generation/EnumGenerationTests.cs
  54. +6 −7 src/NJsonSchema.Tests/Generation/EnumTests.cs
  55. +4 −5 src/NJsonSchema.Tests/Generation/ExceptionTypeTests.cs
  56. +5 −6 src/NJsonSchema.Tests/Generation/ExcplicitInterfacePropertyTests.cs
  57. +3 −5 src/NJsonSchema.Tests/Generation/FieldGenerationTests.cs
  58. +8 −9 src/NJsonSchema.Tests/Generation/FindCommonBaseTypeTests.cs
  59. +12 −16 src/NJsonSchema.Tests/Generation/FlattenInheritanceHierarchyTests.cs
  60. +6 −7 src/NJsonSchema.Tests/Generation/GenericTests.cs
  61. +7 −8 src/NJsonSchema.Tests/Generation/IgnoredPropertyTests.cs
  62. +20 −22 src/NJsonSchema.Tests/Generation/InheritanceTests.cs
  63. +3 −4 src/NJsonSchema.Tests/Generation/InterfaceTests.cs
  64. +5 −6 src/NJsonSchema.Tests/Generation/JsonPropertyAttributeTests.cs
  65. +6 −9 src/NJsonSchema.Tests/Generation/KnownTypeGenerationTests.cs
  66. +11 −12 src/NJsonSchema.Tests/Generation/NullPropertyTests.cs
  67. +24 −25 src/NJsonSchema.Tests/Generation/PrimitiveTypeGenerationTests.cs
  68. +16 −17 src/NJsonSchema.Tests/Generation/PropertyNamesGenerationTests.cs
  69. +19 −20 ...onSchema.Tests/Generation/{DataToJsonSchemaGeneratorTests.cs → SampleJsonSchemaGeneratorTests.cs}
  70. +18 −19 src/NJsonSchema.Tests/Generation/SchemaGenerationTests.cs
  71. +3 −4 src/NJsonSchema.Tests/Generation/ShouldSerializeTests.cs
  72. +11 −13 src/NJsonSchema.Tests/Generation/TypeMapperTests.cs
  73. +13 −14 src/NJsonSchema.Tests/Generation/XmlDocTests.cs
  74. +52 −53 src/NJsonSchema.Tests/Generation/XmlObjectTests.cs
  75. +6 −7 src/NJsonSchema.Tests/Infrastructure/ReflectionCacheTests.cs
  76. +40 −169 src/NJsonSchema.Tests/NJsonSchema.Tests.csproj
  77. +0 −36 src/NJsonSchema.Tests/Properties/AssemblyInfo.cs
  78. +26 −31 src/NJsonSchema.Tests/References/LocalReferencesTests.cs
  79. +14 −16 src/NJsonSchema.Tests/Schema/DataContractTests.cs
  80. +9 −10 src/NJsonSchema.Tests/Schema/JsonPathUtilitiesGetJsonPathTests.cs
  81. +14 −17 src/NJsonSchema.Tests/Schema/JsonPathUtilitiesGetObjectFromJsonPathTests.cs
  82. +53 −55 src/NJsonSchema.Tests/Schema/JsonSchemaTests.cs
  83. +14 −15 src/NJsonSchema.Tests/Serialization/ExtensionDataTests.cs
  84. +0 −14 src/NJsonSchema.Tests/Suite/TestSuiteTests.cs
  85. +41 −42 src/NJsonSchema.Tests/Validation/ArrayValidationTests.cs
  86. +7 −8 src/NJsonSchema.Tests/Validation/EnumValidationTests.cs
  87. +17 −18 src/NJsonSchema.Tests/Validation/FormatBase64Tests.cs
  88. +7 −8 src/NJsonSchema.Tests/Validation/FormatDateTests.cs
  89. +5 −6 src/NJsonSchema.Tests/Validation/FormatDateTimeTests.cs
  90. +5 −6 src/NJsonSchema.Tests/Validation/FormatEmailTests.cs
  91. +5 −6 src/NJsonSchema.Tests/Validation/FormatGuidTests.cs
  92. +5 −6 src/NJsonSchema.Tests/Validation/FormatHostnameTests.cs
  93. +5 −6 src/NJsonSchema.Tests/Validation/FormatIpV4Tests.cs
  94. +5 −6 src/NJsonSchema.Tests/Validation/FormatIpV6Tests.cs
  95. +5 −6 src/NJsonSchema.Tests/Validation/FormatTimeSpanTests.cs
  96. +13 −14 src/NJsonSchema.Tests/Validation/FormatTimeTests.cs
  97. +5 −6 src/NJsonSchema.Tests/Validation/FormatUriTests.cs
  98. +26 −27 src/NJsonSchema.Tests/Validation/InheritanceTests.cs
  99. +11 −12 src/NJsonSchema.Tests/Validation/LineInformationTest.cs
  100. +5 −7 src/NJsonSchema.Tests/Validation/NullPropertyTests.cs
  101. +6 −7 src/NJsonSchema.Tests/Validation/NumberTests.cs
  102. +20 −21 src/NJsonSchema.Tests/Validation/ObjectValidationTests.cs
  103. +9 −10 src/NJsonSchema.Tests/Validation/PatternPropertyValidationTests.cs
  104. +7 −8 src/NJsonSchema.Tests/Validation/SchemaTests.cs
  105. +3 −4 src/NJsonSchema.Tests/Validation/UniqueItemsTests.cs
  106. +49 −50 src/NJsonSchema.Tests/Validation/ValueTypeValidationTests.cs
  107. +47 −19 src/NJsonSchema.sln
  108. +1 −1 src/NJsonSchema/Infrastructure/XmlDocumentationExtensions.cs
View
@@ -14,4 +14,5 @@ src/packages/Newtonsoft.Json**
[Bb]in/
[Oo]bj/
/src/packages
.vs
.vs
/src/NJsonSchema.CodeGeneration.Tests2
View
@@ -0,0 +1,3 @@
dotnet test "%~dp0/../src\NJsonSchema.Tests\NJsonSchema.Tests.csproj" -c Release
dotnet test "%~dp0/../src\NJsonSchema.CodeGeneration\NJsonSchema.CodeGeneration.csproj" -c Release
dotnet test "%~dp0/../src\NJsonSchema.CodeGeneration.CSharp.Tests\NJsonSchema.CodeGeneration.CSharp.Tests.csproj" -c Release
@@ -1,18 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.CodeGeneration.CSharp;
using System.Threading.Tasks;
using Xunit;
namespace NJsonSchema.CodeGeneration.Tests.CSharp.Generation
{
[TestClass]
public class AbstractGenerationTests
public class AbstractSchemaTests
{
public abstract class AbstractClass
{
public string Foo { get; set; }
}
[TestMethod]
[Fact]
public async Task When_class_is_abstract_then_is_abstract_CSharp_keyword_is_generated()
{
/// Arrange
@@ -23,7 +22,7 @@ public async Task When_class_is_abstract_then_is_abstract_CSharp_keyword_is_gene
var code = generator.GenerateFile("AbstractClass");
/// Assert
Assert.IsTrue(code.Contains("public abstract partial class AbstractClass"));
Assert.True(code.Contains("public abstract partial class AbstractClass"));
}
}
}
@@ -1,45 +1,44 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NJsonSchema.CodeGeneration.CSharp;
namespace NJsonSchema.CodeGeneration.Tests.CSharp
{
[TestClass]
public class AdditionalPropertiesTests
{
[TestMethod]
public async Task When_additionalProperties_schema_is_set_for_object_then_special_property_is_rendered()
{
//// Arrange
var json =
@"{
""properties"": {
""Pet"": {
""type"": ""object"",
""properties"": {
""id"": {
""type"": ""integer"",
""format"": ""int64""
},
""category"": {
""type"": ""string""
}
},
""additionalProperties"": {
""type"": ""string""
}
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
var code = generator.GenerateFile("Person");
//// Assert
Assert.IsTrue(code.Contains("[Newtonsoft.Json.JsonExtensionData]"));
Assert.IsTrue(code.Contains("public System.Collections.Generic.IDictionary<string, string> AdditionalProperties"));
}
}
using System.Threading.Tasks;
using NJsonSchema.CodeGeneration.CSharp;
using Xunit;
namespace NJsonSchema.CodeGeneration.Tests.CSharp
{
public class AdditionalPropertiesTests
{
[Fact]
public async Task When_additionalProperties_schema_is_set_for_object_then_special_property_is_rendered()
{
//// Arrange
var json =
@"{
""properties"": {
""Pet"": {
""type"": ""object"",
""properties"": {
""id"": {
""type"": ""integer"",
""format"": ""int64""
},
""category"": {
""type"": ""string""
}
},
""additionalProperties"": {
""type"": ""string""
}
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
var code = generator.GenerateFile("Person");
//// Assert
Assert.True(code.Contains("[Newtonsoft.Json.JsonExtensionData]"));
Assert.True(code.Contains("public System.Collections.Generic.IDictionary<string, string> AdditionalProperties"));
}
}
}
@@ -0,0 +1,245 @@
using System.Threading.Tasks;
using NJsonSchema.CodeGeneration.CSharp;
using Xunit;
namespace NJsonSchema.CodeGeneration.Tests.CSharp
{
public class AllOfTests
{
[Fact]
public async Task When_allOf_has_two_schemas_then_referenced_schema_is_inherited()
{
//// Arrange
var json =
@"{
""allOf"": [
{
""$ref"": ""#/definitions/B""
},
{
""type"": ""object"",
""required"": [
""prop""
],
""properties"": {
""prop"": {
""type"": ""string"",
""minLength"": 1,
""maxLength"": 30
},
""prop2"": {
""type"": ""string""
}
}
}
],
""definitions"": {
""B"": {
""properties"": {
""foo"": {
""type"": ""string""
}
}
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
var code = generator.GenerateFile("A");
//// Assert
Assert.False(code.Contains("Anonymous"));
Assert.True(code.Contains("A : B"));
}
[Fact]
public async Task When_allOf_has_one_schema_then_it_is_inherited()
{
//// Arrange
var json =
@"{
""type"": ""object"",
""discriminator"": ""type"",
""required"": [
""prop"",
""type""
],
""properties"": {
""prop"": {
""type"": ""string"",
""minLength"": 1,
""maxLength"": 30
},
""prop2"": {
""type"": ""string""
},
""type"": {
""type"": ""string""
}
},
""allOf"": [
{
""$ref"": ""#/definitions/B""
}
],
""definitions"": {
""B"": {
""type"": ""object"",
""properties"": {
""foo"": {
""type"": ""string""
}
}
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(json);
//// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
var code = generator.GenerateFile("A");
//// Assert
Assert.False(code.Contains("Anonymous"));
Assert.True(code.Contains("A : B"));
}
[Fact]
public async Task When_all_of_has_multiple_refs_then_the_properties_should_expand_to_single_class()
{
//// Arrange
var json = @"{
'$schema': 'http://json-schema.org/draft-04/schema#',
'id': 'http://some.domain.com/foo.json',
'type': 'object',
'additionalProperties': false,
'definitions': {
'tRef1': {
'properties': {
'val1': {
'type': 'string',
}
}
},
'tRef2': {
'properties': {
'val2': {
'type': 'string',
}
}
},
'tRef3': {
'properties': {
'val3': {
'type': 'string',
}
}
}
},
'properties' : {
'tAgg': {
'allOf': [
{'$ref': '#/definitions/tRef1'},
{'$ref': '#/definitions/tRef2'},
{'$ref': '#/definitions/tRef3'}
]
}
}
}";
//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var settings = new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco, Namespace = "ns" };
var generator = new CSharpGenerator(schema, settings);
var output = generator.GenerateFile("Foo");
//// Assert
Assert.True(output.Contains("public partial class TAgg"));
Assert.True(output.Contains("public string Val1 { get; set; }"));
Assert.True(output.Contains("public string Val2 { get; set; }"));
Assert.True(output.Contains("public string Val3 { get; set; }"));
}
[Fact]
public async Task When_more_properties_are_defined_in_allOf_and_type_none_then_all_of_contains_all_properties_in_generated_code()
{
//// Arrange
var json = @"{
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'properties': {
'prop1' : { 'type' : 'string' }
},
'allOf': [
{
'type': 'object',
'properties': {
'baseProperty' : { 'type' : 'string' }
}
},
{
'properties': {
'prop2' : { 'type' : 'string' }
}
}
]
}";
//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile("Foo").Replace("\r\n", "\n");
//// Assert
Assert.True(code.Contains(
@" public partial class Foo : Anonymous
{
[Newtonsoft.Json.JsonProperty(""prop1"", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Prop1 { get; set; }
[Newtonsoft.Json.JsonProperty(""prop2"", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Prop2 { get; set; }
".Replace("\r", string.Empty)));
Assert.True(code.Contains("class Anonymous"));
}
[Fact]
public async Task When_allOf_schema_is_object_type_then_it_is_an_inherited_class_in_generated_code()
{
//// Arrange
var json = @"{
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'properties': {
'prop1' : { 'type' : 'string' }
},
'allOf': [
{
'$ref': '#/definitions/Bar'
}
],
'definitions': {
'Bar': {
'type': 'object',
'properties': {
'prop2' : { 'type' : 'string' }
}
}
}
}";
//// Act
var schema = await JsonSchema4.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile("Foo");
//// Assert
Assert.True(code.Contains("class Foo : Bar"));
Assert.True(code.Contains("public string Prop1 { get; set; }"));
Assert.True(code.Contains("public string Prop2 { get; set; }"));
}
}
}
Oops, something went wrong.

0 comments on commit 1a25141

Please sign in to comment.