-
-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1172 from j055/feature/update-all-children
Added UpdateAllChildren to FieldManager
- Loading branch information
Showing
8 changed files
with
344 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="Child.cs" company="Marimer LLC"> | ||
// Copyright (c) Marimer LLC. All rights reserved. | ||
// Website: https://cslanet.com | ||
// </copyright> | ||
// <summary>no summary</summary> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace Csla.Test.FieldManager | ||
{ | ||
[Serializable] | ||
public class Child : BusinessBase<Child> | ||
{ | ||
public static Child NewChild() | ||
{ | ||
return Csla.DataPortal.CreateChild<Child>(); | ||
} | ||
|
||
public static Child GetChild() | ||
{ | ||
return Csla.DataPortal.FetchChild<Child>(); | ||
} | ||
|
||
private Child() | ||
{ | ||
MarkAsChild(); | ||
} | ||
|
||
private static PropertyInfo<string> DataProperty = RegisterProperty<string>(typeof(Child), new PropertyInfo<string>("Data")); | ||
public string Data | ||
{ | ||
get { return GetProperty<string>(DataProperty); } | ||
set { SetProperty<string>(DataProperty, value); } | ||
} | ||
|
||
private static PropertyInfo<string> RootDataProperty = RegisterProperty<string>(typeof(Child), new PropertyInfo<string>("RootData", string.Empty)); | ||
public string RootData | ||
{ | ||
get { return GetProperty<string>(RootDataProperty); } | ||
set { SetProperty<string>(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"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="ChildList.cs" company="Marimer LLC"> | ||
// Copyright (c) Marimer LLC. All rights reserved. | ||
// Website: https://cslanet.com | ||
// </copyright> | ||
// <summary>no summary</summary> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace Csla.Test.FieldManager | ||
{ | ||
[Serializable] | ||
public class ChildList : BusinessBindingListBase<ChildList, Child> | ||
{ | ||
public static ChildList GetList() | ||
{ | ||
return Csla.DataPortal.FetchChild<ChildList>(); | ||
} | ||
|
||
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"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="DataPortalChildTests.cs" company="Marimer LLC"> | ||
// Copyright (c) Marimer LLC. All rights reserved. | ||
// Website: https://cslanet.com | ||
// </copyright> | ||
// <summary>no summary</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"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="Root.cs" company="Marimer LLC"> | ||
// Copyright (c) Marimer LLC. All rights reserved. | ||
// Website: https://cslanet.com | ||
// </copyright> | ||
// <summary>no summary</summary> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace Csla.Test.FieldManager | ||
{ | ||
[Serializable] | ||
public class Root : BusinessBase<Root> | ||
{ | ||
private static PropertyInfo<string> DataProperty = RegisterProperty<string>(typeof(Root), new PropertyInfo<string>("Data")); | ||
public string Data | ||
{ | ||
get { return GetProperty<string>(DataProperty); } | ||
set { SetProperty<string>(DataProperty, value); } | ||
} | ||
|
||
private static PropertyInfo<Child> ChildProperty = RegisterProperty<Child>(typeof(Root), new PropertyInfo<Child>("Child")); | ||
public Child Child | ||
{ | ||
get | ||
{ | ||
if (!FieldManager.FieldExists(ChildProperty)) | ||
SetProperty<Child>(ChildProperty, Child.NewChild()); | ||
return GetProperty<Child>(ChildProperty); | ||
} | ||
} | ||
|
||
private static PropertyInfo<ChildList> ChildListProperty = RegisterProperty<ChildList>(typeof(Root), new PropertyInfo<ChildList>("ChildList")); | ||
public ChildList ChildList | ||
{ | ||
get | ||
{ | ||
if (!FieldManager.FieldExists(ChildListProperty)) | ||
SetProperty<ChildList>(ChildListProperty, ChildList.GetList()); | ||
return GetProperty<ChildList>(ChildListProperty); | ||
} | ||
} | ||
|
||
public void FetchChild() | ||
{ | ||
SetProperty<Child>(ChildProperty, Child.GetChild()); | ||
} | ||
|
||
protected override void DataPortal_Insert() | ||
{ | ||
FieldManager.UpdateChildren(); | ||
} | ||
|
||
protected override void DataPortal_Update() | ||
{ | ||
FieldManager.UpdateChildren(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
|
||
namespace Csla.Test.FieldManager | ||
{ | ||
[Serializable] | ||
public class RootUpdateAllChildren : BusinessBase<RootUpdateAllChildren> | ||
{ | ||
private static PropertyInfo<string> DataProperty = RegisterProperty<string>(typeof(RootUpdateAllChildren), new PropertyInfo<string>("Data")); | ||
public string Data | ||
{ | ||
get { return GetProperty<string>(DataProperty); } | ||
set { SetProperty<string>(DataProperty, value); } | ||
} | ||
|
||
private static PropertyInfo<Child> ChildProperty = RegisterProperty<Child>(typeof(RootUpdateAllChildren), new PropertyInfo<Child>("Child")); | ||
public Child Child | ||
{ | ||
get | ||
{ | ||
if (!FieldManager.FieldExists(ChildProperty)) | ||
SetProperty<Child>(ChildProperty, Child.NewChild()); | ||
return GetProperty<Child>(ChildProperty); | ||
} | ||
} | ||
|
||
private static PropertyInfo<ChildList> ChildListProperty = RegisterProperty<ChildList>(typeof(RootUpdateAllChildren), new PropertyInfo<ChildList>("ChildList")); | ||
public ChildList ChildList | ||
{ | ||
get | ||
{ | ||
if (!FieldManager.FieldExists(ChildListProperty)) | ||
SetProperty<ChildList>(ChildListProperty, ChildList.GetList()); | ||
return GetProperty<ChildList>(ChildListProperty); | ||
} | ||
} | ||
|
||
public void FetchChild() | ||
{ | ||
SetProperty<Child>(ChildProperty, Child.GetChild()); | ||
} | ||
|
||
protected override void DataPortal_Insert() | ||
{ | ||
FieldManager.UpdateAllChildren(); | ||
} | ||
|
||
protected override void DataPortal_Update() | ||
{ | ||
FieldManager.UpdateAllChildren(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters