Skip to content

Commit 4aa3892

Browse files
committedApr 1, 2015
Initial commit
1 parent c482688 commit 4aa3892

11 files changed

+528
-0
lines changed
 

‎.nuget/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Redis-32" version="2.6.12.1" />
4+
</packages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{048B0E9B-52CE-4573-98F3-016B13806E70}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Moissaing.ThinktectureIdentityModel.Redis</RootNamespace>
11+
<AssemblyName>Moissaing.ThinktectureIdentityModel.Redis</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<DocumentationFile>bin\Debug\Moissaing.ThinktectureIdentityModel.Redis.XML</DocumentationFile>
25+
<RunCodeAnalysis>false</RunCodeAnalysis>
26+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
<DocumentationFile>bin\Release\Moissaing.ThinktectureIdentityModel.Redis.XML</DocumentationFile>
36+
<RunCodeAnalysis>false</RunCodeAnalysis>
37+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41+
<Private>True</Private>
42+
<HintPath>..\packages\Microsoft.IdentityModel.6.1.7600.16394\lib\net35\Microsoft.IdentityModel.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Microsoft.Threading.Tasks">
45+
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.Threading.Tasks.Extensions">
48+
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
51+
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
54+
<HintPath>..\packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll</HintPath>
55+
</Reference>
56+
<Reference Include="StackExchange.Redis">
57+
<HintPath>..\packages\StackExchange.Redis.1.0.414\lib\net40\StackExchange.Redis.dll</HintPath>
58+
</Reference>
59+
<Reference Include="System" />
60+
<Reference Include="System.Core" />
61+
<Reference Include="System.IdentityModel" />
62+
<Reference Include="System.IO">
63+
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll</HintPath>
64+
</Reference>
65+
<Reference Include="System.Net" />
66+
<Reference Include="System.Runtime">
67+
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll</HintPath>
68+
</Reference>
69+
<Reference Include="System.Threading.Tasks">
70+
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll</HintPath>
71+
</Reference>
72+
<Reference Include="System.Xml.Linq" />
73+
<Reference Include="System.Data.DataSetExtensions" />
74+
<Reference Include="Microsoft.CSharp" />
75+
<Reference Include="System.Data" />
76+
<Reference Include="System.Xml" />
77+
<Reference Include="Thinktecture.IdentityModel">
78+
<HintPath>..\packages\Thinktecture.IdentityModel.3.6.1\lib\net40\Thinktecture.IdentityModel.dll</HintPath>
79+
</Reference>
80+
</ItemGroup>
81+
<ItemGroup>
82+
<Compile Include="RedisTokenCacheRepository.cs" />
83+
<Compile Include="Properties\AssemblyInfo.cs" />
84+
</ItemGroup>
85+
<ItemGroup>
86+
<None Include="app.config" />
87+
<None Include="packages.config" />
88+
</ItemGroup>
89+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
90+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
91+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
92+
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
93+
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
94+
</Target>
95+
<PropertyGroup>
96+
<PostBuildEvent>"$(SolutionDir).nuget\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)</PostBuildEvent>
97+
</PropertyGroup>
98+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
99+
Other similar extension points exist, see Microsoft.Common.targets.
100+
<Target Name="BeforeBuild">
101+
</Target>
102+
<Target Name="AfterBuild">
103+
</Target>
104+
-->
105+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Moissaing.ThinktectureIdentityModel.Redis")]
9+
[assembly: AssemblyDescription("Redis token cache repository for Thinktecture identity")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Guillaume Moissaing")]
12+
[assembly: AssemblyProduct("Moissaing.ThinktectureIdentityModel.Redis")]
13+
[assembly: AssemblyCopyright("Copyright © Guillaume Moissaing 2015")]
14+
[assembly: AssemblyTrademark("Guillaume Moissaing")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("31aab969-900c-4fe1-b176-4c5e4d536b08")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
7+
using StackExchange.Redis;
8+
using Thinktecture.IdentityModel.Web;
9+
10+
namespace Moissaing.ThinktectureIdentityModel.Redis
11+
{
12+
/// <summary>
13+
/// Implementation of token cache repository using redis storage
14+
/// </summary>
15+
public sealed class RedisTokenCacheRepository : ITokenCacheRepository, IDisposable
16+
{
17+
/// <summary>
18+
/// Intializes an instance of RedisTokenCacheRepository
19+
/// </summary>
20+
/// <param name="connectionString">Redis connection string, see StackExchange.Redis documentation</param>
21+
/// <param name="applicationName">Prefix used in cache key to avoid collisions between applications</param>
22+
public RedisTokenCacheRepository(string connectionString, string applicationName)
23+
{
24+
_connection = ConnectionMultiplexer.Connect(connectionString);
25+
_applicationName = applicationName;
26+
}
27+
28+
private readonly string _applicationName;
29+
private ConnectionMultiplexer _connection;
30+
31+
/// <summary>
32+
/// Adds or updates the token in the cache
33+
/// </summary>
34+
public void AddOrUpdate(TokenCacheItem item)
35+
{
36+
if (item == null)
37+
throw new ArgumentNullException("item");
38+
var db = _connection.GetDatabase();
39+
TimeSpan expiry = item.Expires.ToUniversalTime() - DateTime.UtcNow;
40+
db.StringSet(_applicationName + item.Key, item.Token, expiry);
41+
}
42+
43+
/// <summary>
44+
/// Gets a token from the cache
45+
/// </summary>
46+
public TokenCacheItem Get(string key)
47+
{
48+
var db = _connection.GetDatabase();
49+
var cachedValue = db.StringGet(_applicationName + key);
50+
if (cachedValue.IsNull)
51+
return null;
52+
else
53+
return new TokenCacheItem() { Key = key, Token = cachedValue };
54+
}
55+
56+
/// <summary>
57+
/// Removes a token from the cache
58+
/// </summary>
59+
public void Remove(string key)
60+
{
61+
var db = _connection.GetDatabase();
62+
db.KeyDelete(_applicationName + key);
63+
}
64+
65+
/// <summary>
66+
/// Release all resources associated with this object
67+
/// </summary>
68+
public void Dispose()
69+
{
70+
_connection.Dispose();
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
12+
</dependentAssembly>
13+
</assemblyBinding>
14+
</runtime>
15+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net40" />
4+
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
5+
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
6+
<package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net40" />
7+
<package id="Newtonsoft.Json" version="4.5.8" targetFramework="net40" />
8+
<package id="StackExchange.Redis" version="1.0.414" targetFramework="net40" />
9+
<package id="Thinktecture.IdentityModel" version="3.6.1" targetFramework="net40" />
10+
</packages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("RedisTokenCache.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("RedisTokenCache.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("6b6c5cb6-c7c1-4d65-b963-dd042f6d78e3")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>RedisTokenCache.Tests</RootNamespace>
10+
<AssemblyName>RedisTokenCache.Tests</AssemblyName>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.IdentityModel" />
43+
<Reference Include="System.IdentityModel.Services" />
44+
<Reference Include="System.IdentityModel.Tokens.Jwt">
45+
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.1.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Thinktecture.IdentityModel, Version=3.6.1.0, Culture=neutral, processorArchitecture=MSIL">
48+
<SpecificVersion>False</SpecificVersion>
49+
<HintPath>..\packages\Thinktecture.IdentityModel.3.6.1\lib\net45\Thinktecture.IdentityModel.dll</HintPath>
50+
</Reference>
51+
</ItemGroup>
52+
<Choose>
53+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
54+
<ItemGroup>
55+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
56+
</ItemGroup>
57+
</When>
58+
<Otherwise>
59+
<ItemGroup>
60+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
61+
</ItemGroup>
62+
</Otherwise>
63+
</Choose>
64+
<ItemGroup>
65+
<Compile Include="TokenRepositoryTests.cs" />
66+
<Compile Include="Properties\AssemblyInfo.cs" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="..\Moissaing.ThinktectureIdentityModel.Redis\Moissaing.ThinktectureIdentityModel.Redis.csproj">
70+
<Project>{048b0e9b-52ce-4573-98f3-016b13806e70}</Project>
71+
<Name>Moissaing.ThinktectureIdentityModel.Redis</Name>
72+
</ProjectReference>
73+
</ItemGroup>
74+
<ItemGroup>
75+
<None Include="packages.config" />
76+
</ItemGroup>
77+
<Choose>
78+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
79+
<ItemGroup>
80+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
81+
<Private>False</Private>
82+
</Reference>
83+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
84+
<Private>False</Private>
85+
</Reference>
86+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
87+
<Private>False</Private>
88+
</Reference>
89+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
90+
<Private>False</Private>
91+
</Reference>
92+
</ItemGroup>
93+
</When>
94+
</Choose>
95+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
96+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
97+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
98+
Other similar extension points exist, see Microsoft.Common.targets.
99+
<Target Name="BeforeBuild">
100+
</Target>
101+
<Target Name="AfterBuild">
102+
</Target>
103+
-->
104+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Threading;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using Moissaing.ThinktectureIdentityModel.Redis;
6+
using Thinktecture.IdentityModel.Web;
7+
8+
namespace RedisTokenCache.Tests
9+
{
10+
[TestClass]
11+
public class TokenRepositoryTests
12+
{
13+
private Process serverProcess;
14+
private const string connectionString = "localhost,connectRetry=3,connectTimeout=500";
15+
16+
[TestInitialize]
17+
public void Initialize()
18+
{
19+
serverProcess = Process.Start(@"..\..\..\packages\Redis-32.2.6.12.1\tools\redis-server.exe");
20+
}
21+
22+
[TestCleanup]
23+
public void Cleanup()
24+
{
25+
try
26+
{
27+
serverProcess.Kill();
28+
}
29+
catch { }
30+
serverProcess.Dispose();
31+
}
32+
33+
[TestMethod]
34+
public void TestAddOrUpdateThenGet()
35+
{
36+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
37+
38+
repository.AddOrUpdate(new TokenCacheItem() { Key = "42", Expires = DateTime.UtcNow.AddMinutes(1), Token = new byte[] { 0, 1, 2 } });
39+
var item = repository.Get("42");
40+
41+
Assert.IsNotNull(item);
42+
CollectionAssert.AreEqual(new byte[] { 0, 1, 2 }, item.Token);
43+
Assert.AreEqual("42", item.Key);
44+
}
45+
46+
[TestMethod]
47+
public void TestUpdateExisting()
48+
{
49+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
50+
51+
repository.AddOrUpdate(new TokenCacheItem() { Key = "42", Expires = DateTime.UtcNow.AddMinutes(1), Token = new byte[] { 0, 1, 2 } });
52+
var item = repository.Get("42");
53+
repository.AddOrUpdate(new TokenCacheItem() { Key = "42", Expires = DateTime.UtcNow.AddMinutes(1), Token = new byte[] { 3, 4, 5 } });
54+
var item2 = repository.Get("42");
55+
56+
Assert.IsNotNull(item);
57+
CollectionAssert.AreEqual(new byte[] { 0, 1, 2 }, item.Token);
58+
Assert.AreEqual("42", item.Key);
59+
Assert.IsNotNull(item2);
60+
CollectionAssert.AreEqual(new byte[] { 3, 4, 5 }, item2.Token);
61+
Assert.AreEqual("42", item2.Key);
62+
}
63+
64+
[TestMethod]
65+
public void TestDeleteExisting()
66+
{
67+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
68+
repository.AddOrUpdate(new TokenCacheItem() { Key = "42", Expires = DateTime.UtcNow.AddMinutes(1), Token = new byte[] { 0, 1, 2 } });
69+
Assert.IsNotNull(repository.Get("42"));
70+
71+
repository.Remove("42");
72+
73+
Assert.IsNull(repository.Get("42"));
74+
}
75+
76+
[TestMethod]
77+
public void TestExpiration()
78+
{
79+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
80+
repository.AddOrUpdate(new TokenCacheItem() { Key = "42", Expires = DateTime.UtcNow.AddMilliseconds(200), Token = new byte[] { 0, 1, 2 } });
81+
Assert.IsNotNull(repository.Get("42"));
82+
83+
Thread.Sleep(400);
84+
85+
Assert.IsNull(repository.Get("42"));
86+
}
87+
88+
[TestMethod]
89+
public void TestGetMissing()
90+
{
91+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
92+
93+
Assert.IsNull(repository.Get("doesnt.exists"));
94+
}
95+
96+
[TestMethod]
97+
public void TestDeleteMissing()
98+
{
99+
var repository = new RedisTokenCacheRepository(connectionString, "UnitTests");
100+
101+
repository.Remove("doesnt.exists");
102+
103+
Assert.IsNull(repository.Get("doesnt.exists"));
104+
}
105+
}
106+
}

‎RedisTokenCache.Tests/packages.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
4+
<package id="System.IdentityModel.Tokens.Jwt" version="1.0.0" targetFramework="net45" />
5+
<package id="Thinktecture.IdentityModel" version="3.6.1" targetFramework="net45" />
6+
</packages>

‎RedisTokenCache.sln

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moissaing.ThinktectureIdentityModel.Redis", "Moissaing.ThinktectureIdentityModel.Redis\Moissaing.ThinktectureIdentityModel.Redis.csproj", "{048B0E9B-52CE-4573-98F3-016B13806E70}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisTokenCache.Tests", "RedisTokenCache.Tests\RedisTokenCache.Tests.csproj", "{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F5845E8C-2F4C-4693-97EF-CD35156C500B}"
11+
ProjectSection(SolutionItems) = preProject
12+
.nuget\packages.config = .nuget\packages.config
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{048B0E9B-52CE-4573-98F3-016B13806E70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{048B0E9B-52CE-4573-98F3-016B13806E70}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{048B0E9B-52CE-4573-98F3-016B13806E70}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{048B0E9B-52CE-4573-98F3-016B13806E70}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{84E56B3E-DFE1-4211-A884-13B9DC6BEAEF}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
EndGlobal

0 commit comments

Comments
 (0)
Please sign in to comment.