Browse files

Fixing comparisons of guids in json

  • Loading branch information...
1 parent 088cccc commit 1cd69e53aeb09d7d8abfc7800b317de699ed3a0b @ayende ayende committed Nov 20, 2011
View
44 Raven.Abstractions/Json/Linq/RavenJValue.cs
@@ -361,7 +361,38 @@ public bool Equals(RavenJValue other)
private static bool ValuesEquals(RavenJValue v1, RavenJValue v2)
{
- return (v1 == v2 || (v1._valueType == v2._valueType && Compare(v1._valueType, v1._value, v2._value) == 0));
+ if(v1 == v2 )
+ return true;
+
+ switch (v1._valueType)
+ {
+ case JTokenType.Guid:
+ switch (v2._valueType)
+ {
+ case JTokenType.String:
+ case JTokenType.Guid:
+ break;
+ default:
+ return false;
+ }
+ break;
+ case JTokenType.String:
+ switch (v2._valueType)
+ {
+ case JTokenType.String:
+ case JTokenType.Guid:
+ break;
+ default:
+ return false;
+ }
+ break;
+ default:
+ if (v1._valueType != v2._valueType)
+ return false;
+ break;
+ }
+
+ return Compare(v1._valueType, v1._value, v2._value) == 0;
}
public int CompareTo(RavenJValue other)
@@ -433,7 +464,16 @@ private static int Compare(JTokenType valueType, object objA, object objB)
return MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2);
case JTokenType.Guid:
if (!(objB is Guid))
- throw new ArgumentException("Object must be of type Guid.");
+ {
+#if !NET_3_5
+ Guid guid;
+ if(Guid.TryParse((string) objB, out guid) == false)
+ throw new ArgumentException("Object must be of type Guid.");
+ objB = guid;
+#else
+ objB = new Guid((string)objB);
+#endif
+ }
Guid guid1 = (Guid)objA;
Guid guid2 = (Guid)objB;
View
57 Raven.Tests/MailingList/RavenDbPutTest.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Raven.Client;
+using Raven.Client.Document;
+using Raven.Client.Indexes;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class RavenDbPutTest : RavenTest
+ {
+ public class Book
+ {
+ public string Id { get; set; }
+ public Guid OldId { get; set; }
+ public string Name { get; set; }
+
+ }
+
+ [Fact]
+ public void strangely_puts_after_just_a_query()
+ {
+ using(GetNewServer())
+ using (var documentStore = new DocumentStore { Url = "http://localhost:8080/" })
+ {
+ documentStore.Conventions.DefaultQueryingConsistency = Raven.Client.Document.ConsistencyOptions.QueryYourWrites;
+
+ documentStore.Initialize();
+
+ using (var session = documentStore.OpenSession())
+ {
+ session.Store(new Book { Name = "Hello", });
+ session.Store(new Book { Name = "Baby", });
+ session.Store(new Book { Name = "Deer", });
+
+ session.SaveChanges();
+ }
+
+ // Now try querying the index and see the strange PUT requests.
+ using (var session = documentStore.OpenSession())
+ {
+
+ var query = session.Query<Book>()
+ .Customize(x=>x.WaitForNonStaleResults());
+
+
+ var results = query.ToList();
+
+ var old = session.Advanced.NumberOfRequests;
+ session.SaveChanges();
+ Assert.Equal(old, session.Advanced.NumberOfRequests);
+ }
+ }
+ }
+ }
+}
View
1 Raven.Tests/Raven.Tests.csproj
@@ -560,6 +560,7 @@
<Compile Include="MailingList\EnumAsInts.cs" />
<Compile Include="MailingList\GuidProjection.cs" />
<Compile Include="MailingList\LazyStats.cs" />
+ <Compile Include="MailingList\RavenDbPutTest.cs" />
<Compile Include="MailingList\NicolasGarfinkiel.cs" />
<Compile Include="MailingList\Rob.cs" />
<Compile Include="MailingList\RobStats\Entity.cs" />

0 comments on commit 1cd69e5

Please sign in to comment.