Skip to content

Commit

Permalink
Added Memcached unit tests by @softwx from ServiceStack/ServiceStack#334
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 17, 2012
1 parent e846627 commit b811d7c
Show file tree
Hide file tree
Showing 2 changed files with 366 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading

0 comments on commit b811d7c

Please sign in to comment.