Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started work on the non-live Async tests

Also did a bit of shuffling around.
  • Loading branch information...
commit b000abab8356dbe10e5cb76939e1b8bb44ca6c12 1 parent 085ab12
@OJ OJ authored
View
37 CorrugatedIron.Tests/AsyncMethodTester.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Threading;
+
+namespace CorrugatedIron.Tests
+{
+ public class AsyncMethodTester<TCallbackResult>
+ {
+ private readonly AutoResetEvent _eventHandle;
+ private TCallbackResult _result;
+
+ public TCallbackResult Result
+ {
+ get
+ {
+ _eventHandle.WaitOne();
+ return _result;
+ }
+ }
+
+ public Action<TCallbackResult> HandleResult
+ {
+ get
+ {
+ return result =>
+ {
+ _result = result;
+ _eventHandle.Set();
+ };
+ }
+ }
+
+ public AsyncMethodTester()
+ {
+ _eventHandle = new AutoResetEvent(false);
+ }
+ }
+}
View
13 CorrugatedIron.Tests/CorrugatedIron.Tests.csproj
@@ -61,10 +61,12 @@
<Compile Include="..\Metadata\VersionInfo.cs">
<Link>Properties\VersionInfo.cs</Link>
</Compile>
- <Compile Include="Comms\RiakClientSetBucketPropertiesTests.cs" />
- <Compile Include="Comms\RiakClientTestBase.cs" />
- <Compile Include="Comms\RiakClientPingTests.cs" />
- <Compile Include="Comms\RiakClientTests.cs" />
+ <Compile Include="AsyncMethodTester.cs" />
+ <Compile Include="RiakAsyncClientTests.cs" />
+ <Compile Include="RiakClientSetBucketPropertiesTests.cs" />
+ <Compile Include="RiakClientTestBase.cs" />
+ <Compile Include="RiakClientPingTests.cs" />
+ <Compile Include="RiakClientTests.cs" />
<Compile Include="Encoding\MessageEncoderUnitTests.cs" />
<Compile Include="Extensions\UnitTestExtensions.cs" />
<Compile Include="Models\MapReduce\RiakMapReduceTests.cs" />
@@ -84,6 +86,9 @@
<Name>CorrugatedIron</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Comms\" />
+ </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.
View
151 CorrugatedIron.Tests/RiakAsyncClientTests.cs
@@ -0,0 +1,151 @@
+// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
+//
+// This file is provided to you under the Apache License,
+// Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain
+// a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using CorrugatedIron.Extensions;
+using CorrugatedIron.Models;
+using CorrugatedIron.Tests.Extensions;
+using Moq;
+using NUnit.Framework;
+
+namespace CorrugatedIron.Tests.RiakAsyncClientTests
+{
+ public abstract class RiakAsyncClientTestBase<TResult>
+ {
+ protected Mock<IRiakClient> ClientMock;
+ protected RiakAsyncClient AsyncClient;
+ protected AsyncMethodTester<TResult> Tester;
+ protected TResult Result;
+
+ protected RiakAsyncClientTestBase()
+ {
+ ClientMock = new Mock<IRiakClient>();
+ AsyncClient = new RiakAsyncClient(ClientMock.Object);
+ Tester = new AsyncMethodTester<TResult>();
+ }
+ }
+
+ [TestFixture]
+ public class WhenPingingServerAsync : RiakAsyncClientTestBase<RiakResult>
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ ClientMock.Setup(m => m.Ping()).Returns(RiakResult.Success());
+ AsyncClient.Ping(Tester.HandleResult);
+ Result = Tester.Result;
+ }
+
+ [Test]
+ public void AsyncClientInvokesCorrectClientFunction()
+ {
+ ClientMock.Verify(m => m.Ping(), Times.Once());
+ }
+
+ [Test]
+ public void AsyncClientReturnsCorrectResult()
+ {
+ Result.ShouldNotBeNull();
+ Result.IsSuccess.ShouldBeTrue();
+ }
+ }
+
+ [TestFixture]
+ public class WhenCallingGetWithObjectIdAsync : RiakAsyncClientTestBase<RiakResult<RiakObject>>
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ ClientMock.Setup(m => m.Get(It.IsAny<string>(), It.IsAny<string>(), 2)).Returns(RiakResult<RiakObject>.Success(new RiakObject("foo", "bar", "baz")));
+ AsyncClient.Get(new RiakObjectId("foo", "bar"), Tester.HandleResult);
+ Result = Tester.Result;
+ }
+
+ [Test]
+ public void AsyncClientInvokesCorrectClientFunction()
+ {
+ ClientMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<string>(), 2), Times.Once());
+ }
+
+ [Test]
+ public void AsyncClientReturnsCorrectResult()
+ {
+ Result.ShouldNotBeNull();
+ Result.IsSuccess.ShouldBeTrue();
+ Result.Value.ShouldNotBeNull();
+ Result.Value.Bucket.ShouldEqual("foo");
+ Result.Value.Key.ShouldEqual("bar");
+ Result.Value.Value.FromRiakString().ShouldEqual("baz");
+ }
+ }
+
+ [TestFixture]
+ public class WhenCallingGetWithBucketKeyAsync : RiakAsyncClientTestBase<RiakResult<RiakObject>>
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ ClientMock.Setup(m => m.Get(It.IsAny<string>(), It.IsAny<string>(), 2)).Returns(RiakResult<RiakObject>.Success(new RiakObject("foo", "bar", "baz")));
+ AsyncClient.Get("foo", "bar", Tester.HandleResult);
+ Result = Tester.Result;
+ }
+
+ [Test]
+ public void AsyncClientInvokesCorrectClientFunction()
+ {
+ ClientMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<string>(), 2), Times.Once());
+ }
+
+ [Test]
+ public void AsyncClientReturnsCorrectResult()
+ {
+ Result.ShouldNotBeNull();
+ Result.IsSuccess.ShouldBeTrue();
+ Result.Value.ShouldNotBeNull();
+ Result.Value.Bucket.ShouldEqual("foo");
+ Result.Value.Key.ShouldEqual("bar");
+ Result.Value.Value.FromRiakString().ShouldEqual("baz");
+ }
+ }
+
+ [TestFixture]
+ public class WhenCallingGetManyAsync : RiakAsyncClientTestBase<IEnumerable<RiakResult<RiakObject>>>
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ ClientMock.Setup(m => m.Get(It.IsAny<IEnumerable<RiakObjectId>>(), 2)).Returns(new List<RiakResult<RiakObject>>());
+ AsyncClient.Get(new List<RiakObjectId>(), Tester.HandleResult, 2);
+ Result = Tester.Result;
+ }
+
+ [Test]
+ public void AsyncClientInvokesCorrectClientFunction()
+ {
+ ClientMock.Verify(m => m.Get(It.IsAny<IEnumerable<RiakObjectId>>(), 2), Times.Once());
+ }
+
+ [Test]
+ public void AsyncClientReturnsCorrectResult()
+ {
+ Result.ShouldNotBeNull();
+ Result.ShouldBe<List<RiakResult<RiakObject>>>();
+ Result.Count().ShouldEqual(0);
+ }
+ }
+}
View
209 ...edIron.Tests/Comms/RiakClientPingTests.cs → CorrugatedIron.Tests/RiakClientPingTests.cs
@@ -1,104 +1,105 @@
-// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
-//
-// This file is provided to you under the Apache License,
-// Version 2.0 (the "License"); you may not use this file
-// except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-using System.Threading;
-using CorrugatedIron.Tests.Extensions;
-using CorrugatedIron.Messages;
-using Moq;
-using NUnit.Framework;
-
-namespace CorrugatedIron.Tests.Comms.RiakClientPingTests
-{
- internal abstract class RiakClientPingTestBase : RiakClientTestBase<RpbPingReq, RpbPingResp>
- {
- protected RiakResult Response;
-
- public virtual void SetUp()
- {
- SetUpInternal();
- Response = Client.Ping();
- }
-
- [Test]
- public void PbcClientIsInvoked()
- {
- ConnMock.Verify(m => m.PbcWriteRead<RpbPingReq, RpbPingResp>(It.IsAny<RpbPingReq>()), Times.Once());
- }
- }
-
- [TestFixture]
- internal class WhenCallingPingWithError : RiakClientPingTestBase
- {
- [SetUp]
- public override void SetUp()
- {
- Result = RiakResult<RpbPingResp>.Error(ResultCode.CommunicationError);
- base.SetUp();
- }
-
- [Test]
- public void SuccessResultIsReturned()
- {
- Response.IsSuccess.ShouldBeFalse();
- Response.ResultCode.ShouldEqual(ResultCode.CommunicationError);
- }
- }
-
- [TestFixture]
- internal class WhenCallingPingSuccessfully : RiakClientPingTestBase
- {
- [SetUp]
- public override void SetUp()
- {
- Result = RiakResult<RpbPingResp>.Success(new RpbPingResp());
- base.SetUp();
- }
-
- [Test]
- public void SuccessResultIsReturned()
- {
- Response.IsSuccess.ShouldBeTrue();
- }
- }
-
- [TestFixture]
- internal class WhenCallingPingAsynchronously : RiakClientTestBase<RpbPingReq, RpbPingResp>
- {
- private readonly ManualResetEvent _indicator = new ManualResetEvent(false);
- private volatile bool _done = false;
-
- [SetUp]
- public void SetUp()
- {
- Result = RiakResult<RpbPingResp>.Success(new RpbPingResp());
- SetUpInternal();
- }
-
- [Test]
- public void CallbackIsInvokedCorrectly()
- {
- Client.Async.Ping(Callback);
- _indicator.WaitOne();
- _done.ShouldBeTrue();
- }
-
- public void Callback(RiakResult result)
- {
- _done = result.IsSuccess;
- _indicator.Set();
- }
- }
-}
+// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
+//
+// This file is provided to you under the Apache License,
+// Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain
+// a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Threading;
+using CorrugatedIron.Tests.Extensions;
+using CorrugatedIron.Messages;
+using CorrugatedIron.Tests.RiakClientTests;
+using Moq;
+using NUnit.Framework;
+
+namespace CorrugatedIron.Tests.RiakClientPingTests
+{
+ internal abstract class RiakClientPingTestBase : RiakClientTestBase<RpbPingReq, RpbPingResp>
+ {
+ protected RiakResult Response;
+
+ public virtual void SetUp()
+ {
+ SetUpInternal();
+ Response = Client.Ping();
+ }
+
+ [Test]
+ public void PbcClientIsInvoked()
+ {
+ ConnMock.Verify(m => m.PbcWriteRead<RpbPingReq, RpbPingResp>(It.IsAny<RpbPingReq>()), Times.Once());
+ }
+ }
+
+ [TestFixture]
+ internal class WhenCallingPingWithError : RiakClientPingTestBase
+ {
+ [SetUp]
+ public override void SetUp()
+ {
+ Result = RiakResult<RpbPingResp>.Error(ResultCode.CommunicationError);
+ base.SetUp();
+ }
+
+ [Test]
+ public void SuccessResultIsReturned()
+ {
+ Response.IsSuccess.ShouldBeFalse();
+ Response.ResultCode.ShouldEqual(ResultCode.CommunicationError);
+ }
+ }
+
+ [TestFixture]
+ internal class WhenCallingPingSuccessfully : RiakClientPingTestBase
+ {
+ [SetUp]
+ public override void SetUp()
+ {
+ Result = RiakResult<RpbPingResp>.Success(new RpbPingResp());
+ base.SetUp();
+ }
+
+ [Test]
+ public void SuccessResultIsReturned()
+ {
+ Response.IsSuccess.ShouldBeTrue();
+ }
+ }
+
+ [TestFixture]
+ internal class WhenCallingPingAsynchronously : RiakClientTestBase<RpbPingReq, RpbPingResp>
+ {
+ private readonly ManualResetEvent _indicator = new ManualResetEvent(false);
+ private volatile bool _done = false;
+
+ [SetUp]
+ public void SetUp()
+ {
+ Result = RiakResult<RpbPingResp>.Success(new RpbPingResp());
+ SetUpInternal();
+ }
+
+ [Test]
+ public void CallbackIsInvokedCorrectly()
+ {
+ Client.Async.Ping(Callback);
+ _indicator.WaitOne();
+ _done.ShouldBeTrue();
+ }
+
+ public void Callback(RiakResult result)
+ {
+ _done = result.IsSuccess;
+ _indicator.Set();
+ }
+ }
+}
View
216 ...mms/RiakClientSetBucketPropertiesTests.cs → ...sts/RiakClientSetBucketPropertiesTests.cs
@@ -1,108 +1,108 @@
-// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
-//
-// This file is provided to you under the Apache License,
-// Version 2.0 (the "License"); you may not use this file
-// except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using CorrugatedIron.Comms;
-using CorrugatedIron.Messages;
-using CorrugatedIron.Models;
-using CorrugatedIron.Models.Rest;
-using CorrugatedIron.Util;
-using Moq;
-using NUnit.Framework;
-
-namespace CorrugatedIron.Tests.Comms.RiakClientSetBucketPropertiesTests
-{
- public class MockCluster : IRiakCluster
- {
- public Mock<IRiakConnection> ConnectionMock = new Mock<IRiakConnection>();
-
- public void Dispose()
- {
- }
-
- public RiakResult<TResult> UseConnection<TResult>(byte[] clientId, Func<IRiakConnection, RiakResult<TResult>> useFun)
- {
- return useFun(ConnectionMock.Object);
- }
-
- public RiakResult UseConnection(byte[] clientId, Func<IRiakConnection, RiakResult> useFun)
- {
- return useFun(ConnectionMock.Object);
- }
-
- public RiakResult<IEnumerable<TResult>> UseStreamConnection<TResult>(byte[] clientId, Func<IRiakConnection, Action, RiakResult<IEnumerable<TResult>>> useFun)
- {
- throw new NotImplementedException();
- }
- }
-
- public abstract class RiakClientSetBucketPropertiesTestBase
- {
- protected MockCluster Cluster;
- protected RiakClient Client;
- protected byte[] ClientId;
-
- protected RiakClientSetBucketPropertiesTestBase()
- {
- Cluster = new MockCluster();
- ClientId = System.Text.Encoding.Default.GetBytes("fadjskl").Take(4).ToArray();
- Client = new RiakClient(Cluster) {ClientId = ClientId};
- }
- }
-
- [TestFixture]
- public class WhenSettingBucketPropertiesWithExtendedProperties : RiakClientSetBucketPropertiesTestBase
- {
- protected RiakResult Response;
- [SetUp]
- public void SetUp()
- {
- var result = RiakResult<RiakRestResponse>.Success(new RiakRestResponse { StatusCode = System.Net.HttpStatusCode.NoContent });
- Cluster.ConnectionMock.Setup(m => m.RestRequest(It.IsAny<RiakRestRequest>())).Returns(result);
-
- Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true).SetRVal("one"));
- }
-
- [Test]
- public void RestInterfaceIsInvokedWithAppropriateValues()
- {
- Cluster.ConnectionMock.Verify(m => m.RestRequest(It.Is<RiakRestRequest>(r => r.ContentType == RiakConstants.ContentTypes.ApplicationJson
- && r.Method == RiakConstants.Rest.HttpMethod.Put)), Times.Once());
- }
- }
-
- [TestFixture]
- public class WhenSettingBucketPropertiesWithoutExtendedProperties : RiakClientSetBucketPropertiesTestBase
- {
- protected RiakResult Response;
- [SetUp]
- public void SetUp()
- {
- var result = RiakResult<RpbSetBucketResp>.Success(new RpbSetBucketResp());
- Cluster.ConnectionMock.Setup(m => m.PbcWriteRead<RpbSetBucketReq, RpbSetBucketResp>(It.IsAny<RpbSetBucketReq>())).Returns(result);
-
- Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true));
- }
-
- [Test]
- public void PbcInterfaceIsInvokedWithAppropriateValues()
- {
- Cluster.ConnectionMock.Verify(m => m.PbcWriteRead<RpbSetBucketReq, RpbSetBucketResp>(It.Is<RpbSetBucketReq>(r => r.Props.AllowMultiple)), Times.Once());
- }
- }
-}
+// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
+//
+// This file is provided to you under the Apache License,
+// Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain
+// a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using CorrugatedIron.Comms;
+using CorrugatedIron.Messages;
+using CorrugatedIron.Models;
+using CorrugatedIron.Models.Rest;
+using CorrugatedIron.Util;
+using Moq;
+using NUnit.Framework;
+
+namespace CorrugatedIron.Tests.RiakClientSetBucketPropertiesTests
+{
+ public class MockCluster : IRiakCluster
+ {
+ public Mock<IRiakConnection> ConnectionMock = new Mock<IRiakConnection>();
+
+ public void Dispose()
+ {
+ }
+
+ public RiakResult<TResult> UseConnection<TResult>(byte[] clientId, Func<IRiakConnection, RiakResult<TResult>> useFun)
+ {
+ return useFun(ConnectionMock.Object);
+ }
+
+ public RiakResult UseConnection(byte[] clientId, Func<IRiakConnection, RiakResult> useFun)
+ {
+ return useFun(ConnectionMock.Object);
+ }
+
+ public RiakResult<IEnumerable<TResult>> UseStreamConnection<TResult>(byte[] clientId, Func<IRiakConnection, Action, RiakResult<IEnumerable<TResult>>> useFun)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public abstract class RiakClientSetBucketPropertiesTestBase
+ {
+ protected MockCluster Cluster;
+ protected RiakClient Client;
+ protected byte[] ClientId;
+
+ protected RiakClientSetBucketPropertiesTestBase()
+ {
+ Cluster = new MockCluster();
+ ClientId = System.Text.Encoding.Default.GetBytes("fadjskl").Take(4).ToArray();
+ Client = new RiakClient(Cluster) {ClientId = ClientId};
+ }
+ }
+
+ [TestFixture]
+ public class WhenSettingBucketPropertiesWithExtendedProperties : RiakClientSetBucketPropertiesTestBase
+ {
+ protected RiakResult Response;
+ [SetUp]
+ public void SetUp()
+ {
+ var result = RiakResult<RiakRestResponse>.Success(new RiakRestResponse { StatusCode = System.Net.HttpStatusCode.NoContent });
+ Cluster.ConnectionMock.Setup(m => m.RestRequest(It.IsAny<RiakRestRequest>())).Returns(result);
+
+ Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true).SetRVal("one"));
+ }
+
+ [Test]
+ public void RestInterfaceIsInvokedWithAppropriateValues()
+ {
+ Cluster.ConnectionMock.Verify(m => m.RestRequest(It.Is<RiakRestRequest>(r => r.ContentType == RiakConstants.ContentTypes.ApplicationJson
+ && r.Method == RiakConstants.Rest.HttpMethod.Put)), Times.Once());
+ }
+ }
+
+ [TestFixture]
+ public class WhenSettingBucketPropertiesWithoutExtendedProperties : RiakClientSetBucketPropertiesTestBase
+ {
+ protected RiakResult Response;
+ [SetUp]
+ public void SetUp()
+ {
+ var result = RiakResult<RpbSetBucketResp>.Success(new RpbSetBucketResp());
+ Cluster.ConnectionMock.Setup(m => m.PbcWriteRead<RpbSetBucketReq, RpbSetBucketResp>(It.IsAny<RpbSetBucketReq>())).Returns(result);
+
+ Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true));
+ }
+
+ [Test]
+ public void PbcInterfaceIsInvokedWithAppropriateValues()
+ {
+ Cluster.ConnectionMock.Verify(m => m.PbcWriteRead<RpbSetBucketReq, RpbSetBucketResp>(It.Is<RpbSetBucketReq>(r => r.Props.AllowMultiple)), Times.Once());
+ }
+ }
+}
View
102 ...tedIron.Tests/Comms/RiakClientTestBase.cs → CorrugatedIron.Tests/RiakClientTestBase.cs
@@ -1,51 +1,51 @@
-// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
-//
-// This file is provided to you under the Apache License,
-// Version 2.0 (the "License"); you may not use this file
-// except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-using System.Collections.Generic;
-using CorrugatedIron.Comms;
-using CorrugatedIron.Config;
-using Moq;
-
-namespace CorrugatedIron.Tests.Comms
-{
- public abstract class RiakClientTestBase<TRequest, TResult>
- where TResult : new()
- {
- protected RiakResult<TResult> Result;
- protected Mock<IRiakConnection> ConnMock;
- protected Mock<IRiakNodeConfiguration> NodeConfigMock;
- protected Mock<IRiakClusterConfiguration> ClusterConfigMock;
- protected Mock<IRiakConnectionFactory> ConnFactoryMock;
- protected RiakCluster Cluster;
- protected RiakClient Client;
-
- protected void SetUpInternal()
- {
- ConnMock = new Mock<IRiakConnection>();
- ClusterConfigMock = new Mock<IRiakClusterConfiguration>();
- ConnFactoryMock = new Mock<IRiakConnectionFactory>();
- NodeConfigMock = new Mock<IRiakNodeConfiguration>();
-
- ConnMock.Setup(m => m.PbcWriteRead<TRequest, TResult>(It.IsAny<TRequest>())).Returns(() => Result);
- ConnFactoryMock.Setup(m => m.CreateConnection(It.IsAny<IRiakNodeConfiguration>())).Returns(ConnMock.Object);
- NodeConfigMock.SetupGet(m => m.PoolSize).Returns(1);
- ClusterConfigMock.SetupGet(m => m.RiakNodes).Returns(new List<IRiakNodeConfiguration> { NodeConfigMock.Object });
-
- Cluster = new RiakCluster(ClusterConfigMock.Object, new RiakNodeFactory(), ConnFactoryMock.Object);
- Client = new RiakClient(Cluster);
- }
- }
-}
+// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
+//
+// This file is provided to you under the Apache License,
+// Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain
+// a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System.Collections.Generic;
+using CorrugatedIron.Comms;
+using CorrugatedIron.Config;
+using Moq;
+
+namespace CorrugatedIron.Tests.RiakClientTests
+{
+ public abstract class RiakClientTestBase<TRequest, TResult>
+ where TResult : new()
+ {
+ protected RiakResult<TResult> Result;
+ protected Mock<IRiakConnection> ConnMock;
+ protected Mock<IRiakNodeConfiguration> NodeConfigMock;
+ protected Mock<IRiakClusterConfiguration> ClusterConfigMock;
+ protected Mock<IRiakConnectionFactory> ConnFactoryMock;
+ protected RiakCluster Cluster;
+ protected RiakClient Client;
+
+ protected void SetUpInternal()
+ {
+ ConnMock = new Mock<IRiakConnection>();
+ ClusterConfigMock = new Mock<IRiakClusterConfiguration>();
+ ConnFactoryMock = new Mock<IRiakConnectionFactory>();
+ NodeConfigMock = new Mock<IRiakNodeConfiguration>();
+
+ ConnMock.Setup(m => m.PbcWriteRead<TRequest, TResult>(It.IsAny<TRequest>())).Returns(() => Result);
+ ConnFactoryMock.Setup(m => m.CreateConnection(It.IsAny<IRiakNodeConfiguration>())).Returns(ConnMock.Object);
+ NodeConfigMock.SetupGet(m => m.PoolSize).Returns(1);
+ ClusterConfigMock.SetupGet(m => m.RiakNodes).Returns(new List<IRiakNodeConfiguration> { NodeConfigMock.Object });
+
+ Cluster = new RiakCluster(ClusterConfigMock.Object, new RiakNodeFactory(), ConnFactoryMock.Object);
+ Client = new RiakClient(Cluster);
+ }
+ }
+}
View
2  ...ugatedIron.Tests/Comms/RiakClientTests.cs → CorrugatedIron.Tests/RiakClientTests.cs
@@ -5,7 +5,7 @@
using Moq;
using NUnit.Framework;
-namespace CorrugatedIron.Tests.Comms
+namespace CorrugatedIron.Tests.RiakClientTests
{
[TestFixture]
internal class RiakClientTests
View
23 CorrugatedIron/RiakAsyncClient.cs
@@ -73,18 +73,21 @@ public void Ping(Action<RiakResult> callback)
ExecAsync(() => callback(_client.Ping()));
}
- public void Get(string bucket, string key, Action<RiakResult<RiakObject>> callback,
- uint rVal = RiakConstants.Defaults.RVal)
+ public void Get(string bucket, string key, Action<RiakResult<RiakObject>> callback, uint rVal = RiakConstants.Defaults.RVal)
{
ExecAsync(() => callback(_client.Get(bucket, key, rVal)));
}
- public void Get(RiakObjectId objectId, Action<RiakResult<RiakObject>> callback,
- uint rVal = RiakConstants.Defaults.RVal)
+ public void Get(RiakObjectId objectId, Action<RiakResult<RiakObject>> callback, uint rVal = RiakConstants.Defaults.RVal)
{
ExecAsync(() => callback(_client.Get(objectId.Bucket, objectId.Key, rVal)));
}
+ public void Get(IEnumerable<RiakObjectId> bucketKeyPairs, Action<IEnumerable<RiakResult<RiakObject>>> callback, uint rVal = RiakConstants.Defaults.RVal)
+ {
+ ExecAsync(() => callback(_client.Get(bucketKeyPairs, rVal)));
+ }
+
public void Put(IEnumerable<RiakObject> values, Action<IEnumerable<RiakResult<RiakObject>>> callback, RiakPutOptions options)
{
ExecAsync(() => callback(_client.Put(values, options)));
@@ -95,8 +98,7 @@ public void Put(RiakObject value, Action<RiakResult<RiakObject>> callback, RiakP
ExecAsync(() => callback(_client.Put(value, options)));
}
- public void Delete(string bucket, string key, Action<RiakResult> callback,
- uint rwVal = RiakConstants.Defaults.RVal)
+ public void Delete(string bucket, string key, Action<RiakResult> callback, uint rwVal = RiakConstants.Defaults.RVal)
{
ExecAsync(() => callback(_client.Delete(bucket, key, rwVal)));
}
@@ -141,8 +143,7 @@ public void StreamListKeys(string bucket, Action<RiakResult<IEnumerable<string>>
ExecAsync(() => callback(_client.StreamListKeys(bucket)));
}
- public void GetBucketProperties(string bucket, Action<RiakResult<RiakBucketProperties>> callback,
- bool extended = false)
+ public void GetBucketProperties(string bucket, Action<RiakResult<RiakBucketProperties>> callback, bool extended = false)
{
ExecAsync(() => callback(_client.GetBucketProperties(bucket, extended)));
}
@@ -162,12 +163,6 @@ public void GetServerInfo(Action<RiakResult<RiakServerInfo>> callback)
ExecAsync(() => callback(_client.GetServerInfo()));
}
- public void Get(IEnumerable<RiakObjectId> bucketKeyPairs, Action<IEnumerable<RiakResult<RiakObject>>> callback,
- uint rVal = RiakConstants.Defaults.RVal)
- {
- ExecAsync(() => callback(_client.Get(bucketKeyPairs, rVal)));
- }
-
private static void ExecAsync(Action action)
{
ThreadPool.QueueUserWorkItem(o => action());
Please sign in to comment.
Something went wrong with that request. Please try again.