Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Memcached unit tests by @softwx from ServiceStack/ServiceStack#334

  • Loading branch information...
commit b811d7c8138a67049323add3c247cbefdea30ad3 1 parent e846627
@mythz mythz authored
View
239 tests/ServiceStack.CacheAccess.Memcached.Tests/MemoryCacheClientTests.cs
@@ -0,0 +1,239 @@
+using System;
+using NUnit.Framework;
+using ServiceStack.CacheAccess.Providers;
+
+namespace ServiceStack.CacheAccess.Memcached.Tests
+{
+ [TestFixture]
+ public class MemoryCacheClientTests
+ {
+ MemoryCacheClient cache;
+
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ cache = new MemoryCacheClient();
+ }
+
+ [TestFixtureTearDown]
+ public void TestFixtureTearDown()
+ {
+ cache.Dispose();
+ cache = null;
+ }
+
+ [Test]
+ public void Get_before_Add_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, DateTime.Now.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Add_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, DateTime.Now.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+
+ [Test]
+ public void Get_before_Add_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Add_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Add_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, TimeSpan.FromMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Add_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Add(key, value, TimeSpan.FromMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Set_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, DateTime.Now.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Set_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, DateTime.Now.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Set_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Set_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Set_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, TimeSpan.FromMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Set_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value, TimeSpan.FromMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Replace_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, DateTime.Now.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Replace_local_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, DateTime.Now.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Replace_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Replace_utc_DateTime_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, DateTime.UtcNow.AddMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+
+ [Test]
+ public void Get_before_Replace_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, TimeSpan.FromMilliseconds(200));
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.SameAs(value));
+ }
+
+ [Test]
+ public void Get_after_Replace_TimeSpan_expires()
+ {
+ cache.FlushAll();
+ string key = "a";
+ string value = "aValue";
+ cache.Set(key, value);
+ cache.Replace(key, value, TimeSpan.FromMilliseconds(200));
+ System.Threading.Thread.Sleep(250);
+ var retVal = cache.Get(key);
+ Assert.That(retVal, Is.Null);
+ }
+ }
+}
View
253 tests/ServiceStack.CacheAccess.Memcached.Tests/ServiceStack.CacheAccess.Memcached.Tests.csproj
@@ -1,133 +1,134 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{3EEF88B9-14A0-466D-B364-24D5D0E9BE75}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>ServiceStack.CacheAccess.Memcached.Tests</RootNamespace>
- <AssemblyName>ServiceStack.CacheAccess.Memcached.Tests</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="Enyim.Caching, Version=2.11.0.0, Culture=neutral, PublicKeyToken=cec98615db04012e, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\src\packages\EnyimMemcached.2.11\lib\net35\Enyim.Caching.dll</HintPath>
- </Reference>
- <Reference Include="ServiceStack, Version=1.0.4067.4534, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\ServiceStack.dll</HintPath>
- </Reference>
- <Reference Include="ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
- </Reference>
- <Reference Include="ServiceStack.Redis, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\ServiceStack.Redis.dll</HintPath>
- </Reference>
- <Reference Include="ServiceStack.Text, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Configuration" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\tests\nunit.framework.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="AllCacheClientsTestBase.cs" />
- <Compile Include="AllCacheClientTests.cs" />
- <Compile Include="ModelWithIdAndName.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="App.config" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\src\ServiceStack.CacheAccess.Memcached\ServiceStack.CacheAccess.Memcached.csproj">
- <Project>{600612F3-15B4-45B5-9D39-06FA016B81C9}</Project>
- <Name>ServiceStack.CacheAccess.Memcached</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{3EEF88B9-14A0-466D-B364-24D5D0E9BE75}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ServiceStack.CacheAccess.Memcached.Tests</RootNamespace>
+ <AssemblyName>ServiceStack.CacheAccess.Memcached.Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Enyim.Caching, Version=2.11.0.0, Culture=neutral, PublicKeyToken=cec98615db04012e, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\src\packages\EnyimMemcached.2.11\lib\net35\Enyim.Caching.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack, Version=1.0.4067.4534, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\ServiceStack.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Redis, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\ServiceStack.Redis.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Text, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\tests\nunit.framework.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AllCacheClientsTestBase.cs" />
+ <Compile Include="AllCacheClientTests.cs" />
+ <Compile Include="MemoryCacheClientTests.cs" />
+ <Compile Include="ModelWithIdAndName.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\ServiceStack.CacheAccess.Memcached\ServiceStack.CacheAccess.Memcached.csproj">
+ <Project>{600612F3-15B4-45B5-9D39-06FA016B81C9}</Project>
+ <Name>ServiceStack.CacheAccess.Memcached</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
- -->
+ -->
</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.