Skip to content

Commit 8162dde

Browse files
author
Jacques Kang
committed
provide unit tests for DefaultValueConverter
1 parent e1c5a4b commit 8162dde

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ script:
88
- cd ./src
99
- dotnet restore
1010
- dotnet build
11+
- dotnet test JKang.IpcServiceFramework.Core.Tests

src/IpcServiceFramework.sln

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27004.2009
4+
VisualStudioVersion = 15.0.27004.2002
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{03210BFB-17B1-4775-A8A2-D302ECBF2F46}"
77
EndProject
@@ -13,14 +13,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IpcServiceSample.ConsoleCli
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{20913218-C740-42E9-9D17-CAD973B676D0}"
1515
ProjectSection(SolutionItems) = preProject
16+
..\.travis.yml = ..\.travis.yml
1617
..\README.md = ..\README.md
1718
EndProjectSection
1819
EndProject
19-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JKang.IpcServiceFramework.Client", "JKang.IpcServiceFramework.Client\JKang.IpcServiceFramework.Client.csproj", "{13D724CA-3FEA-49E1-BB6B-365CF9397986}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.IpcServiceFramework.Client", "JKang.IpcServiceFramework.Client\JKang.IpcServiceFramework.Client.csproj", "{13D724CA-3FEA-49E1-BB6B-365CF9397986}"
2021
EndProject
21-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JKang.IpcServiceFramework.Core", "JKang.IpcServiceFramework.Core\JKang.IpcServiceFramework.Core.csproj", "{58200319-1F71-4E22-894D-7E69E0CD0B57}"
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.IpcServiceFramework.Core", "JKang.IpcServiceFramework.Core\JKang.IpcServiceFramework.Core.csproj", "{58200319-1F71-4E22-894D-7E69E0CD0B57}"
2223
EndProject
23-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JKang.IpcServiceFramework.Server", "JKang.IpcServiceFramework.Server\JKang.IpcServiceFramework.Server.csproj", "{069B416A-B2C6-40D1-80B8-AC9ACA2217E3}"
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.IpcServiceFramework.Server", "JKang.IpcServiceFramework.Server\JKang.IpcServiceFramework.Server.csproj", "{069B416A-B2C6-40D1-80B8-AC9ACA2217E3}"
25+
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JKang.IpcServiceFramework.Core.Tests", "JKang.IpcServiceFramework.Core.Tests\JKang.IpcServiceFramework.Core.Tests.csproj", "{1EC81913-883B-487C-A3FD-98A80EDE3225}"
2427
EndProject
2528
Global
2629
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -52,6 +55,10 @@ Global
5255
{069B416A-B2C6-40D1-80B8-AC9ACA2217E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
5356
{069B416A-B2C6-40D1-80B8-AC9ACA2217E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
5457
{069B416A-B2C6-40D1-80B8-AC9ACA2217E3}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{1EC81913-883B-487C-A3FD-98A80EDE3225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{1EC81913-883B-487C-A3FD-98A80EDE3225}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{1EC81913-883B-487C-A3FD-98A80EDE3225}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{1EC81913-883B-487C-A3FD-98A80EDE3225}.Release|Any CPU.Build.0 = Release|Any CPU
5562
EndGlobalSection
5663
GlobalSection(SolutionProperties) = preSolution
5764
HideSolutionNode = FALSE
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using JKang.IpcServiceFramework.Services;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Newtonsoft.Json;
4+
using System;
5+
6+
namespace JKang.IpcServiceFramework.Core.Tests
7+
{
8+
[TestClass]
9+
public class DefaultValueConverterTest
10+
{
11+
private DefaultValueConverter _sut;
12+
13+
[TestInitialize]
14+
public void Init()
15+
{
16+
_sut = new DefaultValueConverter();
17+
}
18+
19+
[TestMethod]
20+
public void TryConvert_FloatToDouble()
21+
{
22+
float expected = 123.4f;
23+
24+
bool succeed = _sut.TryConvert(expected, typeof(double), out object actual);
25+
26+
Assert.IsTrue(succeed);
27+
Assert.IsInstanceOfType(actual, typeof(double));
28+
Assert.AreEqual((double)expected, actual);
29+
}
30+
31+
[TestMethod]
32+
public void TryConvert_Int32ToInt64()
33+
{
34+
int expected = 123;
35+
36+
bool succeed = _sut.TryConvert(expected, typeof(long), out object actual);
37+
38+
Assert.IsTrue(succeed);
39+
Assert.IsInstanceOfType(actual, typeof(long));
40+
Assert.AreEqual((long)expected, actual);
41+
}
42+
43+
[TestMethod]
44+
public void TryConvert_SameType()
45+
{
46+
DateTime expected = DateTime.UtcNow;
47+
48+
bool succeed = _sut.TryConvert(expected, typeof(DateTime), out object actual);
49+
50+
Assert.IsTrue(succeed);
51+
Assert.IsInstanceOfType(actual, typeof(DateTime));
52+
Assert.AreEqual(expected, actual);
53+
}
54+
55+
[TestMethod]
56+
public void TryConvert_JObjectToComplexType()
57+
{
58+
var expected = new ComplexType
59+
{
60+
Int32Value = 123,
61+
StringValue = "hello"
62+
};
63+
object jObj = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(expected));
64+
65+
bool succeed = _sut.TryConvert(jObj, typeof(ComplexType), out object actual);
66+
67+
Assert.IsTrue(succeed);
68+
Assert.IsInstanceOfType(actual, typeof(ComplexType));
69+
Assert.AreEqual(expected.Int32Value, ((ComplexType)actual).Int32Value);
70+
Assert.AreEqual(expected.StringValue, ((ComplexType)actual).StringValue);
71+
}
72+
73+
class ComplexType
74+
{
75+
public int Int32Value { get; set; }
76+
public string StringValue { get; set; }
77+
}
78+
}
79+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
12+
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\JKang.IpcServiceFramework.Core\JKang.IpcServiceFramework.Core.csproj" />
17+
</ItemGroup>
18+
19+
</Project>

0 commit comments

Comments
 (0)