9using System.Collections.Generic;
17using System.ComponentModel.DataAnnotations;
18using System.Threading.Tasks;
23using TestClass = NUnit.Framework.TestFixtureAttribute;
24using TestInitialize = NUnit.Framework.SetUpAttribute;
25using TestCleanup = NUnit.Framework.TearDownAttribute;
26using TestMethod = NUnit.Framework.TestAttribute;
27using TestSetup = NUnit.Framework.SetUpAttribute;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
35 [System.Diagnostics.DebuggerNonUserCode]
45 _testDIContext = TestDIContextFactory.CreateDefaultContext();
53 var dp = _testDIContext.CreateDataPortal<
Single>();
54 var root = await dp.CreateAsync();
57 Assert.AreEqual(1, rules.Length,
"Should be 1 rule");
58 Assert.IsFalse(root.IsValid,
"Obj shouldn't be valid");
59 Assert.AreEqual(1, root.BrokenRulesCollection.Count,
"Should be 1 broken rule");
60 Assert.AreEqual(
"Name value required", root.BrokenRulesCollection[0].Description,
"Desc should match");
61 context.Assert.Success();
71 var dp = _testDIContext.CreateDataPortal<
Multiple>();
72 var root = await dp.CreateAsync();
75 Assert.AreEqual(3, rules.Length,
"Should be 3 rules");
76 Assert.IsFalse(root.IsValid,
"Obj shouldn't be valid");
77 Assert.AreEqual(1, root.BrokenRulesCollection.Count,
"Should be 1 broken rule");
79 Assert.AreEqual(2, root.BrokenRulesCollection.Count,
"Should be 2 broken rules after edit");
80 context.Assert.Success();
90 var dp = _testDIContext.CreateDataPortal<
Custom>();
91 var root = await dp.CreateAsync();
94 Assert.AreEqual(1, rules.Length,
"Should be 1 rule");
95 Assert.IsFalse(root.IsValid,
"Obj shouldn't be valid");
96 Assert.AreEqual(1, root.BrokenRulesCollection.Count,
"Should be 1 broken rule");
97 Assert.AreEqual(
"Name must be abc", root.BrokenRulesCollection[0].Description,
"Desc should match");
98 context.Assert.Success();
108 var obj = dataPortal.
Fetch();
110 var typeRules = obj.GetRegisteredRules();
112 Assert.AreEqual(5, typeRules.Rules.Count);
123 [Required(ErrorMessage =
"Name value required")]
126 get {
return GetProperty(NameProperty); }
127 set { SetProperty(NameProperty, value); }
131 private async Task Create()
146 [Required(ErrorMessage =
"Name value required")]
147 [RegularExpression(
"[0-9]")]
148 [System.ComponentModel.DataAnnotations.Range(typeof(
string),
"0",
"9")]
151 get {
return GetProperty(NameProperty); }
152 set { SetProperty(NameProperty, value); }
156 private async Task Create()
174 get {
return GetProperty(NameProperty); }
175 set { SetProperty(NameProperty, value); }
179 private async Task Create()
192 protected override ValidationResult
IsValid(
object value, ValidationContext validationContext)
194 if (validationContext.ObjectInstance ==
null)
195 return new ValidationResult(
"ObjectInstance is null");
196 var obj = validationContext.ObjectInstance as
Custom;
198 return new ValidationResult(
"ObjectInstance is not the Custom type");
199 if (
string.IsNullOrEmpty(obj.Name) || obj.Name !=
"abc")
200 return new ValidationResult(
"Name must be abc");
210 [Required(ErrorMessage=
"Please enter an amount")]
233 [Required(ErrorMessage =
"Amount is required")]
234 [Range(typeof(decimal),
"1",
"100", ErrorMessage =
"Please enter a value between 1 and 100")]
235 public System.Decimal
Amount {
get;
set; }
237 [Required(ErrorMessage =
"Quantity is required")]
238 [Range(1, 100, ErrorMessage =
"Please enter a value between 1 and 100")]
245 [MetadataType(typeof(MultipleMetaDataClass))]
250 return base.GetRegisteredRules();
This is the base class from which most business objects will be derived.
Maintains metadata about a property.
Manages the list of rules for a business type.
Tracks the business rules for a business object.
async Task< List< string > > CheckRulesAsync(int timeout)
Invokes all rules for the business type.
string[] GetRuleDescriptions()
Gets a list of rule:// URI values for the rules defined in the object.
static void ClassInitialize(TestContext context)
async Task MultipleAttributes()
async Task CustomAttribute()
async Task SingleAttribute()
override ValidationResult IsValid(object value, ValidationContext validationContext)
Type to carry context information for DI in unit tests
UnitTestContext GetContext()
Interface defining the members of the data portal type.
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
@ Serializable
Prevents updating or inserting until the transaction is complete.