From a33ad0cec370910d8f62bfb9fe25a8a8583672fe Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 23 Jun 2010 14:54:43 -0500 Subject: [PATCH] Finishing up unit tests. 291 passing --- src/CouchDBIndexService/Class1.cs | 36 +++++++ .../CouchDBIndexService.csproj | 97 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++ src/Relax.Lucene/Relax.Lucene.csproj | 2 +- src/Relax.sln | 12 +++ .../when_getting_all_documents.cs | 41 ++++++++ .../when_getting_all_documents_by_ids.cs | 40 ++++++++ .../when_getting_all_documents_paged.cs | 40 ++++++++ .../when_getting_doc_by_id.cs | 34 +++++++ .../when_getting_doc_by_id_and_rev.cs | 29 ++++++ .../when_getting_documents_by_key_range.cs | 21 ++++ .../GettingDocuments/with_get_all_docs.cs | 42 ++++++++ .../with_get_all_docs_by_ids.cs | 28 ++++++ .../with_get_all_docs_paged.cs | 12 +++ .../with_get_doc_by_id_and_rev_setup.cs | 12 +++ .../with_get_doc_by_id_setup.cs | 24 +++++ .../GettingDocuments/with_get_doc_by_range.cs | 39 ++++++++ tests/Relax.Tests.csproj | 30 +++--- tests/Repository/when_getting_attachment.cs | 27 ++++++ .../when_getting_documents_by_id.cs | 30 ++++++ .../when_getting_documents_by_range.cs | 30 ++++++ tests/Repository/with_get_attachment.cs | 29 ++++++ .../Repository/with_get_documents_by_keys.cs | 27 ++++++ .../Repository/with_get_documents_by_range.cs | 23 +++++ 24 files changed, 728 insertions(+), 13 deletions(-) create mode 100644 src/CouchDBIndexService/Class1.cs create mode 100644 src/CouchDBIndexService/CouchDBIndexService.csproj create mode 100644 src/CouchDBIndexService/Properties/AssemblyInfo.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_all_documents.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_all_documents_by_ids.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_all_documents_paged.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_doc_by_id.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs create mode 100644 tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs create mode 100644 tests/Commands/GettingDocuments/with_get_all_docs.cs create mode 100644 tests/Commands/GettingDocuments/with_get_all_docs_by_ids.cs create mode 100644 tests/Commands/GettingDocuments/with_get_all_docs_paged.cs create mode 100644 tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs create mode 100644 tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs create mode 100644 tests/Commands/GettingDocuments/with_get_doc_by_range.cs create mode 100644 tests/Repository/when_getting_attachment.cs create mode 100644 tests/Repository/when_getting_documents_by_id.cs create mode 100644 tests/Repository/when_getting_documents_by_range.cs create mode 100644 tests/Repository/with_get_attachment.cs create mode 100644 tests/Repository/with_get_documents_by_keys.cs create mode 100644 tests/Repository/with_get_documents_by_range.cs diff --git a/src/CouchDBIndexService/Class1.cs b/src/CouchDBIndexService/Class1.cs new file mode 100644 index 0000000..0de1754 --- /dev/null +++ b/src/CouchDBIndexService/Class1.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Relax; +using Relax.Lucene; +using Symbiote.Core; +using Symbiote.Daemon; +using Symbiote.Log4Net; +using Symbiote.Lucene; +using Symbiote.Restfully; + +namespace CouchDBIndexService +{ + class Program + { + static void Main(string[] args) + { + Assimilate + .Core() + .Relax(x => x.UseDefaults().Preauthorize("admin", "p@ssw0rd")) + .Lucene(x => x.UseDefaults()) + .RelaxLuceneService(x => x.UseDefaults().IndexDatabase("post")) + .HttpServiceHost(x => x.UseDefaults().HostService()) + .Dependencies(x => x.For().Use()) + .Daemon(x => x + .Name("Relax.Lucene") + .DisplayName("Relax Lucene Service") + .Description("A Lucene indexing and query service for CouchDB") + .Arguments(args) + ) + .AddConsoleLogger(x => x.Info().MessageLayout(p => p.TimeStamp().Message())) + .RunDaemon(); + } + } +} diff --git a/src/CouchDBIndexService/CouchDBIndexService.csproj b/src/CouchDBIndexService/CouchDBIndexService.csproj new file mode 100644 index 0000000..df5f5fe --- /dev/null +++ b/src/CouchDBIndexService/CouchDBIndexService.csproj @@ -0,0 +1,97 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {681B03FD-66ED-48D8-8C14-EC49452CDBDC} + Exe + Properties + CouchDBIndexService + CouchDBIndexService + v4.0 + 512 + + + true + full + false + ..\..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\..\lib\log4net.dll + + + ..\..\lib\Lucene.Net.dll + + + False + ..\..\lib\StructureMap.dll + + + False + ..\..\lib\Symbiote.Core.dll + + + ..\..\lib\Symbiote.Daemon.dll + + + ..\..\lib\Symbiote.Log4Net.dll + + + ..\..\lib\Symbiote.Lucene.dll + + + False + ..\..\lib\Symbiote.Restfully.dll + + + + + + + + + + ..\..\lib\Topshelf.dll + + + + + + + + + {EAC2B6B2-8F3C-49A8-88B0-DA6CC04C4935} + Relax.Lucene + + + {3A8D40A3-96F9-4878-902E-7CBC3A82AEDD} + Relax + + + + + \ No newline at end of file diff --git a/src/CouchDBIndexService/Properties/AssemblyInfo.cs b/src/CouchDBIndexService/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c976510 --- /dev/null +++ b/src/CouchDBIndexService/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CouchDBIndexService")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("CouchDBIndexService")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d8cec351-e25d-4e3c-90d3-9b44ed264fa8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Relax.Lucene/Relax.Lucene.csproj b/src/Relax.Lucene/Relax.Lucene.csproj index a977668..b998379 100644 --- a/src/Relax.Lucene/Relax.Lucene.csproj +++ b/src/Relax.Lucene/Relax.Lucene.csproj @@ -17,7 +17,7 @@ true full false - bin\Debug\ + ..\..\bin\ DEBUG;TRACE prompt 4 diff --git a/src/Relax.sln b/src/Relax.sln index c5c0580..ae65ab2 100644 --- a/src/Relax.sln +++ b/src/Relax.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Relax.Lucene.Tests", "..\te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Relax.Overflow", "..\demo\Relax.Overflow\Relax.Overflow.csproj", "{03875D45-98AB-4C98-B569-A8A9EE16252D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CouchDBIndexService", "CouchDBIndexService\CouchDBIndexService.csproj", "{681B03FD-66ED-48D8-8C14-EC49452CDBDC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -84,6 +86,16 @@ Global {03875D45-98AB-4C98-B569-A8A9EE16252D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {03875D45-98AB-4C98-B569-A8A9EE16252D}.Release|Mixed Platforms.Build.0 = Release|Any CPU {03875D45-98AB-4C98-B569-A8A9EE16252D}.Release|x86.ActiveCfg = Release|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Debug|x86.ActiveCfg = Debug|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Release|Any CPU.Build.0 = Release|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {681B03FD-66ED-48D8-8C14-EC49452CDBDC}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/tests/Commands/GettingDocuments/when_getting_all_documents.cs b/tests/Commands/GettingDocuments/when_getting_all_documents.cs new file mode 100644 index 0000000..c9bf34b --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_all_documents.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Json; + +namespace Relax.Tests.Commands +{ + public class when_getting_all_documents : with_get_all_docs + { + protected static CommandResult result; + protected static ViewResult viewResult; + protected static string json; + + private Because of = () => + { + result = command.GetDocuments(); + viewResult = result.GetResultAs>(); + json = result.Json.Replace("\r\n", "").Replace(" ", ""); + }; + + private It should_produce_expected_json = () => json.ShouldEqual(response); + + private It should_have_two_rows = () => ShouldExtensionMethods.ShouldEqual(viewResult.GetList().Count(), 2); + + private It should_create_valid_instances = () => + { + var firstDoc = viewResult.GetList().ToList()[0]; + firstDoc.DocumentId.ShouldEqual("1"); + firstDoc.DocumentRevision.ShouldEqual("1"); + firstDoc.Message.ShouldEqual("Test1"); + + var secondDoc = viewResult.GetList().ToList()[1]; + secondDoc.DocumentId.ShouldEqual("2"); + secondDoc.DocumentRevision.ShouldEqual("1"); + secondDoc.Message.ShouldEqual("Test2"); + }; + + private It should_call_action = () => mockAction.Verify(); + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/when_getting_all_documents_by_ids.cs b/tests/Commands/GettingDocuments/when_getting_all_documents_by_ids.cs new file mode 100644 index 0000000..ede6660 --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_all_documents_by_ids.cs @@ -0,0 +1,40 @@ +using System.Linq; +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Json; + +namespace Relax.Tests.Commands +{ + public class when_getting_all_documents_by_ids : with_get_all_docs_by_ids + { + protected static CommandResult result; + protected static ViewResult viewResult; + protected static string json; + + private Because of = () => + { + result = command.GetDocuments(new object[] {"1","2"}); + viewResult = result.GetResultAs>(); + json = result.Json.Replace("\r\n", "").Replace(" ", ""); + }; + + private It should_produce_expected_json = () => json.ShouldEqual(response); + + private It should_have_two_rows = () => ShouldExtensionMethods.ShouldEqual(viewResult.GetList().Count(), 2); + + private It should_create_valid_instances = () => + { + var firstDoc = viewResult.GetList().ToList()[0]; + firstDoc.DocumentId.ShouldEqual("1"); + firstDoc.DocumentRevision.ShouldEqual("1"); + firstDoc.Message.ShouldEqual("Test1"); + + var secondDoc = viewResult.GetList().ToList()[1]; + secondDoc.DocumentId.ShouldEqual("2"); + secondDoc.DocumentRevision.ShouldEqual("1"); + secondDoc.Message.ShouldEqual("Test2"); + }; + + private It should_call_action = () => mockAction.Verify(); + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/when_getting_all_documents_paged.cs b/tests/Commands/GettingDocuments/when_getting_all_documents_paged.cs new file mode 100644 index 0000000..7c22d15 --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_all_documents_paged.cs @@ -0,0 +1,40 @@ +using System.Linq; +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Json; + +namespace Relax.Tests.Commands +{ + public class when_getting_all_documents_paged : with_get_docs_paged + { + protected static CommandResult result; + protected static ViewResult viewResult; + protected static string json; + + private Because of = () => + { + result = command.GetDocumentsPaged(2, 3); + viewResult = result.GetResultAs>(); + json = result.Json.Replace("\r\n", "").Replace(" ", ""); + }; + + private It should_produce_expected_json = () => json.ShouldEqual(response); + + private It should_have_two_rows = () => ShouldExtensionMethods.ShouldEqual(viewResult.GetList().Count(), 2); + + private It should_create_valid_instances = () => + { + var firstDoc = viewResult.GetList().ToList()[0]; + firstDoc.DocumentId.ShouldEqual("1"); + firstDoc.DocumentRevision.ShouldEqual("1"); + firstDoc.Message.ShouldEqual("Test1"); + + var secondDoc = viewResult.GetList().ToList()[1]; + secondDoc.DocumentId.ShouldEqual("2"); + secondDoc.DocumentRevision.ShouldEqual("1"); + secondDoc.Message.ShouldEqual("Test2"); + }; + + private It should_call_action = () => mockAction.Verify(); + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/when_getting_doc_by_id.cs b/tests/Commands/GettingDocuments/when_getting_doc_by_id.cs new file mode 100644 index 0000000..6458ec6 --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_doc_by_id.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Machine.Specifications; +using Relax.Impl.Commands; +using It = Machine.Specifications.It; + +namespace Relax.Tests.Commands +{ + public class when_getting_doc_by_id : with_get_doc_by_id_setup + { + protected static CommandResult result; + protected static TestDoc model; + protected static string json; + + private Because of = () => + { + result = command.GetDocument("1"); + model = result.GetResultAs(); + json = result.Json.Replace("\r\n", "").Replace(" ", ""); + }; + + private It should_produce_expected_json = () => json.ShouldEqual(response); + + private It should_create_valid_instance = () => + { + model.DocumentId.ShouldEqual("1"); + model.DocumentRevision.ShouldEqual("1"); + model.Message.ShouldEqual("Test"); + }; + private It should_call_action = () => mockAction.Verify(); + } +} diff --git a/tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs b/tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs new file mode 100644 index 0000000..30e08ca --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs @@ -0,0 +1,29 @@ +using Machine.Specifications; +using Relax.Impl.Commands; + +namespace Relax.Tests.Commands +{ + public class when_getting_doc_by_id_and_rev : with_get_doc_by_id_and_rev_setup + { + protected static CommandResult result; + protected static TestDoc model; + protected static string json; + + private Because of = () => + { + result = command.GetDocument("1", "1"); + model = result.GetResultAs(); + json = result.Json.Replace("\r\n", "").Replace(" ", ""); + }; + + private It should_produce_expected_json = () => json.ShouldEqual(response); + + private It should_create_valid_instance = () => + { + model.DocumentId.ShouldEqual("1"); + model.DocumentRevision.ShouldEqual("1"); + model.Message.ShouldEqual("Test"); + }; + private It should_call_action = () => mockAction.Verify(); + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs b/tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs new file mode 100644 index 0000000..d92ae12 --- /dev/null +++ b/tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs @@ -0,0 +1,21 @@ +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Json; + +namespace Relax.Tests.Commands +{ + public class when_getting_documents_by_key_range : with_get_doc_by_range + { + protected static CommandResult result; + protected static ViewResult viewResult; + protected static string json; + + private Because of = () => + { + result = command.GetDocumentsInRange("doc 1", "doc 2"); + viewResult = result.GetResultAs>(); + }; + + private It should_have_one_document = () => viewResult.TotalRows.ShouldEqual(1); + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_all_docs.cs b/tests/Commands/GettingDocuments/with_get_all_docs.cs new file mode 100644 index 0000000..9b3676e --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_all_docs.cs @@ -0,0 +1,42 @@ +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Http; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_all_docs : with_command_factory + { + protected static string response; + protected static string url; + protected static GetAllDocumentsCommand command; + + private Establish context = () => + { + url = @"http://localhost:5984/relax/_all_docs?include_docs=true"; + response = @"{""total_rows"":""2"",""offset"":""0"",""rows"":[{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test1""}},{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""2"",""_rev"":""1"",""Message"":""Test2""}}]}"; + mockAction + .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) + .Returns(response) + .AtMostOnce(); + command = factory.CreateGetAllDocumentsCommand(); + }; + } + + public abstract class with_get_docs_paged : with_command_factory + { + protected static string response; + protected static string url; + protected static GetDocumentsPagedCommand command; + + private Establish context = () => + { + url = @"http://localhost:5984/relax/_all_docs?include_docs=true&skip=4&limit=2"; + response = @"{""total_rows"":""2"",""offset"":""0"",""rows"":[{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test1""}},{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""2"",""_rev"":""1"",""Message"":""Test2""}}]}"; + mockAction + .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) + .Returns(response) + .AtMostOnce(); + command = factory.CreateGetDocumentsPagedCommand(); + }; + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_all_docs_by_ids.cs b/tests/Commands/GettingDocuments/with_get_all_docs_by_ids.cs new file mode 100644 index 0000000..73f84fa --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_all_docs_by_ids.cs @@ -0,0 +1,28 @@ +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Http; +using Relax.Impl.Json; +using Symbiote.Core.Extensions; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_all_docs_by_ids : with_command_factory + { + protected static KeyList keyList; + protected static string response; + protected static string url; + protected static GetDocumentsByIdsCommand command; + + private Establish context = () => + { + keyList = new KeyList() { keys = new object[] { "1", "2" } }; + response = @"{""total_rows"":""2"",""offset"":""0"",""rows"":[{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test1""}},{""doc"":{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""2"",""_rev"":""1"",""Message"":""Test2""}}]}"; + url = @"http://localhost:5984/relax/_all_docs?include_docs=true"; + mockAction + .Setup(x => x.Post(Moq.It.Is(i => i.ToString() == url), keyList.ToJson(false))) + .Returns(response) + .AtMostOnce(); + command = factory.CreateGetDocumentsByIdsCommand(); + }; + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_all_docs_paged.cs b/tests/Commands/GettingDocuments/with_get_all_docs_paged.cs new file mode 100644 index 0000000..3aadf91 --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_all_docs_paged.cs @@ -0,0 +1,12 @@ +using Machine.Specifications; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_all_docs_paged : with_get_all_docs + { + private Establish context = () => + { + url = @"http://localhost:5984/relax/_all_docs?include_docs=true&skip=4&limit=2"; + }; + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs b/tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs new file mode 100644 index 0000000..02591c1 --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs @@ -0,0 +1,12 @@ +using Machine.Specifications; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_doc_by_id_and_rev_setup : with_get_doc_by_id_setup + { + private Establish context = () => + { + url = @"http://localhost:5984/relax/1?rev=1"; + }; + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs b/tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs new file mode 100644 index 0000000..ba0d801 --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs @@ -0,0 +1,24 @@ +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Http; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_doc_by_id_setup : with_command_factory + { + protected static string response; + protected static string url; + protected static GetDocumentCommand command; + + private Establish context = () => + { + url = @"http://localhost:5984/relax/1"; + response = @"{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test""}"; + mockAction + .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) + .Returns(response) + .AtMostOnce(); + command = factory.CreateGetDocumentCommand(); + }; + } +} \ No newline at end of file diff --git a/tests/Commands/GettingDocuments/with_get_doc_by_range.cs b/tests/Commands/GettingDocuments/with_get_doc_by_range.cs new file mode 100644 index 0000000..2bcc7a2 --- /dev/null +++ b/tests/Commands/GettingDocuments/with_get_doc_by_range.cs @@ -0,0 +1,39 @@ +using Machine.Specifications; +using Relax.Impl.Commands; +using Relax.Impl.Http; + +namespace Relax.Tests.Commands +{ + public abstract class with_get_doc_by_range : with_command_factory + { + protected static string response; + protected static string url; + protected static GetDocumentsInRangeCommand command; + + private Establish context = () => + { + url = @"http://localhost:5984/relax/_all_docs?include_docs=true&startkey=""doc+1""&endkey=""doc+2"""; + response = @" +{ + total_rows: 1, + offset: 0, + rows: + [ + { + doc: { + $type: ""Relax.Tests.Commands.TestDoc, Relax.Tests"", + _id: ""1"", + _rev: ""1"", + Message: ""Test"" + } + } + ] +}"; + mockAction + .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) + .Returns(response) + .AtMostOnce(); + command = factory.CreateGetDocumentsInRangeCommand(); + }; + } +} \ No newline at end of file diff --git a/tests/Relax.Tests.csproj b/tests/Relax.Tests.csproj index c3cf169..cf4d6f4 100644 --- a/tests/Relax.Tests.csproj +++ b/tests/Relax.Tests.csproj @@ -100,14 +100,14 @@ - - - - - - - - + + + + + + + + @@ -125,12 +125,12 @@ - - + + - - + + @@ -155,10 +155,16 @@ + + + + + + diff --git a/tests/Repository/when_getting_attachment.cs b/tests/Repository/when_getting_attachment.cs new file mode 100644 index 0000000..bf009b6 --- /dev/null +++ b/tests/Repository/when_getting_attachment.cs @@ -0,0 +1,27 @@ +using System; +using System.Text; +using Machine.Specifications; +using Relax.Tests.Commands; + +namespace Relax.Tests.Repository +{ + public class when_getting_attachment : with_get_attachment + { + protected static Tuple attachmentResult; + protected static string contentResult; + protected static Exception exception; + + private Because of = () => + { + exception = + Catch.Exception( + () => attachmentResult = repository.GetAttachment("1", "myattachment")); + contentResult = Encoding.UTF8.GetString(attachmentResult.Item2); + }; + + private It should_get_correct_attachment = () => attachmentResult.Item1.ShouldEqual("myattachment"); + private It should_have_correct_content = () => contentResult.ShouldEqual(content); + private It should_get_documents_without_exception = () => exception.ShouldBeNull(); + private It should_call_get_correctly = () => commandMock.VerifyAll(); + } +} \ No newline at end of file diff --git a/tests/Repository/when_getting_documents_by_id.cs b/tests/Repository/when_getting_documents_by_id.cs new file mode 100644 index 0000000..f773979 --- /dev/null +++ b/tests/Repository/when_getting_documents_by_id.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using Machine.Specifications; +using Relax.Tests.Commands; + +namespace Relax.Tests.Repository +{ + public class when_getting_documents_by_id : with_get_documents_by_keys + { + protected static IList records; + protected static Exception exception; + + private Because of = () => + { + exception = + Catch.Exception( + () => records = repository.GetAllByKeys(new object[] { "1" })); + }; + + private It should_get_documents_without_exception = () => exception.ShouldBeNull(); + private It should_get_one_record = () => records.Count.ShouldEqual(1); + private It should_get_right_record = () => + { + records[0].DocumentId.ShouldEqual("1"); + records[0].Message.ShouldEqual("Hello"); + records[0].DocumentRevision.ShouldEqual("2"); + }; + private It should_call_get_correctly = () => commandMock.VerifyAll(); + } +} \ No newline at end of file diff --git a/tests/Repository/when_getting_documents_by_range.cs b/tests/Repository/when_getting_documents_by_range.cs new file mode 100644 index 0000000..caad725 --- /dev/null +++ b/tests/Repository/when_getting_documents_by_range.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using Machine.Specifications; +using Relax.Tests.Commands; + +namespace Relax.Tests.Repository +{ + public class when_getting_documents_by_range : with_get_documents_by_range + { + protected static IList records; + protected static Exception exception; + + private Because of = () => + { + exception = + Catch.Exception( + () => records = repository.GetAllBetweenKeys("1","2")); + }; + + private It should_get_documents_without_exception = () => exception.ShouldBeNull(); + private It should_get_one_record = () => records.Count.ShouldEqual(1); + private It should_get_right_record = () => + { + records[0].DocumentId.ShouldEqual("1"); + records[0].Message.ShouldEqual("Hello"); + records[0].DocumentRevision.ShouldEqual("2"); + }; + private It should_call_get_correctly = () => commandMock.VerifyAll(); + } +} \ No newline at end of file diff --git a/tests/Repository/with_get_attachment.cs b/tests/Repository/with_get_attachment.cs new file mode 100644 index 0000000..9f23dd4 --- /dev/null +++ b/tests/Repository/with_get_attachment.cs @@ -0,0 +1,29 @@ +using System; +using System.Text; +using Machine.Specifications; +using Relax.Impl.Http; + +namespace Relax.Tests.Repository +{ + public abstract class with_get_attachment : with_document_repository + { + protected static Tuple attachment; + protected static string content; + + private Establish context = () => + { + uri = new CouchUri("http", "localhost", 5984, "relax") + .Id("1") + .Attachment("myattachment"); + + content = "This is some content. Huzzah."; + var bytes = Encoding.UTF8.GetBytes(content); + attachment = Tuple.Create("myattachment", bytes); + + commandMock.Setup(x => x.GetAttachment(couchUri)) + .Returns(attachment); + + WireUpCommandMock(commandMock.Object); + }; + } +} \ No newline at end of file diff --git a/tests/Repository/with_get_documents_by_keys.cs b/tests/Repository/with_get_documents_by_keys.cs new file mode 100644 index 0000000..6641ee7 --- /dev/null +++ b/tests/Repository/with_get_documents_by_keys.cs @@ -0,0 +1,27 @@ +using Machine.Specifications; +using Relax.Impl.Http; +using Relax.Impl.Json; +using Symbiote.Core.Extensions; + +namespace Relax.Tests.Repository +{ + public abstract class with_get_documents_by_keys : with_document_repository + { + protected static KeyList keyList; + private Establish context = () => + { + uri = new CouchUri("http", "localhost", 5984, "relax") + .ListAll() + .IncludeDocuments(); + + keyList = new KeyList() {keys = new object[] {"1"}}; + var jsonKeyList = keyList.ToJson(false); + + commandMock.Setup(x => x.Post(couchUri, jsonKeyList)) + .Returns( + "{ offset: \"0\", total_rows: \"2\", rows : [ { id : \"1\", key : \"1\", doc : {_id : \"1\", _rev : \"2\", Message : \"Hello\" } } ] }"); + + WireUpCommandMock(commandMock.Object); + }; + } +} \ No newline at end of file diff --git a/tests/Repository/with_get_documents_by_range.cs b/tests/Repository/with_get_documents_by_range.cs new file mode 100644 index 0000000..d11e488 --- /dev/null +++ b/tests/Repository/with_get_documents_by_range.cs @@ -0,0 +1,23 @@ +using Machine.Specifications; +using Relax.Impl.Http; + +namespace Relax.Tests.Repository +{ + public abstract class with_get_documents_by_range : with_document_repository + { + private Establish context = () => + { + uri = new CouchUri("http", "localhost", 5984, "relax") + .ListAll() + .IncludeDocuments() + .StartKey("1") + .EndKey("2"); + + commandMock.Setup(x => x.Get(couchUri)) + .Returns( + "{ offset: \"0\", total_rows: \"2\", rows : [ { id : \"1\", key : \"1\", doc : {_id : \"1\", _rev : \"2\", Message : \"Hello\" } } ] }"); + + WireUpCommandMock(commandMock.Object); + }; + } +} \ No newline at end of file