Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Commit

Permalink
Bug/issue45 (#46)
Browse files Browse the repository at this point in the history
* 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
gregsdennis committed Jan 10, 2017
1 parent 82f4153 commit d42c5e0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
44 changes: 44 additions & 0 deletions Manatee.Json.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Manatee.Json.Path;
using Manatee.Json.Schema;
Expand Down Expand Up @@ -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);
}
}
}
16 changes: 16 additions & 0 deletions Manatee.Json.Tests/Files/baseSchema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
13 changes: 13 additions & 0 deletions Manatee.Json.Tests/Files/refSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"prop3": {
"enum": [
"ændring",
"test"
],
"type": "string"
}
}
}
6 changes: 6 additions & 0 deletions Manatee.Json.Tests/Manatee.Json.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion Manatee.Json/Schema/JsonSchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#if IOS || CORE
using System.Net.Http;
#endif
using System.Text;

namespace Manatee.Json.Schema
{
Expand All @@ -43,7 +44,7 @@ public static Func<string, string> Download
#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; }
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit d42c5e0

Please sign in to comment.