Permalink
Browse files

Bug/issue45 (#46)

* Added tests to cover issue cases.

* updated and resaved test files with proper encoding

* Added encoding to WebClient.  HttpClient (portable & core) unchanged.
  • Loading branch information...
1 parent 82f4153 commit d42c5e04f56d3bff7c457ffbf59ba4f245963b9c @gregsdennis committed on GitHub Jan 10, 2017
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using Manatee.Json.Path;
using Manatee.Json.Schema;
@@ -210,5 +211,48 @@ public void Issue31_JsonPathArrayOperatorShouldWorkOnObjects_Constructed()
Assert.AreEqual(new JsonArray { "red", 19.95 }, results);
}
+
+ [TestMethod]
+ [DeploymentItem("Files\\baseSchema.json")]
+ [DeploymentItem("Files\\refSchema.json")]
+ public void Issue45a_Utf8SupportInReferenceSchemaEnums()
+ {
+ // replace with your full path to the schema file.
+ const string fileName = @"C:\Users\gregd\OneDrive\Projects\Manatee.Json\Manatee.Json.Tests\Files\baseSchema.json";
+ var directory = System.IO.Path.GetDirectoryName(fileName);
+ Directory.SetCurrentDirectory(directory);
+
+ const string jsonString = "{\"prop1\": \"ændring\", \"prop2\": {\"prop3\": \"ændring\"}}";
+ var schema = JsonSchemaFactory.Load(fileName);
+ var json = JsonValue.Parse(jsonString);
+
+ var result = schema.Validate(json);
+ Assert.IsTrue(result.Valid);
+ }
+
+ [TestMethod]
+ [DeploymentItem("Files\\baseSchema.json")]
+ [DeploymentItem("Files\\refSchema.json")]
+ public void Issue45b_Utf8SupportInReferenceSchemaEnums()
+ {
+ const string fileName = @"baseSchema.json";
+
+ const string jsonString = "{\"prop1\": \"ændring\", \"prop2\": {\"prop3\": \"ændring\"}}";
+ var schema = JsonSchemaFactory.Load(fileName);
+ var json = JsonValue.Parse(jsonString);
+
+ var result = schema.Validate(json);
+
+ Console.WriteLine(schema.ToJson(null));
+ var refSchema = ((JsonSchemaReference)((JsonSchema)schema).Properties["prop2"].Type).Resolved;
+ Console.WriteLine(refSchema.ToJson(null));
+ Console.WriteLine(json);
+ foreach (var error in result.Errors)
+ {
+ Console.WriteLine(error);
+ }
+
+ Assert.IsTrue(result.Valid);
+ }
}
}
@@ -0,0 +1,16 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "prop1": {
+ "enum": [
+ "ændring",
+ "test"
+ ],
+ "type": "string"
+ },
+ "prop2": {
+ "$ref": "refSchema.json"
+ }
+ }
+}
@@ -0,0 +1,13 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "prop3": {
+ "enum": [
+ "ændring",
+ "test"
+ ],
+ "type": "string"
+ }
+ }
+}
@@ -94,6 +94,12 @@
<Compile Include="Schema\TestSuite\SchemaTest.cs" />
<Compile Include="Schema\TestSuite\SchemaTestSet.cs" />
<Compile Include="Serialization\JsonDeserializerTest.cs" />
+ <None Include="Files\baseSchema.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Files\refSchema.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
<None Include="Test References\InvalidSchemaValidatedClass.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -25,6 +25,7 @@
#if IOS || CORE
using System.Net.Http;
#endif
+using System.Text;
namespace Manatee.Json.Schema
{
@@ -43,7 +44,7 @@ public static class JsonSchemaOptions
#if IOS || CORE
get { return _download ?? (_download = uri => new HttpClient().GetStringAsync(uri).Result); }
#else
- get { return _download ?? (_download = uri => new WebClient().DownloadString(uri)); }
+ get { return _download ?? (_download = uri => new WebClient {Encoding = Encoding.UTF8}.DownloadString(uri)); }
#endif
set { _download = value; }
}
View
@@ -1,7 +1,7 @@
#Manatee.Json
[![Join the chat at https://gitter.im/gregsdennis/Manatee.Json](https://badges.gitter.im/gregsdennis/Manatee.Json.svg)](https://gitter.im/gregsdennis/Manatee.Json?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-![Build Status](https://ci.appveyor.com/api/projects/status/39glrlct0u3leyla/branch/master?svg=true)
+[![littlecrabsolutions MyGet Build Status](https://www.myget.org/BuildSource/Badge/littlecrabsolutions?identifier=7898edc2-8d91-411c-88c9-2023d9d9fd41)](https://www.myget.org/)
The primary goal of Manatee.Json is to make working with JSON simple and intuitive for the developer. This library recognizes that JSON is much more than just a mechanism for data transfer.

0 comments on commit d42c5e0

Please sign in to comment.