Skip to content

Commit ca87362

Browse files
Backport #4761 to v9.X (#4771)
1 parent d7a5e0a commit ca87362

File tree

7 files changed

+128
-1
lines changed

7 files changed

+128
-1
lines changed

Source/Csla.test/Basic/Children.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//-----------------------------------------------------------------------
88

99
using System.Data;
10+
using Csla.Core;
1011

1112
namespace Csla.Test.Basic
1213
{
@@ -37,6 +38,8 @@ public int DeletedCount
3738
{
3839
get { return DeletedList.Count; }
3940
}
41+
42+
public MobileList<Child> DeletedItems => DeletedList;
4043

4144
[Create]
4245
private void Create()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="BusinessBindingListBaseTests.cs" company="Marimer LLC">
3+
// Copyright (c) Marimer LLC. All rights reserved.
4+
// Website: https://cslanet.com
5+
// </copyright>
6+
// <summary>no summary</summary>
7+
//-----------------------------------------------------------------------
8+
9+
using Csla.Serialization;
10+
using Csla.TestHelpers;
11+
using FluentAssertions;
12+
using FluentAssertions.Execution;
13+
using Microsoft.Extensions.DependencyInjection;
14+
using Microsoft.VisualStudio.TestTools.UnitTesting;
15+
16+
namespace Csla.Test.BusinessListBase
17+
{
18+
[TestClass]
19+
public class BusinessBindingListBaseTests
20+
{
21+
private static TestDIContext _testDIContext;
22+
23+
[ClassInitialize]
24+
public static void ClassInitialize(TestContext context)
25+
{
26+
_testDIContext = TestDIContextFactory.CreateDefaultContext();
27+
}
28+
29+
[TestMethod]
30+
public async Task Parent_LocationTransferWithDeletedItemsMustSetParentOnDeletedItems()
31+
{
32+
var root = CreateRoot();
33+
34+
for (int i = 0; i < 5; i++)
35+
{
36+
root.Children.AddNew();
37+
}
38+
39+
root = await root.SaveAsync();
40+
root.Children.Clear();
41+
42+
var transferredGraph = SimulateLocationTransfer(root);
43+
44+
using (new AssertionScope())
45+
{
46+
transferredGraph.Children.Parent.Should().BeSameAs(transferredGraph);
47+
transferredGraph.Children.DeletedItems.Should().AllSatisfy(c => c.Parent.Should().BeSameAs(transferredGraph.Children));
48+
}
49+
50+
51+
static Basic.Root SimulateLocationTransfer(Basic.Root original)
52+
{
53+
var serializer = _testDIContext.ServiceProvider.GetRequiredService<ISerializationFormatter>();
54+
return (Basic.Root)serializer.Deserialize(serializer.Serialize(original));
55+
}
56+
}
57+
58+
private static Basic.Root CreateRoot()
59+
{
60+
var dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
61+
62+
return dataPortal.Create(new Basic.Root.Criteria("Random"));
63+
}
64+
}
65+
}

Source/Csla.test/BusinessListBase/BusinessListBaseTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
// <summary>no summary</summary>
77
//-----------------------------------------------------------------------
88

9+
using Csla.Serialization;
910
using Csla.TestHelpers;
1011
using FluentAssertions;
1112
using FluentAssertions.Execution;
13+
using Microsoft.Extensions.DependencyInjection;
1214
using Microsoft.VisualStudio.TestTools.UnitTesting;
1315

1416
namespace Csla.Test.BusinessListBase
@@ -234,6 +236,35 @@ public async Task WaitForIdle_WhenMultipleChildsAreBusyItShouldOnlyBeIdlingWhenA
234236
obj.IsBusy.Should().BeFalse();
235237
}
236238
}
239+
240+
[TestMethod]
241+
public async Task Parent_LocationTransferWithDeletedItemsMustSetParentOnDeletedItems()
242+
{
243+
var root = CreateRoot();
244+
245+
for (int i = 0; i < 5; i++)
246+
{
247+
root.Children.AddNew();
248+
}
249+
250+
root = await root.SaveAsync();
251+
root.Children.Clear();
252+
253+
var transferredGraph = SimulateLocationTransfer(root);
254+
255+
using (new AssertionScope())
256+
{
257+
transferredGraph.Children.Parent.Should().BeSameAs(transferredGraph);
258+
transferredGraph.Children.DeletedItems.Should().AllSatisfy(c => c.Parent.Should().BeSameAs(transferredGraph.Children));
259+
}
260+
261+
262+
static Root SimulateLocationTransfer(Root original)
263+
{
264+
var serializer = _testDIContext.ServiceProvider.GetRequiredService<ISerializationFormatter>();
265+
return (Root)serializer.Deserialize(serializer.Serialize(original));
266+
}
267+
}
237268

238269
private Root CreateRoot()
239270
{

Source/Csla.test/BusinessListBase/ChildList.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
// <summary>no summary</summary>
77
//-----------------------------------------------------------------------
88

9+
using Csla.Core;
10+
911
namespace Csla.Test.BusinessListBase
1012
{
1113
[Serializable]
12-
public class ChildList : BusinessListBase<ChildList, Child>;
14+
public class ChildList : BusinessListBase<ChildList, Child>
15+
{
16+
public MobileList<Child> DeletedItems => DeletedList;
17+
}
1318
}

Source/Csla/BusinessBindingListBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,18 @@ protected override void OnSetChildren(Serialization.Mobile.SerializationInfo inf
669669
}
670670
base.OnSetChildren(info, formatter);
671671
}
672+
673+
/// <inheritdoc/>
674+
protected override void OnDeserialized()
675+
{
676+
base.OnDeserialized();
672677

678+
foreach (var item in DeletedList)
679+
{
680+
item.SetParent(this);
681+
}
682+
}
683+
673684
#endregion
674685

675686
#region IsChild

Source/Csla/BusinessListBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,17 @@ protected override void OnSetChildren(SerializationInfo info, MobileFormatter fo
704704
base.OnSetChildren(info, formatter);
705705
}
706706

707+
/// <inheritdoc/>
708+
protected override void OnDeserialized()
709+
{
710+
base.OnDeserialized();
711+
712+
foreach (var item in DeletedList)
713+
{
714+
item.SetParent(this);
715+
}
716+
}
717+
707718
#endregion
708719

709720
#region IsChild

Source/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<LangVersion>latest</LangVersion>
44
<ImplicitUsings>enable</ImplicitUsings>
5+
<EnableWindowsTargeting>true</EnableWindowsTargeting>
56
</PropertyGroup>
67

78
<!-- Common Package Settings -->

0 commit comments

Comments
 (0)