This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3d360b
commit f7b9dfc
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
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
115 changes: 115 additions & 0 deletions
115
test/Masa.Utils.Caching.Redis.Tests/ConvertToValueTest.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,115 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Utils.Caching.Redis.Tests; | ||
|
||
[TestClass] | ||
public class ConvertToValueTest | ||
{ | ||
[TestMethod] | ||
public void TestConvertByGuid() | ||
{ | ||
Guid id = Guid.NewGuid(); | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<Guid>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByByte() | ||
{ | ||
byte id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<byte>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertBySByte() | ||
{ | ||
sbyte id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<sbyte>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByUShort() | ||
{ | ||
ushort id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<ushort>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByUInt() | ||
{ | ||
uint id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<uint>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByULong() | ||
{ | ||
ulong id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<ulong>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByShort() | ||
{ | ||
short id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<short>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByInt() | ||
{ | ||
int id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<int>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByLong() | ||
{ | ||
long id = 1; | ||
RedisValue obj = RedisHelper.ConvertFromValue(id); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<long>(obj) == id); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByDouble() | ||
{ | ||
double score = 1.1d; | ||
RedisValue obj = RedisHelper.ConvertFromValue(score); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<double>(obj) == score); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByFloat() | ||
{ | ||
float score = 1.1f; | ||
RedisValue obj = RedisHelper.ConvertFromValue(score); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<float>(obj) == score); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByDecimal() | ||
{ | ||
decimal score = 1.1m; | ||
dynamic obj = RedisHelper.ConvertFromValue(score); | ||
Assert.IsTrue(RedisHelper.ConvertToValue<decimal>(obj) == score); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConvertByDynamic() | ||
{ | ||
dynamic user = new | ||
{ | ||
Name = "Jim" | ||
}; | ||
RedisValue obj = RedisHelper.ConvertFromValue(user)!; | ||
Assert.IsTrue(RedisHelper.ConvertToValue<dynamic>(obj)!.Name == user.Name); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/Masa.Utils.Caching.Redis.Tests/Masa.Utils.Caching.Redis.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Caching\Masa.Utils.Caching.Redis\Masa.Utils.Caching.Redis.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,7 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
global using Masa.Utils.Caching.Redis.Helpers; | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
global using StackExchange.Redis; | ||
global using System; |