Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
test(cache): Add Redis Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlei520 committed May 10, 2022
1 parent c3d360b commit f7b9dfc
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Masa.Utils.sln
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Utils.Ldap.Novell.Test
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Utils.Data.Elasticsearch.Tests", "test\Masa.Utils.Data.Elasticsearch.Tests\Masa.Utils.Data.Elasticsearch.Tests.csproj", "{EF08AB1B-50DE-4D26-BCCF-48DDE2A8E2CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Utils.Caching.Redis.Tests", "test\Masa.Utils.Caching.Redis.Tests\Masa.Utils.Caching.Redis.Tests.csproj", "{B063C9CC-868A-4474-8DCD-1708A65D4F2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -277,6 +279,10 @@ Global
{F6242694-66A5-4E59-9ECD-510D3D81C8C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6242694-66A5-4E59-9ECD-510D3D81C8C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6242694-66A5-4E59-9ECD-510D3D81C8C6}.Release|Any CPU.Build.0 = Release|Any CPU
{B063C9CC-868A-4474-8DCD-1708A65D4F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B063C9CC-868A-4474-8DCD-1708A65D4F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B063C9CC-868A-4474-8DCD-1708A65D4F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B063C9CC-868A-4474-8DCD-1708A65D4F2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -331,6 +337,7 @@ Global
{59124A98-14AF-4201-87D7-6DC9C92D9849} = {D956582F-4071-47E6-A8E7-4C5A83770045}
{E62E5E11-7119-4782-BCF4-A5913F4048FE} = {59124A98-14AF-4201-87D7-6DC9C92D9849}
{F6242694-66A5-4E59-9ECD-510D3D81C8C6} = {4F908878-0EB8-43E4-96E4-8B1F32E9B635}
{B063C9CC-868A-4474-8DCD-1708A65D4F2A} = {4F908878-0EB8-43E4-96E4-8B1F32E9B635}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D7DAA0E6-098F-4B18-8775-64FDA96F1FF0}
Expand Down
115 changes: 115 additions & 0 deletions test/Masa.Utils.Caching.Redis.Tests/ConvertToValueTest.cs
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);
}
}
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>
7 changes: 7 additions & 0 deletions test/Masa.Utils.Caching.Redis.Tests/_Imports.cs
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;

0 comments on commit f7b9dfc

Please sign in to comment.