Skip to content

Commit

Permalink
Merge pull request #3483 from MarimerLLC/v7.x
Browse files Browse the repository at this point in the history
#3481 Fix GraphMerge issue with losing child objects
  • Loading branch information
rockfordlhotka authored Oct 5, 2023
2 parents ffa5f22 + 2c5ce97 commit 0698eaf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
54 changes: 30 additions & 24 deletions Source/Csla.test/GraphMerge/GraphMergerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,31 +342,37 @@ public void MergeChildList()
ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
IDataPortal<Foo> dataPortal = _testDIContext.CreateDataPortal<Foo>();

var obj = dataPortal.Create();
obj.ChildList.AddNew();
obj.ChildList[0].Name = "1";
obj.ChildList.AddNew();
obj.ChildList[1].Name = "12";
obj.MockUpdated();
var cloned = obj.Clone();
cloned.ChildList[0].Name = "2";
cloned.ChildList.RemoveAt(1);
cloned.ChildList.AddNew();
cloned.ChildList[1].Name = "42";
cloned.MockUpdated();

// create target childlist
var target = dataPortal.Create();
target.ChildList.AddNew();
target.ChildList[0].Name = "1";
target.ChildList.AddNew();
target.ChildList[1].Name = "12";
target.MockUpdated();

// create source childlist
var source = target.Clone();
source.ChildList[0].Name = "2";
source.ChildList.RemoveAt(1);
source.ChildList.AddNew();
source.ChildList[1].Name = "42";
source.MockUpdated();

// act
var merger = new GraphMerger(applicationContext);
merger.MergeGraph(obj, cloned);
Assert.IsFalse(ReferenceEquals(obj.ChildList, cloned.ChildList), "ref");
Assert.AreEqual(2, obj.ChildList.Count, "count");
Assert.IsFalse(obj.ChildList[0].IsValid, "[0] isvalid");
Assert.IsTrue(obj.ChildList[1].IsValid, "[1] isvalid");
Assert.IsFalse(obj.ChildList.IsValid, "isvalid");
Assert.AreEqual("2", obj.ChildList[0].Name, "[0] name");
Assert.AreEqual("42", obj.ChildList[1].Name, "[1] name");
Assert.IsFalse(ReferenceEquals(obj.ChildList[0], cloned.ChildList[0]), "[0] ref");
Assert.IsTrue(ReferenceEquals(obj.ChildList[1], cloned.ChildList[1]), "[1] ref");
Assert.IsTrue(ReferenceEquals(obj.ChildList, obj.ChildList[1].Parent), "parent ref");
merger.MergeGraph(target, source);

// assert
Assert.IsFalse(ReferenceEquals(target.ChildList, source.ChildList), "ref");
Assert.AreEqual(2, target.ChildList.Count, "count");
Assert.IsFalse(target.ChildList[0].IsValid, "[0] isvalid");
Assert.IsTrue(target.ChildList[1].IsValid, "[1] isvalid");
Assert.IsFalse(target.ChildList.IsValid, "isvalid");
Assert.AreEqual("2", target.ChildList[0].Name, "[0] name");
Assert.AreEqual("42", target.ChildList[1].Name, "[1] name");
Assert.IsFalse(ReferenceEquals(target.ChildList[0], source.ChildList[0]), "[0] ref");
Assert.IsTrue(ReferenceEquals(target.ChildList[1], source.ChildList[1]), "[1] ref");
Assert.IsTrue(ReferenceEquals(target.ChildList, target.ChildList[1].Parent), "parent ref");
}

}
Expand Down
6 changes: 0 additions & 6 deletions Source/Csla.test/GraphMerge/IdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void IdentityBaseClone()
}

[TestMethod]

public void IdentityInitializedBusinessListBase()
{
IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
Expand All @@ -97,7 +96,6 @@ public void IdentityNewListChild()
}

[TestMethod]

public void IdentityListClone()
{
IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
Expand All @@ -110,7 +108,6 @@ public void IdentityListClone()
}

[TestMethod]

public void IdentityPostCloneIdentityManager()
{
IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
Expand All @@ -127,7 +124,6 @@ public void IdentityPostCloneIdentityManager()
}

[TestMethod]

public void IdentityInitializedBusinessBindingListBase()
{
IDataPortal<FooBindingList> dataPortal = _testDIContext.CreateDataPortal<FooBindingList>();
Expand All @@ -137,7 +133,6 @@ public void IdentityInitializedBusinessBindingListBase()
}

[TestMethod]

public void IdentityInitializedDynamicListBase()
{
IDataPortal<FooDynamicList> dataPortal = _testDIContext.CreateDataPortal<FooDynamicList>();
Expand All @@ -147,7 +142,6 @@ public void IdentityInitializedDynamicListBase()
}

[TestMethod]

public void IdentityInitializedDynamicBindingListBase()
{
IDataPortal<FooDynamicBindingList> dataPortal = _testDIContext.CreateDataPortal<FooDynamicBindingList>();
Expand Down
13 changes: 9 additions & 4 deletions Source/Csla/Core/IdentityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ public class IdentityManager
/// <returns>The next available identity value.</returns>
public int GetNextIdentity(int current)
{
if (current >= _nextIdentity)
int result;
if (current == -1)
{
_nextIdentity = current + 1;
return current;
result = _nextIdentity++;
}
else
{
return _nextIdentity++;
result = current;
if (current >= _nextIdentity)
{
_nextIdentity = current + 1;
}
}
return result;
}
}
}

0 comments on commit 0698eaf

Please sign in to comment.