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.
RuleDescriptionTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="RuleDescriptionTests.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;
9using System.Collections.Generic;
10using System.Text;
11using UnitDriven;
13
14#if NUNIT
15using NUnit.Framework;
16using TestClass = NUnit.Framework.TestFixtureAttribute;
17using TestInitialize = NUnit.Framework.SetUpAttribute;
18using TestCleanup = NUnit.Framework.TearDownAttribute;
19using TestMethod = NUnit.Framework.TestAttribute;
20#elif MSTEST
21using Microsoft.VisualStudio.TestTools.UnitTesting;
22#endif
23
25{
26 [TestClass]
28 {
29 [TestMethod]
30 public void CheckDescription()
31 {
32 var root = new RuleTestClass();
33 foreach (var item in root.Rules)
34 {
35 var desc = new Csla.Rules.RuleUri(item);
36 Assert.AreEqual("csla.test.validationrules.myrule", desc.RuleTypeName, "Wrong rule type name");
37 }
38 }
39
40 [TestMethod]
41 public void BasicParsing()
42 {
43 var uri = new Csla.Rules.RuleUri("rule://type/property");
44 Assert.AreEqual("type", uri.RuleTypeName, "Rule type");
45 Assert.AreEqual("property", uri.PropertyName, "Property name");
46
47 uri = new Csla.Rules.RuleUri("rule://type/property?p1=a");
48 Assert.AreEqual("type", uri.RuleTypeName, "Rule type");
49 Assert.AreEqual("property", uri.PropertyName, "Property name");
50 }
51
52 [TestMethod]
53 public void NameParsing()
54 {
55 var uri = new Csla.Rules.RuleUri("type", "property");
56 Assert.AreEqual("type", uri.RuleTypeName, "Rule type");
57 Assert.AreEqual("property", uri.PropertyName, "Property name");
58 }
59
60 [TestMethod]
62 {
63 var uri = new Csla.Rules.RuleUri("A+ []`,=%Ä", "P+ []`,=%Ä");
64 Assert.AreEqual("a-----25-c3-84", uri.RuleTypeName, "Rule type");
65 Assert.AreEqual("P-----25-C3-84", uri.PropertyName, "Property name");
66 }
67
68 [TestMethod]
69 public void LongTypeName()
70 {
71 var hostName = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij";
72
73 var uri = new Csla.Rules.RuleUri(hostName, "property");
74 Assert.AreEqual(hostName.Replace("/", ""), uri.RuleTypeName, "Rule type");
75 Assert.AreEqual("property", uri.PropertyName, "Property name");
76 }
77
78 [TestMethod]
79 public void Arguments()
80 {
81 var uri = new Csla.Rules.RuleUri("rule://type/property?p1=v1");
82 Assert.AreEqual(1, uri.Arguments.Count, "Count should be 1");
83 Assert.AreEqual("v1", uri.Arguments["p1"], "Value shoudl be v1");
84
85 uri = new Csla.Rules.RuleUri("rule://type/property?p1=v1&p2=v2");
86 Assert.AreEqual(2, uri.Arguments.Count, "Count should be 2");
87 Assert.AreEqual("v1", uri.Arguments["p1"], "Value shoudl be v1");
88 Assert.AreEqual("v2", uri.Arguments["p2"], "Value shoudl be v2");
89 }
90 }
91
93 public class RuleTestClass : BusinessBase<RuleTestClass>
94 {
95 private static PropertyInfo<string> NameProperty = RegisterProperty(new PropertyInfo<string>("Name", "Name"));
96 public string Name
97 {
98 get { return GetProperty<string>(NameProperty); }
99 set { SetProperty<string>(NameProperty, value); }
100 }
101
102 protected override void AddBusinessRules()
103 {
104 BusinessRules.AddRule(new MyRule { PrimaryProperty = NameProperty });
105 }
106
107 public string[] Rules
108 {
109 get { return this.BusinessRules.GetRuleDescriptions(); }
110 }
111 }
112
113 public class MyRule : Rules.BusinessRule
114 {
115 protected override void Execute(Rules.IRuleContext context)
116 {
117 base.Execute(context);
118 }
119 }
120}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
Parses a rule:// URI to provide easy access to the parts of the URI.
Definition: RuleUri.cs:19
override void Execute(Rules.IRuleContext context)
@ Serializable
Prevents updating or inserting until the transaction is complete.