CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
TestClasses.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using Csla;
7using Csla.Rules;
8
10{
12 public class Foo : BusinessBase<Foo>
13 {
14 public Foo()
15 {
16 ChildList = new FooList();
17 }
18
19 public static readonly PropertyInfo<string> NameProperty =
20 RegisterProperty<string>(c => c.Name);
21 public string Name
22 {
23 get { return GetProperty(NameProperty); }
24 set { SetProperty(NameProperty, value); }
25 }
26
27 public static readonly PropertyInfo<Foo> ChildProperty = RegisterProperty<Foo>(c => c.Child);
28 public Foo Child
29 {
30 get { return GetProperty(ChildProperty); }
31 set { SetProperty(ChildProperty, value); }
32 }
33
34 public static readonly PropertyInfo<FooList> ChildListProperty = RegisterProperty<FooList>(c => c.ChildList);
36 {
37 get { return GetProperty(ChildListProperty); }
38 private set { LoadProperty(ChildListProperty, value); }
39 }
40
41 public void AddChild(IDataPortal<Foo> dataPortal)
42 {
43 var child = dataPortal.Create();
44 child.MarkAsChild();
45 LoadProperty(ChildProperty, child);
46 }
47
48 public void MockUpdated()
49 {
50 MarkOld();
51 if (Child != null)
54 }
55
56 public void MarkForDelete()
57 {
58 MarkDeleted();
59 if (Child != null)
61 ChildList.Clear();
62 }
63
64 public void MockDeleted()
65 {
66 MarkNew();
67 if (Child != null)
69 ChildList.MockDeleted();
70 }
71
72 protected override void AddBusinessRules()
73 {
74 base.AddBusinessRules();
75 BusinessRules.AddRule(new NoTwo { PrimaryProperty = NameProperty });
76 }
77
78 private class NoTwo : Csla.Rules.BusinessRule
79 {
80 protected override void Execute(IRuleContext context)
81 {
82 var target = (Foo)context.Target;
83 if (target.Name == "2")
84 context.AddErrorResult("Name can not be 2");
85 }
86 }
87
88 [Create]
89 private void Create([Inject] IChildDataPortal<FooList> childDataPortal)
90 {
91 LoadProperty(ChildListProperty, childDataPortal.CreateChild());
93 }
94
95 [InsertChild]
96 private void Child_Insert()
97 { }
98
99 [UpdateChild]
100 private void Child_Update()
101 { }
102
103 [DeleteSelfChild]
104 private void Child_DeleteSelf()
105 { }
106 }
107
109 public class FooList : BusinessListBase<FooList, Foo>
110 {
111 public void MockUpdated()
112 {
113 foreach (var item in this)
114 item.MockUpdated();
115 DeletedList.Clear();
116 }
117
118 internal void MockDeleted()
119 {
120 Clear();
121 DeletedList.Clear();
122 }
123
124 [Create]
125 private void Create()
126 {
127 }
128
129 [Update]
130 protected void DataPortal_Update()
131 {
132 base.Child_Update();
133 }
134 }
135
137 public class FooBindingList : BusinessBindingListBase<FooBindingList, Foo>
138 {
139 [Create]
140 private void DataPortal_Create()
141 {
142
143 }
144 }
145
147 public class FooDynamicList : DynamicListBase<Foo>
148 {
149 private void DataPortal_Create()
150 { }
151 }
152
155 {
156 private void DataPortal_Create()
157 { }
158 }
159}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
This is the base class from which most business collections or lists will be derived.
This is the base class from which most business collections or lists will be derived.
MobileList< C > DeletedList
A collection containing all child objects marked for deletion.
This is the base class from which collections of editable root business objects should be derived.
This is the base class from which collections of editable root business objects should be derived.
Maintains metadata about a property.
Base class used to create business and validation rules.
Definition: BusinessRule.cs:15
Tracks the business rules for a business object.
List< string > CheckRules()
Invokes all rules for the business type.
void AddRule(IBusinessRuleBase rule)
Associates a business rule with the business object.
void AddChild(IDataPortal< Foo > dataPortal)
Definition: TestClasses.cs:41
override void AddBusinessRules()
Definition: TestClasses.cs:72
static readonly PropertyInfo< string > NameProperty
Definition: TestClasses.cs:19
static readonly PropertyInfo< Foo > ChildProperty
Definition: TestClasses.cs:27
static readonly PropertyInfo< FooList > ChildListProperty
Definition: TestClasses.cs:34
Interface defining the members of the child data portal type.
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
Context information provided to a business rule when it is invoked.
Definition: IRuleContext.cs:22
object Target
Gets a reference to the target business object.
Definition: IRuleContext.cs:31
void AddErrorResult(string description)
Add a Error severity result to the Results list.
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Execute
Execute operation.
@ Create
Create operation.