示例#1
0
        public void Validator_All_Facts_Reset()
        {
            var sv = new SimplisticValidator("model", 123456789);

            sv.Facts.ToList().ForEach(f => f.IsChecked = f.Success = true);
            Assert.IsTrue(sv.Reset().All(f => !f.IsChecked && !f.Success && f.Exception == null));
        }
示例#2
0
        public void Fact_Check_throws_Exception()
        {
            var sv   = new SimplisticValidator("model", 123456789);
            var fact = sv.Facts.First();

            fact.CheckAsync = (cancellationToken) => throw new ArgumentNullException();
            Task.FromResult(sv.CheckAsync(fact.Id, CancellationToken.None));
            Assert.IsTrue(!fact.Success && fact.IsChecked && fact.Exception is ArgumentNullException);
        }
示例#3
0
        public void Fact_Reset()
        {
            var sv      = new SimplisticValidator("model", 123456789);
            var anyFact = sv.Facts.First();

            anyFact.IsChecked = anyFact.Success = true;
            anyFact.Exception = new AccessViolationException();
            anyFact.Reset();
            Assert.IsTrue(!anyFact.IsChecked && !anyFact.Success && anyFact.Exception == null);
        }
示例#4
0
        public void Set_Get_Fact_Properties()
        {
            var sv      = new SimplisticValidator("model", 123456789);
            var fact    = sv.Facts.First();
            var oldType = fact.Type;

            fact.Type = oldType == FactType.Error ? FactType.Warning : FactType.Error;
            Assert.AreNotEqual(oldType, fact.Type);
            Assert.IsTrue(fact.FieldNames.Count() == 1);
        }
示例#5
0
        public void Check_All_Facts()
        {
            var sv = new SimplisticValidator("The model", 123456789);

            sv.Facts.Last().Enabled = true;

            var result = sv.CheckAsync(CancellationToken.None).Result;

            Assert.AreEqual(sv.Facts.Count, result.Count);
        }
示例#6
0
        public void Disabled_Fact_Is_Not_Executed()
        {
            var sv   = new SimplisticValidator("model", 123456789);
            var fact = sv.Facts.First();

            fact.CheckAsync = (cancellationToken) => throw new ArithmeticException();
            Assert.Throws <ArithmeticException>(() => fact.CheckAsync(CancellationToken.None));
            fact.Enabled = false;
            Task.FromResult(sv.CheckAsync(fact.Id, CancellationToken.None));
            Assert.IsNull(fact.Exception); // check is not executed
        }
示例#7
0
        private SimplisticValidator CreateValidatorWithErrorForType(FactType factType)
        {
            var sv = new SimplisticValidator("The model", 123456789);

            Assert.AreEqual(3, sv.Facts.Count);

            var fact = sv.Facts.First(f => f.Type == factType);

            fact.Enabled    = true;
            fact.CheckAsync = (cancellationToken) => Task.FromResult(new FactResult
            {
                Message = "error " + sv.Model,
                Success = false
            });
            return(sv);
        }
示例#8
0
        public void Get_Enabled_Facts()
        {
            var sv = new SimplisticValidator("The model", 123456789);

            Assert.AreEqual(2, sv.GetEnabledFacts().Count);
        }