Improve Testcases for ODB
parent
54ef7ba55d
commit
a768f22802
100
test/ODBTests.cs
100
test/ODBTests.cs
|
@ -8,6 +8,7 @@ using ln.types.odb.ng.storage.session;
|
|||
using ln.types.odb.values;
|
||||
using NUnit.Framework;
|
||||
using ln.types.odb.ng.mappings;
|
||||
using ln.types.odb.ng.diff;
|
||||
namespace ln.types.test
|
||||
{
|
||||
[TestFixture()]
|
||||
|
@ -221,8 +222,105 @@ namespace ln.types.test
|
|||
}
|
||||
}
|
||||
|
||||
[TestCase()]
|
||||
public void TestDiff()
|
||||
{
|
||||
Document docA = new Document();
|
||||
Document docB, docC, docD;
|
||||
Document[] spareDocuments = new Document[16];
|
||||
|
||||
public class Person
|
||||
for (int n = 0; n < spareDocuments.Length; n++)
|
||||
{
|
||||
spareDocuments[n] = new Document();
|
||||
spareDocuments[n]["spareIdx"] = new ODBInteger(n);
|
||||
spareDocuments[n]["value"] = new ODBInteger(n);
|
||||
spareDocuments[n]["valueB"] = new ODBStringValue("valueB");
|
||||
spareDocuments[n]["valueC"] = new ODBStringValue("valueC");
|
||||
}
|
||||
|
||||
ODBList subDocuments = new ODBList();
|
||||
docA["documents"] = subDocuments;
|
||||
|
||||
for (int n = 0; n < 8; n++)
|
||||
subDocuments.Add(spareDocuments[n].Clone());
|
||||
|
||||
docB = docA.Clone() as Document;
|
||||
docD = docA.Clone() as Document;
|
||||
|
||||
for (int n = 8; n < 12; n++)
|
||||
{
|
||||
(docA["documents"] as ODBList).Add(spareDocuments[n].Clone());
|
||||
}
|
||||
|
||||
for (int n = 12; n < 16; n++)
|
||||
{
|
||||
(docB["documents"] as ODBList).Add(spareDocuments[n].Clone());
|
||||
(docD["documents"] as ODBList).Add(spareDocuments[n].Clone());
|
||||
}
|
||||
|
||||
docC = docA.Clone() as Document;
|
||||
|
||||
for (int n = 0; n < 4; n++)
|
||||
{
|
||||
((docC["documents"] as ODBList)[6] as Document)["value"] = new ODBInteger(100 + n);
|
||||
(docC["documents"] as ODBList).RemoveAt(2);
|
||||
|
||||
(docD["documents"] as ODBList).RemoveAt(2);
|
||||
}
|
||||
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
((docD["documents"] as ODBList)[2+n] as Document)["value"] = new ODBInteger(100 + n);
|
||||
}
|
||||
|
||||
Console.WriteLine("docA:\n{0}", docA.TreeString);
|
||||
Console.WriteLine("docB:\n{0}", docB.TreeString);
|
||||
Console.WriteLine("docC:\n{0}", docC.TreeString);
|
||||
|
||||
Diff diffAB = Diff.Construct(docA, docB);
|
||||
Diff diffAC = Diff.Construct(docA, docC);
|
||||
|
||||
Console.WriteLine("diffAB: {0}", diffAB.TreeString);
|
||||
Console.WriteLine("diffAC: {0}", diffAC.TreeString);
|
||||
|
||||
Document docB2 = docA.Clone() as Document;
|
||||
Document docC2 = docA.Clone() as Document;
|
||||
|
||||
diffAB.Apply(docB2);
|
||||
diffAC.Apply(docC2);
|
||||
|
||||
Console.WriteLine("docB2:\n{0}", docB2.TreeString);
|
||||
Console.WriteLine("docC2:\n{0}", docB2.TreeString);
|
||||
|
||||
Assert.AreEqual(docB, docB2);
|
||||
Assert.IsTrue(docB.CompareTo(docB2) == 0);
|
||||
|
||||
Assert.AreEqual(docC, docC2);
|
||||
Assert.IsTrue(docC.CompareTo(docC2) == 0);
|
||||
|
||||
Document docD2 = docA.Clone() as Document;
|
||||
diffAB.Apply(docD2);
|
||||
diffAC.Apply(docD2);
|
||||
|
||||
Console.WriteLine("docD:\n{0}", docD.TreeString);
|
||||
Console.WriteLine("docD2:\n{0}", docD2.TreeString);
|
||||
|
||||
Assert.AreEqual(docD, docD2);
|
||||
Assert.IsTrue(docD.CompareTo(docD2) == 0);
|
||||
|
||||
Document docD3 = docA.Clone() as Document;
|
||||
diffAB.Apply(docD3);
|
||||
diffAC.Apply(docD3);
|
||||
|
||||
Console.WriteLine("docD3:\n{0}", docD3.TreeString);
|
||||
|
||||
Assert.AreEqual(docD, docD3);
|
||||
Assert.IsTrue(docD.CompareTo(docD3) == 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class Person
|
||||
{
|
||||
public readonly Guid ID;
|
||||
|
||||
|
|
Loading…
Reference in New Issue