Permalink
Browse files

Finishing up unit tests. 291 passing

  • Loading branch information...
1 parent 67ddd65 commit a33ad0cec370910d8f62bfb9fe25a8a8583672fe @arobson arobson committed Jun 23, 2010
Showing with 728 additions and 13 deletions.
  1. +36 −0 src/CouchDBIndexService/Class1.cs
  2. +97 −0 src/CouchDBIndexService/CouchDBIndexService.csproj
  3. +36 −0 src/CouchDBIndexService/Properties/AssemblyInfo.cs
  4. +1 −1 src/Relax.Lucene/Relax.Lucene.csproj
  5. +12 −0 src/Relax.sln
  6. +41 −0 tests/Commands/GettingDocuments/when_getting_all_documents.cs
  7. +40 −0 tests/Commands/GettingDocuments/when_getting_all_documents_by_ids.cs
  8. +40 −0 tests/Commands/GettingDocuments/when_getting_all_documents_paged.cs
  9. +34 −0 tests/Commands/GettingDocuments/when_getting_doc_by_id.cs
  10. +29 −0 tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs
  11. +21 −0 tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs
  12. +42 −0 tests/Commands/GettingDocuments/with_get_all_docs.cs
  13. +28 −0 tests/Commands/GettingDocuments/with_get_all_docs_by_ids.cs
  14. +12 −0 tests/Commands/GettingDocuments/with_get_all_docs_paged.cs
  15. +12 −0 tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs
  16. +24 −0 tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs
  17. +39 −0 tests/Commands/GettingDocuments/with_get_doc_by_range.cs
  18. +18 −12 tests/Relax.Tests.csproj
  19. +27 −0 tests/Repository/when_getting_attachment.cs
  20. +30 −0 tests/Repository/when_getting_documents_by_id.cs
  21. +30 −0 tests/Repository/when_getting_documents_by_range.cs
  22. +29 −0 tests/Repository/with_get_attachment.cs
  23. +27 −0 tests/Repository/with_get_documents_by_keys.cs
  24. +23 −0 tests/Repository/with_get_documents_by_range.cs
View
36 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<IRelaxQueryService>())
+ .Dependencies(x => x.For<IRelaxQueryService>().Use<RelaxQueryService>())
+ .Daemon(x => x
+ .Name("Relax.Lucene")
+ .DisplayName("Relax Lucene Service")
+ .Description("A Lucene indexing and query service for CouchDB")
+ .Arguments(args)
+ )
+ .AddConsoleLogger<RelaxIndexingService>(x => x.Info().MessageLayout(p => p.TimeStamp().Message()))
+ .RunDaemon();
+ }
+ }
+}
View
97 src/CouchDBIndexService/CouchDBIndexService.csproj
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{681B03FD-66ED-48D8-8C14-EC49452CDBDC}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>CouchDBIndexService</RootNamespace>
+ <AssemblyName>CouchDBIndexService</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\bin\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="log4net">
+ <HintPath>..\..\lib\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="Lucene.Net">
+ <HintPath>..\..\lib\Lucene.Net.dll</HintPath>
+ </Reference>
+ <Reference Include="StructureMap, Version=2.5.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\StructureMap.dll</HintPath>
+ </Reference>
+ <Reference Include="Symbiote.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Symbiote.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Symbiote.Daemon">
+ <HintPath>..\..\lib\Symbiote.Daemon.dll</HintPath>
+ </Reference>
+ <Reference Include="Symbiote.Log4Net">
+ <HintPath>..\..\lib\Symbiote.Log4Net.dll</HintPath>
+ </Reference>
+ <Reference Include="Symbiote.Lucene">
+ <HintPath>..\..\lib\Symbiote.Lucene.dll</HintPath>
+ </Reference>
+ <Reference Include="Symbiote.Restfully, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Symbiote.Restfully.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Topshelf">
+ <HintPath>..\..\lib\Topshelf.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Class1.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Relax.Lucene\Relax.Lucene.csproj">
+ <Project>{EAC2B6B2-8F3C-49A8-88B0-DA6CC04C4935}</Project>
+ <Name>Relax.Lucene</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Relax\Relax.csproj">
+ <Project>{3A8D40A3-96F9-4878-902E-7CBC3A82AEDD}</Project>
+ <Name>Relax</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.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
36 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")]
View
2 src/Relax.Lucene/Relax.Lucene.csproj
@@ -17,7 +17,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
+ <OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
View
12 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
View
41 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<TestDoc> viewResult;
+ protected static string json;
+
+ private Because of = () =>
+ {
+ result = command.GetDocuments<TestDoc>();
+ viewResult = result.GetResultAs<ViewResult<TestDoc>>();
+ 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();
+ }
+}
View
40 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<TestDoc> viewResult;
+ protected static string json;
+
+ private Because of = () =>
+ {
+ result = command.GetDocuments<TestDoc>(new object[] {"1","2"});
+ viewResult = result.GetResultAs<ViewResult<TestDoc>>();
+ 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();
+ }
+}
View
40 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<TestDoc> viewResult;
+ protected static string json;
+
+ private Because of = () =>
+ {
+ result = command.GetDocumentsPaged<TestDoc>(2, 3);
+ viewResult = result.GetResultAs<ViewResult<TestDoc>>();
+ 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();
+ }
+}
View
34 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<TestDoc>("1");
+ model = result.GetResultAs<TestDoc>();
+ 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();
+ }
+}
View
29 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<TestDoc>("1", "1");
+ model = result.GetResultAs<TestDoc>();
+ 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();
+ }
+}
View
21 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<TestDoc> viewResult;
+ protected static string json;
+
+ private Because of = () =>
+ {
+ result = command.GetDocumentsInRange<TestDoc>("doc 1", "doc 2");
+ viewResult = result.GetResultAs<ViewResult<TestDoc>>();
+ };
+
+ private It should_have_one_document = () => viewResult.TotalRows.ShouldEqual(1);
+ }
+}
View
42 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<CouchUri>(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<CouchUri>(i => i.ToString() == url)))
+ .Returns(response)
+ .AtMostOnce();
+ command = factory.CreateGetDocumentsPagedCommand();
+ };
+ }
+}
View
28 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<CouchUri>(i => i.ToString() == url), keyList.ToJson(false)))
+ .Returns(response)
+ .AtMostOnce();
+ command = factory.CreateGetDocumentsByIdsCommand();
+ };
+ }
+}
View
12 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";
+ };
+ }
+}
View
12 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";
+ };
+ }
+}
View
24 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<CouchUri>(i => i.ToString() == url)))
+ .Returns(response)
+ .AtMostOnce();
+ command = factory.CreateGetDocumentCommand();
+ };
+ }
+}
View
39 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<CouchUri>(i => i.ToString() == url)))
+ .Returns(response)
+ .AtMostOnce();
+ command = factory.CreateGetDocumentsInRangeCommand();
+ };
+ }
+}
View
30 tests/Relax.Tests.csproj
@@ -100,14 +100,14 @@
<Compile Include="Commands\DeletingAttachments\with_delete_attachment_command.cs" />
<Compile Include="Commands\FromView\when_getting_from_view.cs" />
<Compile Include="Commands\FromView\with_get_from_view_command.cs" />
- <Compile Include="Commands\GetCommand\when_getting_all_documents.cs" />
- <Compile Include="Commands\GetCommand\when_getting_all_documents_by_ids.cs" />
- <Compile Include="Commands\GetCommand\when_getting_all_documents_paged.cs" />
- <Compile Include="Commands\GetCommand\when_getting_documents_by_key_range.cs" />
- <Compile Include="Commands\GetCommand\with_get_all_docs.cs" />
- <Compile Include="Commands\GetCommand\with_get_all_docs_by_ids.cs" />
- <Compile Include="Commands\GetCommand\with_get_all_docs_paged.cs" />
- <Compile Include="Commands\GetCommand\with_get_doc_by_range.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_all_documents.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_all_documents_by_ids.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_all_documents_paged.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_documents_by_key_range.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_all_docs.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_all_docs_by_ids.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_all_docs_paged.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_doc_by_range.cs" />
<Compile Include="Commands\GettingAttachments\when_getting_attachment.cs" />
<Compile Include="Commands\GettingAttachments\with_get_attachment_command.cs" />
<Compile Include="Commands\ParentDoc.cs" />
@@ -125,12 +125,12 @@
<Compile Include="Commands\SaveCommand\with_serialized_bulk_persist.cs" />
<Compile Include="Commands\SaveCommand\with_single_parent_document.cs" />
<Compile Include="Commands\TestDoc.cs" />
- <Compile Include="Commands\GetCommand\when_getting_doc_by_id.cs" />
- <Compile Include="Commands\GetCommand\when_getting_doc_by_id_and_rev.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_doc_by_id.cs" />
+ <Compile Include="Commands\GettingDocuments\when_getting_doc_by_id_and_rev.cs" />
<Compile Include="Commands\with_command_factory.cs" />
<Compile Include="Commands\with_configuration.cs" />
- <Compile Include="Commands\GetCommand\with_get_doc_by_id_and_rev_setup.cs" />
- <Compile Include="Commands\GetCommand\with_get_doc_by_id_setup.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_doc_by_id_and_rev_setup.cs" />
+ <Compile Include="Commands\GettingDocuments\with_get_doc_by_id_setup.cs" />
<Compile Include="Commands\with_mock_http_action.cs" />
<Compile Include="Configuration\TestDatabaseResolver.cs" />
<Compile Include="Configuration\when_using_cache_without_a_cache_provider.cs" />
@@ -155,10 +155,16 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\when_deleting_attachment.cs" />
<Compile Include="Repository\when_deleting_document_by_id.cs" />
+ <Compile Include="Repository\when_getting_attachment.cs" />
+ <Compile Include="Repository\when_getting_documents_by_id.cs" />
+ <Compile Include="Repository\when_getting_documents_by_range.cs" />
<Compile Include="Repository\when_getting_from_view.cs" />
<Compile Include="Repository\with_delete_attachment_command.cs" />
<Compile Include="Repository\with_delete_document_command_by_id.cs" />
<Compile Include="Repository\with_from_view_command.cs" />
+ <Compile Include="Repository\with_get_attachment.cs" />
+ <Compile Include="Repository\with_get_documents_by_keys.cs" />
+ <Compile Include="Repository\with_get_documents_by_range.cs" />
<Compile Include="Serialization\ComplexDocument.cs" />
<Compile Include="Serialization\Filtering\ClassA.cs" />
<Compile Include="Serialization\Filtering\ClassB.cs" />
View
27 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<string, byte[]> attachmentResult;
+ protected static string contentResult;
+ protected static Exception exception;
+
+ private Because of = () =>
+ {
+ exception =
+ Catch.Exception(
+ () => attachmentResult = repository.GetAttachment<TestDoc>("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();
+ }
+}
View
30 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<TestDoc> records;
+ protected static Exception exception;
+
+ private Because of = () =>
+ {
+ exception =
+ Catch.Exception(
+ () => records = repository.GetAllByKeys<TestDoc>(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();
+ }
+}
View
30 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<TestDoc> records;
+ protected static Exception exception;
+
+ private Because of = () =>
+ {
+ exception =
+ Catch.Exception(
+ () => records = repository.GetAllBetweenKeys<TestDoc>("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();
+ }
+}
View
29 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<string, byte[]> 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);
+ };
+ }
+}
View
27 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);
+ };
+ }
+}
View
23 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);
+ };
+ }
+}

0 comments on commit a33ad0c

Please sign in to comment.