This commit is contained in:
James Montemagno 2017-12-11 19:26:54 -08:00
Родитель 001d08fde0
Коммит 71750d0b9c
4 изменённых файлов: 150 добавлений и 0 удалений

Просмотреть файл

@ -23,6 +23,78 @@ namespace MonkeyCache.Tests
monkeys = JsonConvert.DeserializeObject<IEnumerable<Monkey>>(json);
}
#region Get Tests
[TestMethod]
public void GetStringTest()
{
//Saves the cache and pass it a timespan for expiration
barrel.Add(key: url, data: json, expireIn: TimeSpan.FromDays(1));
var cached = barrel.Get(url);
Assert.IsNotNull(cached);
}
[TestMethod]
public void GetTest()
{
//Saves the cache and pass it a timespan for expiration
barrel.Add(key: url, data: monkeys, expireIn: TimeSpan.FromDays(1));
var cached = barrel.Get<IEnumerable<Monkey>>(url);
Assert.IsNotNull(cached);
}
[TestMethod]
public void GetETagTest()
{
var tag = "etag";
//Saves the cache and pass it a timespan for expiration
barrel.Add(key: url, data: json, expireIn: TimeSpan.FromDays(1), eTag: tag);
var cached = barrel.GetETag(url);
Assert.AreEqual(cached, tag);
}
[TestMethod]
public void GetETagNullTest()
{
var cached = barrel.GetETag(url);
Assert.IsNull(cached);
}
#endregion
#region Add Tests
[TestMethod]
public void AddStringNullTest()
{
//Saves the cache and pass it a timespan for expiration
barrel.Add(key: url, data: null, expireIn: TimeSpan.FromDays(1));
var cached = barrel.Get(url);
Assert.IsNull(cached);
}
[TestMethod]
public void AddStringTest()
{
@ -37,6 +109,20 @@ namespace MonkeyCache.Tests
}
[TestMethod]
public void AddNullTest()
{
//Saves the cache and pass it a timespan for expiration
barrel.Add<Monkey>(key: url, data: null, expireIn: TimeSpan.FromDays(1));
var cached = barrel.Get<Monkey>(url);
Assert.AreEqual(cached, default);
}
[TestMethod]
public void AddTest()
{
@ -51,6 +137,34 @@ namespace MonkeyCache.Tests
}
[TestMethod]
public void AddTestNull()
{
//Saves the cache and pass it a timespan for expiration
barrel.Add(key: url, data: null, expireIn: TimeSpan.FromDays(1));
var cached = barrel.Get<IEnumerable<Monkey>>(url);
Assert.IsNull(cached);
}
#endregion
#region Expiration Tests
[TestMethod]
public void IsExpiredNullTest()
{
Assert.IsFalse(barrel.IsExpired(url));
}
[TestMethod]
public void IsExpiredTest()
{
@ -81,6 +195,10 @@ namespace MonkeyCache.Tests
}
#endregion
#region Empty Tests
[TestMethod]
public void EmptyTest()
{
@ -140,6 +258,10 @@ namespace MonkeyCache.Tests
Assert.IsFalse(barrel.Exists(url2));
}
#endregion
#region Exists Tests
[TestMethod]
public void ExistsTest()
{
@ -165,6 +287,8 @@ namespace MonkeyCache.Tests
Assert.IsFalse(barrel.Exists(url));
}
#endregion
[TestCleanup]
public void Teardown()
{

Просмотреть файл

@ -32,6 +32,14 @@ namespace MonkeyCache.Tests
Assert.IsNotNull(result);
}
[TestMethod]
public async Task GetCachedForceTest()
{
var result = await HttpCache.Current.GetCachedAsync(url, TimeSpan.FromSeconds(60), TimeSpan.FromDays(1), true);
Assert.IsNotNull(result);
}
}
}

Просмотреть файл

@ -6,6 +6,14 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />

Просмотреть файл

@ -20,6 +20,16 @@
<Description>The best cache that is always monkeying around with your data.</Description>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>latest</LangVersion>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="sqlite-net-pcl" Version="1.4.118" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />