-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started implementation
- Loading branch information
Showing
15 changed files
with
753 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
UnitsNet.Serialization.SystemTextJson.Tests/Infrastructure/TestObject.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,11 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public sealed class TestObject | ||
{ | ||
public Frequency? NullableFrequency { get; set; } | ||
public Frequency NonNullableFrequency { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
UnitsNet.Serialization.SystemTextJson.Tests/Infrastructure/TestObjectWithIComparable.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,12 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public sealed class TestObjectWithIComparable | ||
{ | ||
public IComparable Value { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
UnitsNet.Serialization.SystemTextJson.Tests/Infrastructure/TestObjectWithThreeIComparable.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,16 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public sealed class TestObjectWithThreeIComparable | ||
{ | ||
public IComparable Value1 { get; set; } | ||
|
||
public IComparable Value2 { get; set; } | ||
|
||
public IComparable Value3 { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ialization.SystemTextJson.Tests/Infrastructure/TestObjectWithValueAndUnitAsIComparable.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,18 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public sealed class TestObjectWithValueAndUnitAsIComparable : IComparable | ||
{ | ||
public double Value { get; set; } | ||
public string Unit { get; set; } | ||
|
||
public int CompareTo(object obj) | ||
{ | ||
return ((IComparable)Value).CompareTo(obj); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...Net.Serialization.SystemTextJson.Tests/Infrastructure/TestObjectWithValueAsIComparable.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,32 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public sealed class TestObjectWithValueAsIComparable : IComparable | ||
{ | ||
public int Value { get; set; } | ||
|
||
public int CompareTo(object obj) | ||
{ | ||
return ((IComparable)Value).CompareTo(obj); | ||
} | ||
|
||
// Needed for verifying that the deserialized object is the same, should not affect the serialization code | ||
public override bool Equals(object obj) | ||
{ | ||
if (obj == null || GetType() != obj.GetType()) | ||
{ | ||
return false; | ||
} | ||
return Value.Equals(((TestObjectWithValueAsIComparable)obj).Value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Value.GetHashCode(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
UnitsNet.Serialization.SystemTextJson.Tests/Infrastructure/UnitsNetJsonBaseTest.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,29 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System.Text.Json; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure | ||
{ | ||
public abstract class UnitsNetJsonBaseTest | ||
{ | ||
private readonly JsonSerializerOptions _jsonSerializerSettings; | ||
|
||
protected UnitsNetJsonBaseTest() | ||
{ | ||
_jsonSerializerSettings = new JsonSerializerOptions {WriteIndented = true}; | ||
_jsonSerializerSettings.Converters.Add(new UnitsNetJsonConverterFactory()); | ||
//_jsonSerializerSettings.Converters.Add(new UnitsNetIQuantityJsonConverter()); | ||
//_jsonSerializerSettings.Converters.Add(new UnitsNetIComparableJsonConverter()); | ||
} | ||
|
||
protected string SerializeObject(object obj) | ||
{ | ||
return JsonSerializer.Serialize(obj, _jsonSerializerSettings).Replace("\r\n", "\n"); | ||
} | ||
|
||
protected T DeserializeObject<T>(string json) | ||
{ return JsonSerializer.Deserialize<T>(json, _jsonSerializerSettings); | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace UnitsNet.Serialization.SystemTextJson.Tests | ||
{ | ||
public sealed class TestObject | ||
{ | ||
public Frequency? NullableFrequency { get; set; } | ||
public Frequency NonNullableFrequency { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...Net.Serialization.SystemTextJson.Tests/UnitsNet.Serialization.SystemTextJson.Tests.csproj
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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UnitsNet.Serialization.SystemTextJson\UnitsNet.Serialization.SystemTextJson.csproj" /> | ||
<ProjectReference Include="..\UnitsNet\UnitsNet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
26 changes: 26 additions & 0 deletions
26
UnitsNet.Serialization.SystemTextJson.Tests/UnitsNetJsonBaseTest.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,26 @@ | ||
using System.Text.Json; | ||
|
||
namespace UnitsNet.Serialization.SystemTextJson.Tests | ||
{ | ||
public abstract class UnitsNetJsonBaseTest | ||
{ | ||
private readonly JsonSerializerOptions _jsonSerializerSettings; | ||
|
||
protected UnitsNetJsonBaseTest() | ||
{ | ||
_jsonSerializerSettings = new JsonSerializerOptions {WriteIndented = true}; | ||
_jsonSerializerSettings.Converters.Add(new UnitsNetJsonConverterFactory()); | ||
//_jsonSerializerSettings.Converters.Add(new UnitsNetIQuantityJsonConverter()); | ||
//_jsonSerializerSettings.Converters.Add(new UnitsNetIComparableJsonConverter()); | ||
} | ||
|
||
protected string SerializeObject(object obj) | ||
{ | ||
return JsonSerializer.Serialize(obj, _jsonSerializerSettings).Replace("\r\n", "\n"); | ||
} | ||
|
||
protected T DeserializeObject<T>(string json) | ||
{ return JsonSerializer.Deserialize<T>(json, _jsonSerializerSettings); | ||
} | ||
} | ||
} |
Oops, something went wrong.