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.
Fakes/Server/DataPortal/Single.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="Single.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//-----------------------------------------------------------------------
8using System.Collections.Generic;
9using System.Text;
10using Csla;
11using System;
12using System.Threading.Tasks;
13
14using Csla.Core;
15using Csla.Server;
16
18{
19#if TESTING
20 [System.Diagnostics.DebuggerNonUserCode]
21#endif
23 public class Single : BusinessBase<Single>
24 {
25 public readonly static PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
26 public int Id
27 {
28 get { return GetProperty(IdProperty); }
29 set { SetProperty(IdProperty, value); }
30 }
31
32 public readonly static PropertyInfo<string> MethodCalledProperty = RegisterProperty<string>(c => c.MethodCalled, "MethodCalled");
33 public string MethodCalled
34 {
35 get { return GetProperty(MethodCalledProperty); }
36 set { SetProperty(MethodCalledProperty, value); }
37 }
38
39 public Single()
40 { }
41
42 [Create]
43 protected void DataPortal_Create()
44 {
45 DoCreate(0);
46 BusinessRules.CheckRules();
47 }
48
49 [Create]
50 protected void DataPortal_Create(int id)
51 {
52 DoCreate(id);
53 BusinessRules.CheckRules();
54 }
55
56 private void DoCreate(int id)
57 {
58 Id = id;
60 TestResults.Add("Single", "Created");
61 MethodCalled = "Created";
62 if (id == 9999)
63 throw new Exception("Bad data");
64 }
65
66 private void DataPortal_Fetch()
67 {
68 DoFetch(0);
69 }
70
71 private void DataPortal_Fetch(int id)
72 {
73 DoFetch(id);
74 }
75
76 private void DoFetch(int id)
77 {
78 Id = id;
79 TestResults.Reinitialise();
80 TestResults.Add("Single", "Fetched");
81 MethodCalled = "Fetched";
82 if (id == 9999)
83 throw new Exception("Bad data");
84 }
85
86 [Insert]
87 protected void DataPortal_Insert()
88 {
89 DoInsertUpdate(false);
90 }
91
92 [Update]
93 protected void DataPortal_Update()
94 {
95 DoInsertUpdate(true);
96 }
97
98 private void DoInsertUpdate(bool isUpdate)
99 {
100 var insertOrUpdate = isUpdate ? "Updated" : "Inserted";
101
103 TestResults.Add("Single", insertOrUpdate);
104 MethodCalled = insertOrUpdate;
105 }
106
107 [DeleteSelf]
108 protected void DataPortal_DeleteSelf()
109 {
111 TestResults.Add("Single", "SelfDeleted");
112 MethodCalled = "SelfDeleted";
113 }
114
115 [Delete]
116 private void DataPortal_Delete(int id)
117 {
119 TestResults.Add("Single", "Deleted");
120 MethodCalled = "Deleted";
121 }
122 }
123
125 [ObjectFactory(typeof(SingleWithFactoryFactory))]
126 public class SingleWithFactory : BusinessBase<SingleWithFactory>
127 {
128 }
129
131 {
132 public SingleWithFactoryFactory(ApplicationContext applicationContext) : base(applicationContext)
133 {
134
135 }
136
137 public async Task<object> Fetch()
138 {
139 return await Task.Run(() => new SingleWithFactory());
140 }
141
142 public async Task<object> Create()
143 {
144 return await Task.Run(() => new SingleWithFactory());
145 }
146 }
147
149 public class Single2 : BusinessBase<Single2>
150 {
151 public static readonly PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
152 public int Id
153 {
154 get { return GetProperty(IdProperty); }
155 set { SetProperty(IdProperty, value); }
156 }
157
158 private void DataPortal_Create(int id)
159 {
160 if (id == 9999)
161 throw new Exception("bad value");
162 Id = id;
163 BusinessRules.CheckRules();
164 }
165
166 private void DataPortal_Fetch()
167 {
168 DataPortal_Fetch(0);
169 }
170
171 private void DataPortal_Fetch(int id)
172 {
173 if (id == 9999)
174 throw new Exception("bad value");
175 Id = id;
176 BusinessRules.CheckRules();
177 }
178
179 [Insert]
180 protected void DataPortal_Insert()
181 {
182 if (Id == 555)
183 throw new Exception("bad value");
184 }
185
186 [Update]
187 protected void DataPortal_Update()
188 {
189 if (Id == 555)
190 throw new Exception("bad value");
191 }
192
193 [DeleteSelf]
194 protected void DataPortal_DeleteSelf()
195 {
196 if (Id == 555)
197 throw new Exception("bad value");
198 }
199
200 [Delete]
201 private void DataPortal_Delete(int id)
202 {
203 if (Id == 555)
204 throw new Exception("bad value");
205 Id = id;
206 }
207 }
208
210 public class SingleCommand : CommandBase<SingleCommand>
211 {
212 public static readonly PropertyInfo<int> ValueProperty = RegisterProperty<int>(c => c.Value);
213 public int Value
214 {
215 get { return ReadProperty(ValueProperty); }
216 set { LoadProperty(ValueProperty, value); }
217 }
218
219 [RunLocal]
220 [Create]
221 private void Create()
222 { }
223
224 [RunLocal]
225 [Create]
226 private void Create(int value)
227 {
228 Value = value;
229 }
230
231 [Execute]
232 protected void DataPortal_Execute()
233 {
234 if (Value == 555)
235 throw new Exception("bad value");
236 Value += 1;
237 }
238 }
239}
Provides consistent context information between the client and server DataPortal objects.
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
This is the base class from which command objects will be derived.
Definition: CommandBase.cs:51
Maintains metadata about a property.
Base class to be used when creating a data portal factory object.
Class containing the default implementation for the FactoryLoader delegate used by the data portal ho...
static readonly PropertyInfo< int > IdProperty
static readonly PropertyInfo< int > ValueProperty
static readonly PropertyInfo< int > IdProperty
static readonly PropertyInfo< string > MethodCalledProperty
SingleWithFactoryFactory(ApplicationContext applicationContext)
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
Definition: TestResults.cs:69
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:29
@ 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.
@ Delete
Delete operation.