Example #1
0
        public void LessThanSetsErrorOnBothFields()
        {
            // StartDate less than
            string ruleSet = "Date";
            string err1, err2;
            var    actual = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            actual.StartDate = "today";
            actual.EndDate   = "yesterday";

            err1 = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.StartDateProperty.Name];
            err2 = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.EndDateProperty.Name];

            Assert.IsFalse(actual.IsSelfValid); // object has broken rule
            Assert.IsTrue(err1.Length > 1);     // both fields have error message
            Assert.IsTrue(err2.Length > 1);

            actual.EndDate = "tomorrow";
            err1           = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.StartDateProperty.Name];
            err2           = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.EndDateProperty.Name];

            Assert.IsTrue(actual.IsSelfValid);   // object has no broken rules
            Assert.AreEqual(string.Empty, err1); // both fields are now OK
            Assert.AreEqual(string.Empty, err2);
        }
Example #2
0
        public void NewObjectWithObjectRulesIsValid()
        {
            string ruleSet = "Object";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            Assert.IsTrue(actual.IsSelfValid);
        }
Example #3
0
        public void AsyncLookupDoNotRunServerSide()
        {
            string ruleSet = "Lookup";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            // rule did not run on serverside (DAL) and no value is explicitly set
            Assert.AreEqual(string.Empty, actual.Name);
        }
Example #4
0
        public void NewObjectWithObjectRulesHas3InfosForCustomerId6()
        {
            string ruleSet = "Object";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            actual.CustomerId = 6;
            Assert.IsTrue(actual.IsValid);
            Assert.AreEqual(3, actual.BrokenRulesCollection.Where(p => p.Severity == RuleSeverity.Information).Count());
        }
Example #5
0
        public void NewObjectWithObjectRulesHas3ErrorForCustomerId4()
        {
            string ruleSet = "Object";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            actual.CustomerId = 4;
            Assert.IsFalse(actual.IsValid);
            Assert.AreEqual(3, actual.BrokenRulesCollection.Where(p => p.Severity == RuleSeverity.Error).Count());
        }
Example #6
0
        public void NewObjectWithObjectRulesIsValid()
        {
            IDataPortal <RuleBaseClassesRoot> dataPortal = _testDIContext.CreateDataPortal <RuleBaseClassesRoot>();

            string ruleSet = "Object";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(dataPortal, ruleSet);

            Assert.IsTrue(actual.IsSelfValid);
        }
Example #7
0
        public void AsyncLookupDoNotRunServerSide()
        {
            IDataPortal <RuleBaseClassesRoot> dataPortal = _testDIContext.CreateDataPortal <RuleBaseClassesRoot>();

            string ruleSet = "Lookup";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(dataPortal, ruleSet);

            // rule did not run on serverside (DAL) and no value is explicitly set
            Assert.AreEqual(string.Empty, actual.Name);
        }
Example #8
0
        public void NewObjectWithObjectRulesHas3InfosForCustomerId6()
        {
            IDataPortal <RuleBaseClassesRoot> dataPortal = _testDIContext.CreateDataPortal <RuleBaseClassesRoot>();

            string ruleSet = "Object";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(dataPortal, ruleSet);

            actual.CustomerId = 6;
            Assert.IsTrue(actual.IsValid);
            Assert.AreEqual(3, actual.BrokenRulesCollection.Where(p => p.Severity == RuleSeverity.Information).Count());
        }
Example #9
0
        public void NameRequiredIsBrokenOnNewRoot()
        {
            // test that Name has broken rule on new object
            string ruleSet = "LookupAndNameRequired";
            string err1;
            var    actual = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            err1 = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.NameProperty.Name];


            Assert.AreEqual(string.Empty, actual.Name); // name is not set
            Assert.IsFalse(actual.IsSelfValid);         // object has broken rules
            Assert.IsTrue(err1.Length > 0);             // name has broken rule with message
        }
Example #10
0
        public void AsyncLookupCustomerSetsCustomerName()
        {
            string ruleSet = "Lookup";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            actual.ValidationComplete += (o, e) => waitHandle.Set();
            waitHandle.Reset();
            actual.CustomerId = 1;
            waitHandle.WaitOne(); // wait for async lookup to complete
            Assert.AreEqual("Rocky Lhotka", actual.Name);

            waitHandle.Reset();
            actual.CustomerId = 2;
            waitHandle.WaitOne();
            Assert.AreEqual("Customer_2", actual.Name);
        }
Example #11
0
        public void MessageDelegateAndResources()
        {
            string ruleSet = "Required";
            var    actual  = RuleBaseClassesRoot.NewEditableRoot(ruleSet);
            var    culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
            actual.Name = "xyz";
            actual.Name = "";
            Assert.AreEqual("Name required", actual.BrokenRulesCollection[0].Description);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo("nb-NO");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("nb-NO");
            actual.Name = "xyz";
            actual.Name = "";
            Assert.AreEqual("Name pÄkrevd", actual.BrokenRulesCollection[0].Description);
            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;
        }
Example #12
0
        public void NameRequiredIsNotBrokenAfterLookupCustomer()
        {
            // test that Name is revalidated as it is an affected property of LookupCustomer rule
            // that runs when CustomerId is set.
            string ruleSet = "LookupAndNameRequired";
            string err1;
            var    actual = RuleBaseClassesRoot.NewEditableRoot(ruleSet);

            err1 = ((IDataErrorInfo)actual)[RuleBaseClassesRoot.NameProperty.Name];

            Assert.IsFalse(actual.IsSelfValid); // is broken before we set customerid

            var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            actual.ValidationComplete += (o, e) => waitHandle.Set();
            waitHandle.Reset();
            actual.CustomerId = 1;
            waitHandle.WaitOne();              // wait for async lookup to complete

            Assert.IsTrue(actual.IsSelfValid); // is valid after
        }