Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Fixed problem with Assert.AreEqual treating documents as collections,…
Browse files Browse the repository at this point in the history
… bypassing calls to .Equals (Arne Claassen)
  • Loading branch information
samus committed Oct 14, 2009
1 parent da50440 commit 128b075
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions MongoDB.Net-Tests/TestDocument.cs
@@ -1,8 +1,3 @@
/*
* User: scorder
* Date: 7/8/2009
*/

using System;
using System.Collections;

Expand Down Expand Up @@ -106,42 +101,42 @@ public void TestValuesAdded()
public void TestTwoDocumentsWithSameContentInSameOrderAreEqual() {
Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
Document d2 = new Document().Append("k1", "v1").Append("k2", "v2");
Assert.AreEqual(d1, d2);
AreEqual(d1, d2);
}

[Test]
public void TestTwoDocumentsWithSameContentInDifferentOrderAreNotEqual() {
Document d1 = new Document().Append("k1", "v1").Append("k2", "v2");
Document d2 = new Document().Append("k2", "v2").Append("k1", "v1");
Assert.AreNotEqual(d1, d2);
AreNotEqual(d1, d2);
}

[Test]
public void TestTwoDocumentsWithSameArrayContentAreEqual() {
Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
Document d2 = new Document().Append("k1", new string[] { "v1", "v2" });
Assert.AreEqual(d1, d2);
AreEqual(d1, d2);
}

[Test]
public void TestTwoDocumentsWithMisorderedArrayContentAreNotEqual() {
Document d1 = new Document().Append("k1", new string[] { "v1", "v2" });
Document d2 = new Document().Append("k1", new string[] { "v2", "v1" });
Assert.AreNotEqual(d1, d2);
AreNotEqual(d1, d2);
}

[Test]
public void TestTwoDocumentsWithSameDocumentChildTreeAreEqual() {
Document d1 = new Document().Append("k1", new Document().Append("k2",new Document().Append("k3","foo")));
Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
Assert.AreEqual(d1, d2);
AreEqual(d1, d2);
}

[Test]
public void TestTwoDocumentsWithDifferentDocumentChildTreeAreNotEqual() {
Document d1 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "foo")));
Document d2 = new Document().Append("k1", new Document().Append("k2", new Document().Append("k3", "bar")));
Assert.AreNotEqual(d1, d2);
AreNotEqual(d1, d2);
}

[Test]
Expand Down Expand Up @@ -217,5 +212,17 @@ public void TestValuesAdded()
});
Assert.AreEqual(@"{ ""foo"": [ { ""a"": 1 }, { ""b"": 2 }, { ""c"": 3 } ] }", doc.ToString());
}

private void AreEqual(Document d1, Document d2) {
if (!d1.Equals(d2)) {
Assert.Fail(string.Format("Documents don't match\r\nExpected: {0}\r\nActual: {1}", d1, d2));
}
}

private void AreNotEqual(Document d1, Document d2) {
if (d1.Equals(d2)) {
Assert.Fail(string.Format("Documents match\r\nExpected: not {0}\r\nActual: {1}", d1, d2));
}
}
}
}

0 comments on commit 128b075

Please sign in to comment.