Permalink
Browse files

Adding improved unit test coverage and fixing bugs related to views a…

…nd document deletion by id
  • Loading branch information...
1 parent a167bb8 commit 4ca53f83956c5fa65b92818b40dcc403b10589e8 @arobson arobson committed Jun 18, 2010
@@ -215,7 +215,7 @@ public virtual object[] GetDocumentGraph(object model)
public virtual bool IsDocument(object instance)
{
- return instance.GetType().GetInterface("ICouchDocument`2") != null;
+ return instance.GetType().GetInterface("ICouchDocument`1") != null;
}
public virtual string GetDatabaseForType<TModel>()
@@ -8,7 +8,7 @@ public class ViewRow<TModel>
public string Id { get; set; }
[JsonProperty(PropertyName = "key")]
- public string Key { get; set; }
+ public object Key { get; set; }
[JsonIgnore()]
public TModel Model
@@ -30,7 +30,8 @@ public virtual void DeleteDocument<TModel>(object id)
var deleteCommand = commandFactory.GetDeleteCommand();
var getCommand = commandFactory.GetGetDocumentCommand();
- var doc = getCommand.GetDocument<TModel>(id);
+ var getResult = getCommand.GetDocument<TModel>(id);
+ var doc = getResult.GetResultAs<TModel>();
deleteCommand.DeleteDocument(doc);
}
@@ -7,7 +7,7 @@ namespace Relax.Impl.Serialization
{
public class ChildDocumentContractResolver : DefaultContractResolver
{
- private const string ICOUCHDOC_TYPE = "ICouchDocument`2";
+ private const string ICOUCHDOC_TYPE = "ICouchDocument`1";
private const string IENUMERABLE_TYPE = "IEnumerable`1";
private ICouchConfiguration configuration { get; set; }
@@ -15,10 +15,10 @@ public bool ResolverAppliesForSerialization(Type type)
public bool ResolverAppliesForDeserialization(Type type)
{
if (type.IsGenericType)
- if (type.GetGenericArguments()[0].GetInterface("ICouchDocument`2") == null)
+ if (type.GetGenericArguments()[0].GetInterface("ICouchDocument`1") == null)
return true;
- return type.GetInterface("ICouchDocument`2") == null;
+ return type.GetInterface("ICouchDocument`1") == null;
}
public IContractResolver Resolver
@@ -10,7 +10,7 @@ public class ConventionSerializationContractResolverStrategy : IContractResolver
{
public bool ResolverAppliesForSerialization(Type type)
{
- return type.GetInterface("ICouchDocument`2") == null;
+ return type.GetInterface("ICouchDocument`1") == null;
}
public bool ResolverAppliesForDeserialization(Type type)
@@ -0,0 +1,34 @@
+using System.Linq;
+using Machine.Specifications;
+using Newtonsoft.Json.Linq;
+using Relax.Config;
+using Relax.Impl;
+using StructureMap;
+using Symbiote.Core.Extensions;
+
+namespace Relax.Tests.Commands.SaveCommand
+{
+ class when_persisting_list_with_breaking_documents : with_nested_document_list
+ {
+ protected static object[] result;
+ protected static string serialized;
+
+ private Because of = () =>
+ {
+ var configuration = ObjectFactory.GetInstance<ICouchConfiguration>();
+ configuration.BreakDownDocumentGraphs = true;
+
+ result = testDocs.GetDocmentsFromGraph();
+ serialized = result[0].ToJson();
+ };
+
+ private It should_produce_eight_documents_total = () =>
+ result.Length.ShouldEqual(8);
+
+ private It should_not_include_children_property_in_json = () =>
+ {
+ var json = JObject.Parse(serialized);
+ ShouldExtensionMethods.ShouldNotContain(json.Properties().Select(x => x.Name), "Children");
+ };
+ }
+}
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Machine.Specifications;
+using Newtonsoft.Json.Linq;
+using Relax.Config;
+using Relax.Impl;
+using StructureMap;
+using Symbiote.Core.Extensions;
+
+namespace Relax.Tests.Commands.SaveCommand
+{
+ class when_persisting_list_without_breaking_documents : with_nested_document_list
+ {
+ protected static object[] result;
+ protected static string serialized;
+
+ private Because of = () =>
+ {
+ var configuration = ObjectFactory.GetInstance<ICouchConfiguration>();
+ configuration.BreakDownDocumentGraphs = false;
+
+ result = testDocs.GetDocmentsFromGraph();
+
+ serialized = result[0].ToJson();
+ };
+
+ private It should_produce_six_documents_total = () =>
+ result.Length.ShouldEqual(2);
+
+ private It should_have_children_collection_included_in_json = () =>
+ {
+ var json = JObject.Parse(serialized);
+ json["Children"]["$values"].Children().Count().
+ ShouldEqual(3);
+ };
+
+ }
+}
@@ -28,7 +28,7 @@ public class when_scrubbing_bulk_persist_type_tokens : with_serialized_bulk_pers
private It should_not_produce_null = () => deserialized.ShouldNotBeNull();
private It should_correctly_deserialize_documents = () => deserializedDocument.ShouldNotBeNull();
- private It should_not_contain_type_tokens_at_top_level = () => scrubbedJsonObject["docs"].ShouldNotBeNull();
- //private It should_take_less_than_25ms = () => timer.ElapsedMilliseconds.ShouldBeLessThan(25);
+ private It should_have_simple_docs_array = () => scrubbedJsonObject["docs"].ShouldNotContain(new [] {new JProperty("$values")});
+ private It should_take_less_than_25ms = () => timer.ElapsedMilliseconds.ShouldBeLessThan(25);
}
}
@@ -78,6 +78,8 @@
<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\SaveCommand\when_persisting_list_without_breaking_documents.cs" />
+ <Compile Include="Commands\SaveCommand\when_persisting_list_with_breaking_documents.cs" />
<Compile Include="Commands\SaveCommand\when_scrubbing_bulk_persist_type_tokens.cs" />
<Compile Include="Commands\SaveCommand\with_document_list.cs" />
<Compile Include="Commands\SaveCommand\with_nested_document_list.cs" />
@@ -118,12 +120,16 @@
<Compile Include="Serialization\Filtering\when_serializing_complex_graph.cs" />
<Compile Include="Serialization\Filtering\with_test_graph.cs" />
<Compile Include="Serialization\Test.cs" />
+ <Compile Include="Serialization\when_deserializing_view_result_and_document_excluded.cs" />
+ <Compile Include="Serialization\when_deserializing_view_result_with_documents_included.cs" />
<Compile Include="Serialization\with_bulk_insert.cs" />
<Compile Include="Serialization\when_serializing_bulk_insert.cs" />
<Compile Include="Serialization\with_assimilation.cs" />
<Compile Include="Serialization\when_trying_custom_serializer.cs" />
<Compile Include="Serialization\with_complex_document.cs" />
<Compile Include="Serialization\with_single_document.cs" />
+ <Compile Include="Serialization\with_view_result_and_documents_included.cs" />
+ <Compile Include="Serialization\with_view_result_and_no_documents.cs" />
<Compile Include="Server\when_cleaning_up_views.cs" />
<Compile Include="Server\when_compacting_db.cs" />
<Compile Include="Server\when_compacting_view.cs" />
@@ -0,0 +1,19 @@
+using Machine.Specifications;
+using Relax.Impl.Json;
+using Symbiote.Core.Extensions;
+
+namespace Relax.Tests.Serialization
+{
+ public class when_deserializing_view_result_and_document_excluded : with_view_result_and_no_documents
+ {
+ protected static ViewResult<TestDocument> result;
+
+ private Because of = () =>
+ {
+ result = viewResultJson.FromJson<ViewResult<TestDocument>>();
+ };
+
+ private It should_have_document_message = () =>
+ result.Rows[0].Model.Message.ShouldEqual("Hi");
+ }
+}
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Machine.Specifications;
+using Relax.Impl.Json;
+using Symbiote.Core.Extensions;
+
+namespace Relax.Tests.Serialization
+{
+ public class when_deserializing_view_result_with_documents_included : with_view_result_and_documents_included
+ {
+ protected static ViewResult<TestDocument> result;
+
+ private Because of = () =>
+ {
+ result = viewResultJson.FromJson<ViewResult<TestDocument>>();
+ };
+
+ private It should_have_document_message = () =>
+ result.Rows[0].Model.Message.ShouldEqual("Howdy");
+ }
+}
@@ -0,0 +1,34 @@
+using Machine.Specifications;
+
+namespace Relax.Tests.Serialization
+{
+ public abstract class with_view_result_and_documents_included
+ {
+ protected static string viewResultJson;
+
+ private Establish context = () =>
+ {
+ viewResultJson = @"
+{
+ rows:
+ [
+ {
+ id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"",
+ key: [""Test"",1],
+ value: {
+ _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"",
+ _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"",
+ Message: ""Hi""
+ },
+ doc: {
+ _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"",
+ _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"",
+ Message: ""Howdy""
+ }
+ }
+ ]
+}
+";
+ };
+ }
+}
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Machine.Specifications;
+
+namespace Relax.Tests.Serialization
+{
+ public abstract class with_view_result_and_no_documents
+ {
+ protected static string viewResultJson;
+
+ private Establish context = () =>
+ {
+ viewResultJson = @"
+{
+ rows:
+ [
+ {
+ id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"",
+ key: {thingy:""Test"",thingy2:1},
+ value: {
+ _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"",
+ _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"",
+ Message: ""Hi""
+ }
+ }
+ ]
+}
+";
+ };
+ }
+}

0 comments on commit 4ca53f8

Please sign in to comment.