-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
816 additions
and
664 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,153 @@ | ||
*.tt text eol=crlf | ||
* text=auto | ||
*.cs diff=csharp | ||
*.tt text eol=crlf | ||
*.sln text eol=crlf | ||
*.csproj text eol=crlf | ||
*.vbproj text eol=crlf | ||
*.vcxproj text eol=crlf | ||
*.vcproj text eol=crlf | ||
*.dbproj text eol=crlf | ||
*.fsproj text eol=crlf | ||
*.lsproj text eol=crlf | ||
*.wixproj text eol=crlf | ||
*.modelproj text eol=crlf | ||
*.sqlproj text eol=crlf | ||
*.wmaproj text eol=crlf | ||
*.xproj text eol=crlf | ||
*.props text eol=crlf | ||
*.filters text eol=crlf | ||
*.vcxitems text eol=crlf | ||
*.bat text | ||
*.coffee text | ||
*.css text | ||
*.htm text | ||
*.html text | ||
*.inc text | ||
*.ini text | ||
*.js text | ||
*.jsx text | ||
*.json text | ||
*.less text | ||
*.php text | ||
*.pl text | ||
*.py text | ||
*.rb text | ||
*.sass text | ||
*.scm text | ||
*.scss text | ||
*.sh text | ||
*.sql text | ||
*.styl text | ||
*.tpl text | ||
*.ts text | ||
*.twig text | ||
*.xml text | ||
*.xhtml text | ||
*.markdown text | ||
*.md text | ||
*.mdwn text | ||
*.mdown text | ||
*.mkd text | ||
*.mkdn text | ||
*.mdtxt text | ||
*.mdtext text | ||
*.txt text | ||
AUTHORS text | ||
CHANGELOG text | ||
CHANGES text | ||
CONTRIBUTING text | ||
COPYING text | ||
INSTALL text | ||
license text | ||
LICENSE text | ||
NEWS text | ||
readme text | ||
*README* text | ||
TODO text | ||
*.dot text | ||
*.ejs text | ||
*.haml text | ||
*.handlebars text | ||
*.hbs text | ||
*.hbt text | ||
*.jade text | ||
*.latte text | ||
*.mustache text | ||
*.phtml text | ||
*.tmpl text | ||
.csslintrc text | ||
.eslintrc text | ||
.jscsrc text | ||
.jshintrc text | ||
.jshintignore text | ||
.stylelintrc text | ||
*.bowerrc text | ||
*.cnf text | ||
*.conf text | ||
*.config text | ||
.editorconfig text | ||
.gitattributes text | ||
.gitconfig text | ||
.gitignore text | ||
.htaccess text | ||
*.npmignore text | ||
*.yaml text | ||
*.yml text | ||
Makefile text | ||
makefile text | ||
*.ai binary | ||
*.bmp binary | ||
*.eps binary | ||
*.gif binary | ||
*.ico binary | ||
*.jng binary | ||
*.jp2 binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.jpx binary | ||
*.jxr binary | ||
*.pdf binary | ||
*.png binary | ||
*.psb binary | ||
*.psd binary | ||
*.svg text | ||
*.svgz binary | ||
*.tif binary | ||
*.tiff binary | ||
*.wbmp binary | ||
*.webp binary | ||
*.kar binary | ||
*.m4a binary | ||
*.mid binary | ||
*.midi binary | ||
*.mp3 binary | ||
*.ogg binary | ||
*.ra binary | ||
*.3gpp binary | ||
*.3gp binary | ||
*.as binary | ||
*.asf binary | ||
*.asx binary | ||
*.fla binary | ||
*.flv binary | ||
*.m4v binary | ||
*.mng binary | ||
*.mov binary | ||
*.mp4 binary | ||
*.mpeg binary | ||
*.mpg binary | ||
*.swc binary | ||
*.swf binary | ||
*.webm binary | ||
*.7z binary | ||
*.gz binary | ||
*.rar binary | ||
*.tar binary | ||
*.zip binary | ||
*.ttf binary | ||
*.eot binary | ||
*.otf binary | ||
*.woff binary | ||
*.woff2 binary | ||
*.exe binary | ||
*.pyc binary |
198 changes: 99 additions & 99 deletions
198
src/NJsonSchema.Tests/Conversion/ArrayTypeToSchemaTests.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 |
---|---|---|
@@ -1,99 +1,99 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace NJsonSchema.Tests.Conversion | ||
{ | ||
[TestClass] | ||
public class ArrayTypeToSchemaTests | ||
{ | ||
[TestMethod] | ||
public async Task When_converting_type_inheriting_from_dictionary_then_it_should_be_correct() | ||
{ | ||
//// Act | ||
var schema = await JsonSchema4.FromTypeAsync<DictionarySubType>(); | ||
var data = schema.ToJson(); | ||
|
||
//// Assert | ||
Assert.AreEqual(JsonObjectType.Object, schema.Type); | ||
Assert.IsNotNull(schema.AllOf.First().ActualSchema.Properties["Foo"]); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_array_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Array"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_collection_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Collection"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("List"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_interface_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("InterfaceList"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_enumerable_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Enumerable"); | ||
} | ||
|
||
public async Task When_converting_array_then_items_must_correctly_be_loaded(string propertyName) | ||
{ | ||
//// Act | ||
var schema = await JsonSchema4.FromTypeAsync<MyType>(); | ||
var schemaData = schema.ToJson(); | ||
|
||
//// Assert | ||
var property = schema.Properties[propertyName]; | ||
|
||
Assert.AreEqual(JsonObjectType.Array | JsonObjectType.Null, property.Type); | ||
Assert.AreEqual(JsonObjectType.Object, property.ActualSchema.Item.ActualSchema.Type); | ||
Assert.IsTrue(schema.Definitions.Any(d => d.Key == "MySubtype")); | ||
Assert.AreEqual(JsonObjectType.String | JsonObjectType.Null, property.ActualSchema.Item.ActualSchema.Properties["Id"].Type); | ||
} | ||
|
||
public class DictionarySubType : DictionaryType | ||
{ | ||
|
||
} | ||
|
||
public class DictionaryType : Dictionary<string, IList<string>> | ||
{ | ||
public string Foo { get; set; } | ||
} | ||
|
||
public class MyType | ||
{ | ||
public MySubtype Reference { get; set; } | ||
|
||
public MySubtype[] Array { get; set; } | ||
|
||
public Collection<MySubtype> Collection { get; set; } | ||
|
||
public List<MySubtype> List { get; set; } | ||
|
||
public IList<MySubtype> InterfaceList { get; set; } | ||
|
||
public IEnumerable<MySubtype> Enumerable { get; set; } | ||
} | ||
|
||
public class MySubtype | ||
{ | ||
public string Id { get; set; } | ||
} | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace NJsonSchema.Tests.Conversion | ||
{ | ||
[TestClass] | ||
public class ArrayTypeToSchemaTests | ||
{ | ||
[TestMethod] | ||
public async Task When_converting_type_inheriting_from_dictionary_then_it_should_be_correct() | ||
{ | ||
//// Act | ||
var schema = await JsonSchema4.FromTypeAsync<DictionarySubType>(); | ||
var data = schema.ToJson(); | ||
|
||
//// Assert | ||
Assert.AreEqual(JsonObjectType.Object, schema.Type); | ||
Assert.IsNotNull(schema.AllOf.First().ActualSchema.Properties["Foo"]); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_array_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Array"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_collection_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Collection"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("List"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_interface_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("InterfaceList"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_converting_enumerable_list_then_items_must_correctly_be_loaded() | ||
{ | ||
await When_converting_array_then_items_must_correctly_be_loaded("Enumerable"); | ||
} | ||
|
||
public async Task When_converting_array_then_items_must_correctly_be_loaded(string propertyName) | ||
{ | ||
//// Act | ||
var schema = await JsonSchema4.FromTypeAsync<MyType>(); | ||
var schemaData = schema.ToJson(); | ||
|
||
//// Assert | ||
var property = schema.Properties[propertyName]; | ||
|
||
Assert.AreEqual(JsonObjectType.Array | JsonObjectType.Null, property.Type); | ||
Assert.AreEqual(JsonObjectType.Object, property.ActualSchema.Item.ActualSchema.Type); | ||
Assert.IsTrue(schema.Definitions.Any(d => d.Key == "MySubtype")); | ||
Assert.AreEqual(JsonObjectType.String | JsonObjectType.Null, property.ActualSchema.Item.ActualSchema.Properties["Id"].Type); | ||
} | ||
|
||
public class DictionarySubType : DictionaryType | ||
{ | ||
|
||
} | ||
|
||
public class DictionaryType : Dictionary<string, IList<string>> | ||
{ | ||
public string Foo { get; set; } | ||
} | ||
|
||
public class MyType | ||
{ | ||
public MySubtype Reference { get; set; } | ||
|
||
public MySubtype[] Array { get; set; } | ||
|
||
public Collection<MySubtype> Collection { get; set; } | ||
|
||
public List<MySubtype> List { get; set; } | ||
|
||
public IList<MySubtype> InterfaceList { get; set; } | ||
|
||
public IEnumerable<MySubtype> Enumerable { get; set; } | ||
} | ||
|
||
public class MySubtype | ||
{ | ||
public string Id { get; set; } | ||
} | ||
} | ||
} |
Oops, something went wrong.