From 3fe68bff93b89202a01ee5b65e63d267d986d39e Mon Sep 17 00:00:00 2001 From: richtea Date: Wed, 5 Jan 2011 16:06:45 +0000 Subject: [PATCH] Fixed errors where AddParameters were not passed through into operations --- SolrNet.Tests/SolrServerTests.cs | 127 ++++++++++++++++++++++++++++++- SolrNet/Impl/SolrServer.cs | 4 +- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/SolrNet.Tests/SolrServerTests.cs b/SolrNet.Tests/SolrServerTests.cs index 82b44a39f..6d1e2f376 100644 --- a/SolrNet.Tests/SolrServerTests.cs +++ b/SolrNet.Tests/SolrServerTests.cs @@ -28,6 +28,130 @@ namespace SolrNet.Tests { [TestFixture] public class SolrServerTests { + + [Test] + public void Add_single_doc_calls_operations_with_null_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Null)) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new TestDocument(); + s.Add(t); + }); + } + + [Test] + public void Add_single_doc_with_add_parameters_calls_operations_with_same_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + var parameters = new AddParameters { CommitWithin = 4343 }; + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Equal(parameters))) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new TestDocument(); + s.Add(t, parameters); + }); + } + + [Test] + public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Null)) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new TestDocument(); + s.AddWithBoost(t, 2.1); + }); + } + + [Test] + public void AddWithBoost_single_doc_with_add_parameters_calls_operations_with_same_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + var parameters = new AddParameters { CommitWithin = 4343 }; + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Equal(parameters))) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new TestDocument(); + s.AddWithBoost(t, 2.1, parameters); + }); + } + + [Test] + public void Add_enumerable_calls_operations_with_null_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Null)) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new[] { new TestDocument(), new TestDocument() }; + s.Add(t); + }); + } + + [Test] + public void Add_enumerable_with_add_parameters_calls_operations_with_same_add_parameters() + { + var mocks = new MockRepository(); + var basicServer = mocks.StrictMock>(); + var mapper = mocks.StrictMock(); + var validationManager = mocks.StrictMock(); + var parameters = new AddParameters { CommitWithin = 4343 }; + With.Mocks(mocks) + .Expecting(() => + Expect.Call( + basicServer.AddWithBoost(Arg>>.Is.Anything, Arg.Is.Equal(parameters))) + .Repeat.Once()) + .Verify(() => + { + var s = new SolrServer(basicServer, mapper, validationManager); + var t = new[] { new TestDocument(), new TestDocument() }; + s.Add(t, parameters); + }); + } + [Test] public void Ping() { var mocks = new MockRepository(); @@ -62,7 +186,8 @@ public void GetSchema() { .Expecting(() => Expect.Call(basicServer.GetSchema()) .Repeat.Once() .Return(new SolrSchema())) - .Verify(() => { + .Verify(() => + { var s = new SolrServer(basicServer, mapper, validationManager); s.GetSchema(); }); diff --git a/SolrNet/Impl/SolrServer.cs b/SolrNet/Impl/SolrServer.cs index fe59c0737..9eb7d702c 100644 --- a/SolrNet/Impl/SolrServer.cs +++ b/SolrNet/Impl/SolrServer.cs @@ -123,7 +123,7 @@ public ResponseHeader AddWithBoost(T doc, double boost) { } public ResponseHeader AddWithBoost(T doc, double boost, AddParameters parameters) { - return ((ISolrOperations)this).AddWithBoost(new[] { new KeyValuePair(doc, boost) }); + return ((ISolrOperations)this).AddWithBoost(new[] { new KeyValuePair(doc, boost) }, parameters); } public ResponseHeader Add(IEnumerable docs) { @@ -199,7 +199,7 @@ public ResponseHeader Add(T doc) { } public ResponseHeader Add(T doc, AddParameters parameters) { - return Add(new[] { doc }); + return Add(new[] { doc }, parameters); } public SolrSchema GetSchema() {