Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed Aug 13, 2015
1 parent 57f77b4 commit 00a82d8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
39 changes: 39 additions & 0 deletions SolrNet.Tests/GenericDictionaryDocumentVisitorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using MbUnit.Framework;
using SolrNet.Attributes;
using SolrNet.Impl;
using SolrNet.Impl.DocumentPropertyVisitors;
using SolrNet.Impl.FieldParsers;
using SolrNet.Mapping;
using SolrNet.Tests.Utils;

namespace SolrNet.Tests {
[TestFixture]
public class GenericDictionaryDocumentVisitorTests {

[Test]
public void ParseDictionaryOfCollection() {
var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.docWithDynamicFields.xml");
var mapper = new AttributesMappingManager();
var parser = new SolrDocumentResponseParser<Entity>(mapper, new DefaultDocumentVisitor(mapper, new DefaultFieldParser()), new SolrDocumentActivator<Entity>());
var entity = parser.ParseDocument(xml.Root);
Assert.IsNotNull(entity, "entity was null");
Assert.IsNotNull(entity.Attributes, "attributes was null");
Assert.AreEqual(16, entity.Attributes.Count);

var attr2 = entity.Attributes["2"];
Assert.AreEqual(5, attr2.Count);
Assert.Contains(attr2, 63);
Assert.Contains(attr2, 64);
Assert.Contains(attr2, 65);
Assert.Contains(attr2, 66);
Assert.Contains(attr2, 102);
}

class Entity {
[SolrField("attr_")]
public IDictionary<string, ICollection<int>> Attributes { get; set; }
}
}
}
56 changes: 56 additions & 0 deletions SolrNet.Tests/Resources/docWithDynamicFields.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://github.com/mausch/SolrNet/issues/211 -->
<doc>
<arr name="attr_6">
<int>31</int>
</arr>
<arr name="attr_2">
<int>63</int>
<int>64</int>
<int>65</int>
<int>66</int>
<int>102</int>
</arr>
<arr name="attr_1">
<int>69</int>
</arr>
<arr name="attr_9">
<int>224</int>
</arr>
<arr name="attr_5">
<int>226</int>
</arr>
<arr name="attr_8">
<int>236</int>
</arr>
<arr name="attr_11">
<int>243</int>
</arr>
<arr name="attr_20">
<int>557</int>
</arr>
<arr name="attr_4">
<int>1349</int>
</arr>
<arr name="attr_3">
<int>2144</int>
</arr>
<arr name="attr_23">
<int>2472</int>
</arr>
<arr name="attr_13">
<int>2556</int>
</arr>
<arr name="attr_18">
<int>2894</int>
</arr>
<arr name="attr_22">
<int>3881</int>
</arr>
<arr name="attr_21">
<int>3882</int>
</arr>
<arr name="attr_26">
<int>3998</int>
</arr>
</doc>
4 changes: 4 additions & 0 deletions SolrNet.Tests/SolrNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="DateTimeOffsetFieldParserTests.cs" />
<Compile Include="DebugResponseParserTests.cs" />
<Compile Include="DefaultResponseParserTests.cs" />
<Compile Include="GenericDictionaryDocumentVisitorTests.cs" />
<Compile Include="LocationTests.cs" />
<Compile Include="MergeCommandTests.cs" />
<Compile Include="Mocks\MSolrFieldSerializer.cs" />
Expand Down Expand Up @@ -339,6 +340,9 @@
<EmbeddedResource Include="Resources\responseWithStructuredDebugDetails.xml" />
<EmbeddedResource Include="Resources\responseWithSimpleDebugDetails.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\docWithDynamicFields.xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 00a82d8

Please sign in to comment.