Commit b591974b authored by Marc Gravell's avatar Marc Gravell

Merge pull request #94 from mwikstrom/master

Key space isolation tests
parents 63e3fdb9 b0301847
using System;
using Moq;
using NUnit.Framework;
using StackExchange.Redis.StackExchange.Redis.KeyspaceIsolation;
namespace StackExchange.Redis.Tests
{
[TestFixture]
public sealed class BatchWrapperTests
{
private Mock<IBatch> mock;
private BatchWrapper wrapper;
[TestFixtureSetUp]
public void Initialize()
{
mock = new Mock<IBatch>();
wrapper = new BatchWrapper(mock.Object, "prefix:");
}
[Test]
public void Execute()
{
wrapper.Execute();
mock.Verify(_ => _.Execute(), Times.Once());
}
}
}
This diff is collapsed.
......@@ -53,6 +53,9 @@
<Reference Include="BookSleeve">
<HintPath>..\packages\BookSleeve.1.3.41\lib\BookSleeve.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\StackExchange.Redis\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
......@@ -63,12 +66,16 @@
<ItemGroup>
<Compile Include="AsyncTests.cs" />
<Compile Include="BasicOps.cs" />
<Compile Include="WrapperBaseTests.cs" />
<Compile Include="TransactionWrapperTests.cs" />
<Compile Include="Bits.cs" />
<Compile Include="Cluster.cs" />
<Compile Include="Commands.cs" />
<Compile Include="ConnectFailTimeout.cs" />
<Compile Include="ConnectionShutdown.cs" />
<Compile Include="Databases.cs" />
<Compile Include="BatchWrapperTests.cs" />
<Compile Include="DatabaseWrapperTests.cs" />
<Compile Include="DefaultPorts.cs" />
<Compile Include="Expiry.cs" />
<Compile Include="Config.cs" />
......@@ -110,7 +117,9 @@
<Compile Include="WithKeyPrefixTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj">
......
using System;
using Moq;
using NUnit.Framework;
using StackExchange.Redis.StackExchange.Redis.KeyspaceIsolation;
namespace StackExchange.Redis.Tests
{
[TestFixture]
public sealed class TransactionWrapperTests
{
private Mock<ITransaction> mock;
private TransactionWrapper wrapper;
[TestFixtureSetUp]
public void Initialize()
{
mock = new Mock<ITransaction>();
wrapper = new TransactionWrapper(mock.Object, "prefix:");
}
[Test]
public void AddCondition_HashEqual()
{
wrapper.AddCondition(Condition.HashEqual("key", "field", "value"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key > field == value" == value.ToString())));
}
[Test]
public void AddCondition_HashNotEqual()
{
wrapper.AddCondition(Condition.HashNotEqual("key", "field", "value"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key > field != value" == value.ToString())));
}
[Test]
public void AddCondition_HashExists()
{
wrapper.AddCondition(Condition.HashExists("key", "field"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key > field exists" == value.ToString())));
}
[Test]
public void AddCondition_HashNotExists()
{
wrapper.AddCondition(Condition.HashNotExists("key", "field"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key > field does not exists" == value.ToString())));
}
[Test]
public void AddCondition_KeyExists()
{
wrapper.AddCondition(Condition.KeyExists("key"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key exists" == value.ToString())));
}
[Test]
public void AddCondition_KeyNotExists()
{
wrapper.AddCondition(Condition.KeyNotExists("key"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key does not exists" == value.ToString())));
}
[Test]
public void AddCondition_StringEqual()
{
wrapper.AddCondition(Condition.StringEqual("key", "value"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key == value" == value.ToString())));
}
[Test]
public void AddCondition_StringNotEqual()
{
wrapper.AddCondition(Condition.StringNotEqual("key", "value"));
mock.Verify(_ => _.AddCondition(It.Is<Condition>(value => "prefix:key != value" == value.ToString())));
}
[Test]
public void ExecuteAsync()
{
wrapper.ExecuteAsync(CommandFlags.HighPriority);
mock.Verify(_ => _.ExecuteAsync(CommandFlags.HighPriority), Times.Once());
}
[Test]
public void Execute()
{
wrapper.Execute(CommandFlags.HighPriority);
mock.Verify(_ => _.Execute(CommandFlags.HighPriority), Times.Once());
}
}
}
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BookSleeve" version="1.3.41" targetFramework="net45" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="NUnit" version="2.6.3" targetFramework="net45" />
</packages>
\ No newline at end of file
......@@ -38,3 +38,5 @@
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly:CLSCompliant(true)]
[assembly:InternalsVisibleTo("StackExchange.Redis.Tests")]
\ No newline at end of file
......@@ -6,12 +6,12 @@
namespace StackExchange.Redis.StackExchange.Redis.KeyspaceIsolation
{
internal abstract class WrapperBase<TInner> : IDatabaseAsync where TInner : IDatabaseAsync
internal class WrapperBase<TInner> : IDatabaseAsync where TInner : IDatabaseAsync
{
private readonly TInner _inner;
private readonly RedisKey _prefix;
protected WrapperBase(TInner inner, RedisKey prefix)
internal WrapperBase(TInner inner, RedisKey prefix)
{
_inner = inner;
_prefix = prefix;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment