Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing test showing that properties can be named "Inner" and then be …

…queried upon
  • Loading branch information...
commit 285da73108b430ee7d077e36fac0ea1b2bfe51d3 1 parent d155204
@ayende ayende authored
View
2  Raven.Abstractions/Extensions/JsonExtensions.cs
@@ -23,7 +23,7 @@ public static class JsonExtensions
public static RavenJObject ToJObject(object result)
{
#if !NET_3_5
- var dynamicJsonObject = result as Linq.DynamicJsonObject;
+ var dynamicJsonObject = result as Linq.IDynamicJsonObject;
if (dynamicJsonObject != null)
return dynamicJsonObject.Inner;
#endif
View
2  Raven.Abstractions/Json/JsonToJsonConverter.cs
@@ -16,7 +16,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
else if(value is DynamicNullObject)
writer.WriteNull();
else
- ((DynamicJsonObject)value).Inner.WriteTo(writer);
+ ((IDynamicJsonObject)value).Inner.WriteTo(writer);
#else
throw new NotImplementedException();
#endif
View
33 Raven.Abstractions/Linq/DynamicJsonObject.cs
@@ -16,14 +16,23 @@
namespace Raven.Abstractions.Linq
{
+ public interface IDynamicJsonObject
+ {
+ /// <summary>
+ /// Gets the inner json object
+ /// </summary>
+ /// <value>The inner.</value>
+ RavenJObject Inner { get; }
+
+ }
/// <summary>
/// A dynamic implementation on top of <see cref="RavenJObject"/>
/// </summary>
- public class DynamicJsonObject : DynamicObject, IEnumerable<object>
+ public class DynamicJsonObject : DynamicObject, IEnumerable<object>, IDynamicJsonObject
{
public IEnumerator<object> GetEnumerator()
{
- foreach (var item in Inner)
+ foreach (var item in inner)
{
if (item.Key[0] == '$')
continue;
@@ -79,15 +88,6 @@ IEnumerator IEnumerable.GetEnumerator()
private readonly RavenJObject inner;
/// <summary>
- /// Gets the inner json object
- /// </summary>
- /// <value>The inner.</value>
- public RavenJObject Inner
- {
- get { return inner; }
- }
-
- /// <summary>
/// Initializes a new instance of the <see cref="DynamicJsonObject"/> class.
/// </summary>
/// <param name="inner">The obj.</param>
@@ -197,7 +197,7 @@ public object GetValue(string name)
}
if (name == "Inner")
{
- return Inner;
+ return inner;
}
return new DynamicNullObject();
}
@@ -456,6 +456,15 @@ public IEnumerable<object> SelectMany(Func<object, IEnumerable<object>> func)
return new DynamicList(inner.SelectMany(func).ToArray());
}
}
+
+ /// <summary>
+ /// Gets the inner json object
+ /// </summary>
+ /// <value>The inner.</value>
+ RavenJObject IDynamicJsonObject.Inner
+ {
+ get { return inner; }
+ }
}
}
#endif
View
4 Raven.Database/Indexing/AnonymousObjectToLuceneDocumentConverter.cs
@@ -193,9 +193,9 @@ private IEnumerable<AbstractField> CreateFields(string name, object value, Index
yield return CreateFieldWithCaching(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
- else if (value is DynamicJsonObject)
+ else if (value is IDynamicJsonObject)
{
- var inner = ((DynamicJsonObject)value).Inner;
+ var inner = ((IDynamicJsonObject)value).Inner;
yield return CreateFieldWithCaching(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
yield return CreateFieldWithCaching(name, inner.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
View
10 Raven.Database/Indexing/MapReduceIndex.cs
@@ -158,8 +158,8 @@ public Grouping(object key, IEnumerator enumerator)
private static RavenJObject GetMapedData(object doc)
{
- if (doc is DynamicJsonObject)
- return ((DynamicJsonObject)doc).Inner;
+ if (doc is IDynamicJsonObject)
+ return ((IDynamicJsonObject)doc).Inner;
return RavenJObject.FromObject(doc, JsonExtensions.CreateDefaultJsonSerializer());
}
@@ -195,7 +195,7 @@ private static string ReduceKeyToString(object reduceValue)
{
if (reduceValue is string || reduceValue is ValueType)
return reduceValue.ToString();
- var dynamicJsonObject = reduceValue as DynamicJsonObject;
+ var dynamicJsonObject = reduceValue as IDynamicJsonObject;
if (dynamicJsonObject != null)
return dynamicJsonObject.Inner.ToString(Formatting.None);
return RavenJToken.FromObject(reduceValue).ToString(Formatting.None);
@@ -345,9 +345,9 @@ private string ExtractReduceKey(AbstractViewGenerator viewGenerator, object doc)
private IEnumerable<AbstractField> GetFields(AnonymousObjectToLuceneDocumentConverter anonymousObjectToLuceneDocumentConverter, object doc, ref PropertyDescriptorCollection properties)
{
IEnumerable<AbstractField> fields;
- if (doc is DynamicJsonObject)
+ if (doc is IDynamicJsonObject)
{
- fields = anonymousObjectToLuceneDocumentConverter.Index(((DynamicJsonObject)doc).Inner,
+ fields = anonymousObjectToLuceneDocumentConverter.Index(((IDynamicJsonObject)doc).Inner,
indexDefinition, Field.Store.YES);
}
else
View
2  Raven.Database/Indexing/SimpleIndex.cs
@@ -135,7 +135,7 @@ private IndexingResult ExtractIndexDataFromDocument(AnonymousObjectToLuceneDocum
var newDocId = dynamicJsonObject.GetDocumentId();
return new IndexingResult
{
- Fields = anonymousObjectToLuceneDocumentConverter.Index(dynamicJsonObject.Inner, indexDefinition,
+ Fields = anonymousObjectToLuceneDocumentConverter.Index(((IDynamicJsonObject)dynamicJsonObject).Inner, indexDefinition,
Field.Store.NO).ToList(),
NewDocId = newDocId is DynamicNullObject ? null : (string)newDocId,
ShouldSkip = false
View
20 Raven.Tests/Bugs/Iulian/GeneratesCorrectTemporaryIndex.cs
@@ -4,15 +4,6 @@ namespace Raven.Tests.Bugs.Iulian
using System.Linq;
using Xunit;
- /// <summary>
- /// Test that verifies that the generated index is correct.
- /// The following index is generated:
- /// Name: Temp/Outers/ByFlag
- /// Map: from doc in docs.Outers select new { Flag = doc.Flag }
- ///
- /// The map part is wrong since the projection should be new { Flag = doc.Inner.Flag }
- ///
- /// </summary>
public class GeneratesCorrectTemporaryIndex : LocalClientTest
{
public class Inner
@@ -28,7 +19,7 @@ public class Outer
[Fact]
public void Can_Generate_Correct_Temporary_Index()
{
- using (var store = base.NewDocumentStore().Initialize())
+ using (var store = base.NewDocumentStore("munin", false))
{
using (var s = store.OpenSession())
{
@@ -40,13 +31,10 @@ public void Can_Generate_Correct_Temporary_Index()
using (var s = store.OpenSession())
{
- // verify that the element is saved as expected ( this passes )
- Outer test = s.Query<Outer>().SingleOrDefault();
- Assert.NotNull(test);
- Assert.True(test.Inner.Flag);
-
// query by the inner flag
- Outer outer = s.Query<Outer>().Where(o => o.Inner.Flag).SingleOrDefault();
+ Outer outer = s.Query<Outer>()
+ .Customize(x=>x.WaitForNonStaleResults())
+ .Where(o => o.Inner.Flag).SingleOrDefault();
Assert.NotNull(outer); // this fails
}
Please sign in to comment.
Something went wrong with that request. Please try again.