From 4ff701f74cc61886e86081cc6b32b19019524088 Mon Sep 17 00:00:00 2001 From: Andrew Jocelyn Date: Thu, 30 May 2019 22:00:53 +0100 Subject: [PATCH 1/2] Add UpdateAll to ChildDataPortal and UpdateAllChildren to FieldDataManager --- .../Core/FieldManager/FieldDataManager.cs | 19 ++++++++++++ Source/Csla.Shared/Server/ChildDataPortal.cs | 29 ++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Source/Csla.Shared/Core/FieldManager/FieldDataManager.cs b/Source/Csla.Shared/Core/FieldManager/FieldDataManager.cs index 42a5e34c28..91c24a2d21 100644 --- a/Source/Csla.Shared/Core/FieldManager/FieldDataManager.cs +++ b/Source/Csla.Shared/Core/FieldManager/FieldDataManager.cs @@ -650,6 +650,25 @@ public void UpdateChildren(params object[] parameters) } } + /// + /// Invokes the data portal to update + /// all child objects, including those which are not dirty, + /// contained in the list of fields. + /// + public void UpdateAllChildren(params object[] parameters) + { + Server.ChildDataPortal portal = new Server.ChildDataPortal(); + foreach (var item in _fieldData) + { + if (item != null) + { + object obj = item.Value; + if (obj is IEditableBusinessObject || obj is IEditableCollection) + portal.UpdateAll(obj, parameters); + } + } + } + #endregion #if (ANDROID || IOS) || NETFX_CORE || NETSTANDARD2_0 diff --git a/Source/Csla.Shared/Server/ChildDataPortal.cs b/Source/Csla.Shared/Server/ChildDataPortal.cs index 613239f837..9bef8339dc 100644 --- a/Source/Csla.Shared/Server/ChildDataPortal.cs +++ b/Source/Csla.Shared/Server/ChildDataPortal.cs @@ -204,7 +204,7 @@ private object Fetch(Type objectType, bool hasParameters, params object[] parame /// Business object to update. public void Update(object obj) { - Update(obj, false, null); + Update(obj, false, false, null); } /// @@ -216,16 +216,37 @@ public void Update(object obj) /// public void Update(object obj, params object[] parameters) { - Update(obj, true, parameters); + Update(obj, true, false, parameters); } - private void Update(object obj, bool hasParameters, params object[] parameters) + /// + /// Update a business object. Include objects which are not dirty. + /// + /// Business object to update. + public void UpdateAll(object obj) + { + Update(obj, false, true, null); + } + + /// + /// Update a business object. Include objects which are not dirty. + /// + /// Business object to update. + /// + /// Parameters passed to method. + /// + public void UpdateAll(object obj, params object[] parameters) + { + Update(obj, true, true, parameters); + } + + private void Update(object obj, bool hasParameters, bool bypassIsDirtyTest, params object[] parameters) { if (obj == null) return; var busObj = obj as Core.BusinessBase; - if (busObj != null && busObj.IsDirty == false) + if (busObj != null && busObj.IsDirty == false && bypassIsDirtyTest == false) { // if the object isn't dirty, then just exit return; From 8bb020fefd0a50474050d57cfdc66cb5a98e6eb8 Mon Sep 17 00:00:00 2001 From: Andrew Jocelyn Date: Fri, 31 May 2019 09:57:02 +0100 Subject: [PATCH 2/2] FieldManager UpdateAllChildren tests --- Source/Csla.test/FieldManager/Child.cs | 81 +++++++++++++++++++ Source/Csla.test/FieldManager/ChildList.cs | 48 +++++++++++ .../FieldManager/ChildUpdateTests.cs | 54 +++++++++++++ Source/Csla.test/FieldManager/Root.cs | 60 ++++++++++++++ .../FieldManager/RootUpdateAllChildren.cs | 52 ++++++++++++ Source/Csla.test/csla.test.csproj | 5 ++ 6 files changed, 300 insertions(+) create mode 100644 Source/Csla.test/FieldManager/Child.cs create mode 100644 Source/Csla.test/FieldManager/ChildList.cs create mode 100644 Source/Csla.test/FieldManager/ChildUpdateTests.cs create mode 100644 Source/Csla.test/FieldManager/Root.cs create mode 100644 Source/Csla.test/FieldManager/RootUpdateAllChildren.cs diff --git a/Source/Csla.test/FieldManager/Child.cs b/Source/Csla.test/FieldManager/Child.cs new file mode 100644 index 0000000000..f0fcc5214b --- /dev/null +++ b/Source/Csla.test/FieldManager/Child.cs @@ -0,0 +1,81 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// no summary +//----------------------------------------------------------------------- + +using System; + +namespace Csla.Test.FieldManager +{ + [Serializable] + public class Child : BusinessBase + { + public static Child NewChild() + { + return Csla.DataPortal.CreateChild(); + } + + public static Child GetChild() + { + return Csla.DataPortal.FetchChild(); + } + + private Child() + { + MarkAsChild(); + } + + private static PropertyInfo DataProperty = RegisterProperty(typeof(Child), new PropertyInfo("Data")); + public string Data + { + get { return GetProperty(DataProperty); } + set { SetProperty(DataProperty, value); } + } + + private static PropertyInfo RootDataProperty = RegisterProperty(typeof(Child), new PropertyInfo("RootData", string.Empty)); + public string RootData + { + get { return GetProperty(RootDataProperty); } + set { SetProperty(RootDataProperty, value); } + } + + private string _status; + public string Status + { + get { return _status; } + } + + public void DeleteChild() + { + MarkDeleted(); + } + + protected override void Child_Create() + { + _status = "Created"; + } + + protected void Child_Fetch() + { + _status = "Fetched"; + } + + protected void Child_Insert() + { + _status = "Inserted"; + } + + protected void Child_Update() + { + _status = "Updated"; + } + + protected void Child_DeleteSelf() + { + _status = "Deleted"; + } + } +} \ No newline at end of file diff --git a/Source/Csla.test/FieldManager/ChildList.cs b/Source/Csla.test/FieldManager/ChildList.cs new file mode 100644 index 0000000000..b0f134a300 --- /dev/null +++ b/Source/Csla.test/FieldManager/ChildList.cs @@ -0,0 +1,48 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// no summary +//----------------------------------------------------------------------- + +using System; + +namespace Csla.Test.FieldManager +{ + [Serializable] + public class ChildList : BusinessBindingListBase + { + public static ChildList GetList() + { + return Csla.DataPortal.FetchChild(); + } + + private ChildList() + { + MarkAsChild(); + } + + public object MyParent + { + get { return this.Parent; } + } + + private string _status; + public string Status + { + get { return _status; } + } + + protected void Child_Fetch() + { + _status = "Fetched"; + } + + protected override void Child_Update(params object[] p) + { + base.Child_Update(); + _status = "Updated"; + } + } +} \ No newline at end of file diff --git a/Source/Csla.test/FieldManager/ChildUpdateTests.cs b/Source/Csla.test/FieldManager/ChildUpdateTests.cs new file mode 100644 index 0000000000..0711f87b39 --- /dev/null +++ b/Source/Csla.test/FieldManager/ChildUpdateTests.cs @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// no summary +//----------------------------------------------------------------------- + +using Microsoft.VisualStudio.TestTools.UnitTesting; +#if !NUNIT + +#else +using NUnit.Framework; +using TestClass = NUnit.Framework.TestFixtureAttribute; +using TestInitialize = NUnit.Framework.SetUpAttribute; +using TestCleanup = NUnit.Framework.TearDownAttribute; +using TestMethod = NUnit.Framework.TestAttribute; +#endif + +namespace Csla.Test.FieldManager +{ + [TestClass()] + public class ChildUpdateTests + { + [TestMethod] + public void FetchAndSaveChild() + { + Root root = new Root(); + root.FetchChild(); + + Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty"); + Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after fetch"); + + root = root.Save(); + + Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after Save"); + } + + [TestMethod] + public void FetchAndSaveAnyChild() + { + var root = new RootUpdateAllChildren(); + root.FetchChild(); + + Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty"); + Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after fetch"); + + root = root.Save(); + + Assert.AreEqual("Updated", root.Child.Status, "Child status incorrect after Save"); + } + + } +} \ No newline at end of file diff --git a/Source/Csla.test/FieldManager/Root.cs b/Source/Csla.test/FieldManager/Root.cs new file mode 100644 index 0000000000..c16c264e6c --- /dev/null +++ b/Source/Csla.test/FieldManager/Root.cs @@ -0,0 +1,60 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// no summary +//----------------------------------------------------------------------- + +using System; + +namespace Csla.Test.FieldManager +{ + [Serializable] + public class Root : BusinessBase + { + private static PropertyInfo DataProperty = RegisterProperty(typeof(Root), new PropertyInfo("Data")); + public string Data + { + get { return GetProperty(DataProperty); } + set { SetProperty(DataProperty, value); } + } + + private static PropertyInfo ChildProperty = RegisterProperty(typeof(Root), new PropertyInfo("Child")); + public Child Child + { + get + { + if (!FieldManager.FieldExists(ChildProperty)) + SetProperty(ChildProperty, Child.NewChild()); + return GetProperty(ChildProperty); + } + } + + private static PropertyInfo ChildListProperty = RegisterProperty(typeof(Root), new PropertyInfo("ChildList")); + public ChildList ChildList + { + get + { + if (!FieldManager.FieldExists(ChildListProperty)) + SetProperty(ChildListProperty, ChildList.GetList()); + return GetProperty(ChildListProperty); + } + } + + public void FetchChild() + { + SetProperty(ChildProperty, Child.GetChild()); + } + + protected override void DataPortal_Insert() + { + FieldManager.UpdateChildren(); + } + + protected override void DataPortal_Update() + { + FieldManager.UpdateChildren(); + } + } +} \ No newline at end of file diff --git a/Source/Csla.test/FieldManager/RootUpdateAllChildren.cs b/Source/Csla.test/FieldManager/RootUpdateAllChildren.cs new file mode 100644 index 0000000000..81d95a1709 --- /dev/null +++ b/Source/Csla.test/FieldManager/RootUpdateAllChildren.cs @@ -0,0 +1,52 @@ +using System; + +namespace Csla.Test.FieldManager +{ + [Serializable] + public class RootUpdateAllChildren : BusinessBase + { + private static PropertyInfo DataProperty = RegisterProperty(typeof(RootUpdateAllChildren), new PropertyInfo("Data")); + public string Data + { + get { return GetProperty(DataProperty); } + set { SetProperty(DataProperty, value); } + } + + private static PropertyInfo ChildProperty = RegisterProperty(typeof(RootUpdateAllChildren), new PropertyInfo("Child")); + public Child Child + { + get + { + if (!FieldManager.FieldExists(ChildProperty)) + SetProperty(ChildProperty, Child.NewChild()); + return GetProperty(ChildProperty); + } + } + + private static PropertyInfo ChildListProperty = RegisterProperty(typeof(RootUpdateAllChildren), new PropertyInfo("ChildList")); + public ChildList ChildList + { + get + { + if (!FieldManager.FieldExists(ChildListProperty)) + SetProperty(ChildListProperty, ChildList.GetList()); + return GetProperty(ChildListProperty); + } + } + + public void FetchChild() + { + SetProperty(ChildProperty, Child.GetChild()); + } + + protected override void DataPortal_Insert() + { + FieldManager.UpdateAllChildren(); + } + + protected override void DataPortal_Update() + { + FieldManager.UpdateAllChildren(); + } + } +} \ No newline at end of file diff --git a/Source/Csla.test/csla.test.csproj b/Source/Csla.test/csla.test.csproj index 1b9803bd33..1709a875a8 100644 --- a/Source/Csla.test/csla.test.csproj +++ b/Source/Csla.test/csla.test.csproj @@ -210,6 +210,11 @@ + + + + +