Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ghforwin-hax'
Browse files Browse the repository at this point in the history
Conflicts:
	Akavache.Tests/BlobCacheExtensionsFixture.cs
	Akavache.Tests/BlobCacheFixture.cs
	Akavache/BlobCache.cs
	Akavache/BlobCacheExtensions.cs
	Akavache/IBlobCache.cs
	Akavache/PersistentBlobCache.cs
	Akavache/TestBlobCache.cs
	Akavache/Utility.cs
  • Loading branch information
anaisbetts committed Apr 23, 2012
2 parents 0efde9c + 84285f4 commit 1022b4a
Show file tree
Hide file tree
Showing 58 changed files with 89,418 additions and 4,958 deletions.
22 changes: 14 additions & 8 deletions Akavache.Tests/Akavache.Tests.csproj
Expand Up @@ -35,14 +35,9 @@
<HintPath>..\..\packages\Rx_Experimental-Testing.1.1.11111\lib\Net4-Full\Microsoft.Reactive.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="ReactiveUI">
<HintPath>..\packages\reactiveui-core.2.5.2.0\lib\Net4\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="ReactiveUI.Testing">
<HintPath>..\packages\reactiveui-testing.2.5.2.0\lib\Net4\ReactiveUI.Testing.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=4.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.4.0.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -71,9 +66,20 @@
<Compile Include="Utility.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ReactiveUI\ReactiveUI.Testing\ReactiveUI.Testing.csproj">
<Project>{E1F2AD19-276E-4D05-A41A-89AA133CECFC}</Project>
<Name>ReactiveUI.Testing</Name>
</ProjectReference>
<ProjectReference Include="..\..\ReactiveUI\ReactiveUI\ReactiveUI.csproj">
<Project>{292A477B-BB94-43C1-984E-E177EF9FEDB7}</Project>
<Name>ReactiveUI</Name>
</ProjectReference>
<ProjectReference Include="..\Akavache\Akavache.csproj">
<Project>{3EF05CA8-ED19-489C-AF42-71C4B6507AE7}</Project>
<Name>Akavache</Name>
Expand Down
37 changes: 22 additions & 15 deletions Akavache.Tests/BlobCacheExtensionsFixture.cs
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using Microsoft.Reactive.Testing;
using ReactiveUI.Testing;
using Xunit;

namespace Akavache.Tests
Expand Down Expand Up @@ -33,26 +35,31 @@ public void DownloadUrlTest()
[Fact]
public void ObjectsShouldBeRoundtrippable()
{
string path;
var input = new UserObject() {Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com"};
UserObject result;

using(Utility.WithEmptyDirectory(out path))
new TestScheduler().With(sched =>
{
using(var fixture = new TPersistentBlobCache(path))
{
fixture.InsertObject("key", input);
}
string path;
var input = new UserObject() {Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com"};
UserObject result;
using(var fixture = new TPersistentBlobCache(path))
using (Utility.WithEmptyDirectory(out path))
{
result = fixture.GetObjectAsync<UserObject>("key").First();
using (var fixture = new TPersistentBlobCache(path))
{
fixture.InsertObject("key", input);
}
sched.Start();
using (var fixture = new TPersistentBlobCache(path))
{
var action = fixture.GetObjectAsync<UserObject>("key");
sched.Start();
result = action.First();
}
}
}
Assert.Equal(input.Blog, result.Blog);
Assert.Equal(input.Bio, result.Bio);
Assert.Equal(input.Name, result.Name);
Assert.Equal(input.Blog, result.Blog);
Assert.Equal(input.Bio, result.Bio);
Assert.Equal(input.Name, result.Name);
});
}

[Fact]
Expand Down
31 changes: 18 additions & 13 deletions Akavache.Tests/BlobCacheFixture.cs
Expand Up @@ -51,22 +51,27 @@ public void CacheShouldBeAbleToGetAndInsertBlobs()
[Fact]
public void CacheShouldBeRoundtrippable()
{
string path;

using (Utility.WithEmptyDirectory(out path))
new TestScheduler().With(sched =>
{
using (var fixture = CreateBlobCache(path))
{
fixture.Insert("Foo", new byte[] { 1, 2, 3 });
}
string path;
using (var fixture = CreateBlobCache(path))
using (Utility.WithEmptyDirectory(out path))
{
var output = fixture.GetAsync("Foo").First();
Assert.Equal(3, output.Length);
Assert.Equal(1, output[0]);
using (var fixture = CreateBlobCache(path))
{
fixture.Insert("Foo", new byte[] {1, 2, 3});
}
sched.Start();
using (var fixture = CreateBlobCache(path))
{
var action = fixture.GetAsync("Foo");
sched.Start();
var output = action.First();
Assert.Equal(3, output.Length);
Assert.Equal(1, output[0]);
}
}
}
});
}

[Fact]
Expand Down Expand Up @@ -151,7 +156,7 @@ public void CacheShouldRespectExpiration()
}
}

[Fact]
[Fact(Skip = "Put off this test until later, it's fairly evil")]
public void AbuseTheCacheOnATonOfThreads()
{
var rng = new Random();
Expand Down
53 changes: 29 additions & 24 deletions Akavache.Tests/EncryptedBlobCacheFixture.cs
Expand Up @@ -5,6 +5,8 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Text;
using Microsoft.Reactive.Testing;
using ReactiveUI.Testing;
using Xunit;
using ReactiveUI;

Expand All @@ -15,36 +17,39 @@ class TEncryptedBlobCache : EncryptedBlobCache
public TEncryptedBlobCache (string cacheDirectory = null, IScheduler scheduler = null) : base(cacheDirectory, null, scheduler) { }
}

public class EncryptedBlobCacheFixture : IEnableLogger
public class EncryptedBlobCacheFixture
{
[Fact]
public void NoPlaintextShouldShowUpInCache()
{
const string secretUser = "OmgSekritUser";
const string secretPass = "OmgSekritPassword";
string path;

using (Utility.WithEmptyDirectory(out path))
new TestScheduler().With(sched =>
{
using (var fixture = new TEncryptedBlobCache(path))
const string secretUser = "OmgSekritUser";
const string secretPass = "OmgSekritPassword";
string path;
using (Utility.WithEmptyDirectory(out path))
{
fixture.SaveLogin(secretUser, secretPass);
}
using (var fixture = new TEncryptedBlobCache(path))
{
fixture.SaveLogin(secretUser, secretPass, "github.com");
}
sched.Start();
var di = new DirectoryInfo(path);
var fileList = di.GetFiles().ToArray();
Assert.True(fileList.Length > 1);
var di = new DirectoryInfo(path);
var fileList = di.GetFiles().ToArray();
Assert.True(fileList.Length > 1);
foreach(var file in fileList)
{
var text = File.ReadAllText(file.FullName, Encoding.UTF8);
this.Log().InfoFormat("File '{0}': {1}", file.Name, text);
foreach (var file in fileList)
{
var text = File.ReadAllText(file.FullName, Encoding.UTF8);
Assert.False(text.Contains(secretUser));
Assert.False(text.Contains(secretPass));
Assert.False(text.Contains("login"));
Assert.False(text.Contains(secretUser));
Assert.False(text.Contains(secretPass));
Assert.False(text.Contains("login"));
}
}
}
});
}

[Fact]
Expand All @@ -58,14 +63,14 @@ public void EncryptedDataShouldBeRoundtripped()
{
using (var fixture = new TEncryptedBlobCache(path))
{
fixture.SaveLogin(secretUser, secretPass);
fixture.SaveLogin(secretUser, secretPass, "github.com");
}

using (var fixture = new TEncryptedBlobCache(path))
{
var loginInfo = fixture.GetLoginAsync().First();
Assert.Equal(secretUser, loginInfo.Item1);
Assert.Equal(secretPass, loginInfo.Item2);
var loginInfo = fixture.GetLoginAsync("github.com").First();
Assert.Equal(secretUser, loginInfo.UserName);
Assert.Equal(secretPass, loginInfo.Password);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Akavache.Tests/Utility.cs
Expand Up @@ -48,7 +48,7 @@ public static IDisposable WithEmptyDirectory(out string directoryPath)
return Disposable.Create(() => DeleteDirectory(di.FullName));
}

public static void Retry(this Action block, int retries = 3)
public static void Retry(this Action block, int retries = 2)
{
while (true)
{
Expand All @@ -59,12 +59,12 @@ public static void Retry(this Action block, int retries = 3)
}
catch (Exception)
{
retries--;
if (retries == 0)
{
Thread.Sleep(10);
throw;
}
retries--;
Thread.Sleep(10);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions Akavache.Tests/app.config
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.11011.0" newVersion="1.1.11011.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.0.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
18 changes: 13 additions & 5 deletions Akavache/Akavache.csproj
Expand Up @@ -31,13 +31,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=4.0.7.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.4.0.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="ReactiveUI">
<HintPath>..\packages\reactiveui-core.2.5.2.0\lib\Net4\ReactiveUI.dll</HintPath>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive, Version=1.1.11111.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -57,6 +58,7 @@
<Compile Include="DataProtectionApi.cs" />
<Compile Include="EncryptedBlobCache.cs" />
<Compile Include="IBlobCache.cs" />
<Compile Include="LoginInfo.cs" />
<Compile Include="PersistentBlobCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleFilesystemProvider.cs" />
Expand All @@ -66,6 +68,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ReactiveUI\ReactiveUI\ReactiveUI.csproj">
<Project>{292A477B-BB94-43C1-984E-E177EF9FEDB7}</Project>
<Name>ReactiveUI</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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.
Expand Down
24 changes: 23 additions & 1 deletion Akavache/BlobCache.cs
@@ -1,10 +1,23 @@
using System;
using System.Reactive.Concurrency;
using ReactiveUI;

namespace Akavache
{
public static class BlobCache
{
static string applicationName;
static ISecureBlobCache perSession = new TestBlobCache(Scheduler.Immediate);

static BlobCache()
{
if (RxApp.InUnitTestRunner())
{
localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
userAccount = new TestBlobCache(RxApp.TaskpoolScheduler);
secure = new TestBlobCache(RxApp.TaskpoolScheduler);
}
}

/// <summary>
///
Expand Down Expand Up @@ -55,5 +68,14 @@ public static ISecureBlobCache Secure
set { secure = value; }
}
#endif

/// <summary>
///
/// </summary>
public static ISecureBlobCache InMemory
{
get { return perSession; }
set { perSession = value; }
}
}
}
}

0 comments on commit 1022b4a

Please sign in to comment.