Unit tests for Cached<T>

This commit is contained in:
Piotr Szmyd 2014-12-01 02:42:21 +01:00
parent 7c9af76293
commit dc3f407036
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,47 @@
using System;
using NUnit.Framework;
using Orchard.Caching.Services;
namespace Orchard.Tests.Modules.Email {
[TestFixture]
public class CachedTests {
[Test]
public void ShouldExplicitlyConvertToValueTypeT() {
Cached<int> cached = 10;
var raw = (int)cached;
Assert.That(raw, Is.EqualTo(10));
}
[Test]
public void ShouldConvertFromValueTypeT() {
Cached<int> cached1 = 10;
var cached2 = (Cached<int>)10;
Assert.That(cached1.Value, Is.EqualTo(10));
Assert.That(cached2.Value, Is.EqualTo(10));
}
[Test]
public void ShouldImplicitlyConvertFromNull()
{
object x = null;
Cached<object> cached = x;
Assert.That(cached.HasValue, Is.EqualTo(false));
}
[Test]
public void ShouldCompareWithObjectsOfTypeT() {
int raw1 = 10;
int raw2 = 20;
Cached<int> cached = 10;
Assert.That(cached == raw1, Is.EqualTo(true));
Assert.That(raw1 == cached, Is.EqualTo(true));
Assert.That(cached != raw2, Is.EqualTo(true));
Assert.That(raw2 != cached, Is.EqualTo(true));
}
}
}

View File

@ -141,6 +141,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Autoroute\DefaultSlugServiceTests.cs" />
<Compile Include="Caching\CachedTests.cs" />
<Compile Include="CodeGeneration\Commands\CodeGenerationCommandsTests.cs" />
<Compile Include="Comments\Services\CommentServiceTests.cs" />
<Compile Include="Email\EmailChannelTests.cs" />
@ -209,6 +210,10 @@
<Project>{66fccd76-2761-47e3-8d11-b45d0001ddaa}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Caching\Orchard.Caching.csproj">
<Project>{7528bf74-25c7-4abe-883a-443b4eec4776}</Project>
<Name>Orchard.Caching</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.CodeGeneration\Orchard.CodeGeneration.csproj">
<Project>{C0C45321-B51D-4D8D-9B7B-AA4C2E0B2962}</Project>
<Name>Orchard.CodeGeneration</Name>