Skip to content

Commit 7b64ddc

Browse files
committed
Started implementation
Started implementation
1 parent 3558d59 commit 7b64ddc

15 files changed

+753
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
5+
{
6+
public sealed class TestObject
7+
{
8+
public Frequency? NullableFrequency { get; set; }
9+
public Frequency NonNullableFrequency { get; set; }
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using System;
5+
6+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
7+
{
8+
public sealed class TestObjectWithIComparable
9+
{
10+
public IComparable Value { get; set; }
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using System;
5+
6+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
7+
{
8+
public sealed class TestObjectWithThreeIComparable
9+
{
10+
public IComparable Value1 { get; set; }
11+
12+
public IComparable Value2 { get; set; }
13+
14+
public IComparable Value3 { get; set; }
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using System;
5+
6+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
7+
{
8+
public sealed class TestObjectWithValueAndUnitAsIComparable : IComparable
9+
{
10+
public double Value { get; set; }
11+
public string Unit { get; set; }
12+
13+
public int CompareTo(object obj)
14+
{
15+
return ((IComparable)Value).CompareTo(obj);
16+
}
17+
}
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using System;
5+
6+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
7+
{
8+
public sealed class TestObjectWithValueAsIComparable : IComparable
9+
{
10+
public int Value { get; set; }
11+
12+
public int CompareTo(object obj)
13+
{
14+
return ((IComparable)Value).CompareTo(obj);
15+
}
16+
17+
// Needed for verifying that the deserialized object is the same, should not affect the serialization code
18+
public override bool Equals(object obj)
19+
{
20+
if (obj == null || GetType() != obj.GetType())
21+
{
22+
return false;
23+
}
24+
return Value.Equals(((TestObjectWithValueAsIComparable)obj).Value);
25+
}
26+
27+
public override int GetHashCode()
28+
{
29+
return Value.GetHashCode();
30+
}
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using System.Text.Json;
5+
6+
namespace UnitsNet.Serialization.SystemTextJson.Tests.Infrastructure
7+
{
8+
public abstract class UnitsNetJsonBaseTest
9+
{
10+
private readonly JsonSerializerOptions _jsonSerializerSettings;
11+
12+
protected UnitsNetJsonBaseTest()
13+
{
14+
_jsonSerializerSettings = new JsonSerializerOptions {WriteIndented = true};
15+
_jsonSerializerSettings.Converters.Add(new UnitsNetJsonConverterFactory());
16+
//_jsonSerializerSettings.Converters.Add(new UnitsNetIQuantityJsonConverter());
17+
//_jsonSerializerSettings.Converters.Add(new UnitsNetIComparableJsonConverter());
18+
}
19+
20+
protected string SerializeObject(object obj)
21+
{
22+
return JsonSerializer.Serialize(obj, _jsonSerializerSettings).Replace("\r\n", "\n");
23+
}
24+
25+
protected T DeserializeObject<T>(string json)
26+
{ return JsonSerializer.Deserialize<T>(json, _jsonSerializerSettings);
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace UnitsNet.Serialization.SystemTextJson.Tests
2+
{
3+
public sealed class TestObject
4+
{
5+
public Frequency? NullableFrequency { get; set; }
6+
public Frequency NonNullableFrequency { get; set; }
7+
}
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="1.3.0">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\UnitsNet.Serialization.SystemTextJson\UnitsNet.Serialization.SystemTextJson.csproj" />
24+
<ProjectReference Include="..\UnitsNet\UnitsNet.csproj" />
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Text.Json;
2+
3+
namespace UnitsNet.Serialization.SystemTextJson.Tests
4+
{
5+
public abstract class UnitsNetJsonBaseTest
6+
{
7+
private readonly JsonSerializerOptions _jsonSerializerSettings;
8+
9+
protected UnitsNetJsonBaseTest()
10+
{
11+
_jsonSerializerSettings = new JsonSerializerOptions {WriteIndented = true};
12+
_jsonSerializerSettings.Converters.Add(new UnitsNetJsonConverterFactory());
13+
//_jsonSerializerSettings.Converters.Add(new UnitsNetIQuantityJsonConverter());
14+
//_jsonSerializerSettings.Converters.Add(new UnitsNetIComparableJsonConverter());
15+
}
16+
17+
protected string SerializeObject(object obj)
18+
{
19+
return JsonSerializer.Serialize(obj, _jsonSerializerSettings).Replace("\r\n", "\n");
20+
}
21+
22+
protected T DeserializeObject<T>(string json)
23+
{ return JsonSerializer.Deserialize<T>(json, _jsonSerializerSettings);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)