-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add System.Text.Json ExtensionData attribute tests (#1312)
* Add System.Text.Json extension attribute tests * Fix test Co-authored-by: Rico Suter <mail@rsuter.com>
- Loading branch information
1 parent
3f7f55e
commit 39d09be
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...NJsonSchema.Tests/Generation/SystemTextJson/SystemTextJsonExtensionDataGenerationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#if !NET46 && !NET452 | ||
|
||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using NJsonSchema.Generation; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.Tests.Generation.SystemTextJson | ||
{ | ||
public class SystemTextJsonExtensionDataGenerationTests | ||
{ | ||
public class ClassWithExtensionData | ||
{ | ||
public string Foo { get; set; } | ||
|
||
[JsonExtensionData] | ||
public IDictionary<string, object> ExtensionData { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void SystemTextJson_When_class_has_property_with_JsonExtensionDataAttribute_on_property_then_AdditionalProperties_schema_is_set() | ||
{ | ||
//// Act | ||
var schema = JsonSchema.FromType<ClassWithExtensionData>(new JsonSchemaGeneratorSettings | ||
{ | ||
SchemaType = SchemaType.OpenApi3, | ||
SerializerOptions = new System.Text.Json.JsonSerializerOptions() | ||
}); | ||
|
||
//// Assert | ||
Assert.Equal(1, schema.ActualProperties.Count); | ||
Assert.True(schema.AllowAdditionalProperties); | ||
Assert.True(schema.AdditionalPropertiesSchema.ActualSchema.IsAnyType); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters