Пример #1
0
        public void NotExtensionEvaluesCorrectly()
        {
            var model = new GuidCount();

            model.Increment();
            Assert.False(new PositiveCounterRule().Not().IsSatisfied(model));
        }
Пример #2
0
        public void SimpleSatisfiedRuleReturnsTrue()
        {
            var model = new GuidCount();

            model.Increment();
            Assert.True(new PositiveCounterRule().IsSatisfied(model));
        }
Пример #3
0
        public void OrExtensionEvaluatesCorrectly()
        {
            var model = new GuidCount();

            model.Increment();
            Assert.True(new PositiveCounterRule().Or(new NegativeCounterRule()).IsSatisfied(model));
        }
Пример #4
0
        public void ExecutesWithoutBusinessRule()
        {
            var model = new GuidCount();

            new GuidCountIncrementWorkflow().Execute(model);
            Assert.Equal(1, model.Counter);
        }
Пример #5
0
        public void CanExecuteChainedWorkflowsOfDifferentTypeViaFlow()
        {
            var incWorkflow = new GuidCountIncrementWorkflow();
            var dupWorkflow = new GuidCountDuplicateWorkflow();

            var results = new GuidCount().AsFlowable().Flow(incWorkflow).Flow(incWorkflow).Flow(dupWorkflow).Value;

            Assert.Equal(2, results.Count);
            Assert.True(results.All(r => r.Counter == 2));
        }
Пример #6
0
        public void ValidatesPreBusinessRuleAndExecutes()
        {
            var model = new GuidCount();

            var preRule = Substitute.For <IStateRule <GuidCount> >();

            preRule.IsSatisfied(Arg.Any <GuidCount>()).Returns(true);

            new GuidCountIncrementWorkflow(preRule).Execute(model);

            Assert.Equal(1, model.Counter);
        }
Пример #7
0
        public void TypeModWorkflowExecutesCorrectly()
        {
            var model = new GuidCount();

            var preRule = Substitute.For <IStateRule <GuidCount> >();

            preRule.IsSatisfied(Arg.Any <GuidCount>()).Returns(true);

            var result = new GuidCountDuplicateWorkflow(preRule).Execute(model);

            Assert.IsType <List <GuidCount> >(result);
            Assert.Equal(2, result.Count);
        }
Пример #8
0
        public void AndPredicateFiltersCorrectly()
        {
            var validCandidate = new GuidCount {
                Counter = 1
            };
            var invalidCandidate = new GuidCount {
                Counter = -1
            };

            var candidates = new List <GuidCount> {
                validCandidate, invalidCandidate
            }.AsQueryable();
            var filtered = candidates.Where(new PositiveCounterRule().And(new LessThanTenCounterRule()).Predicate).ToList();

            Assert.Equal(1, filtered.Count);
            Assert.Equal(validCandidate.Id, filtered[0].Id);
        }
Пример #9
0
        public void ThrowsErrorOnInvalidPreBusinessRuleAndDoesNotExecute()
        {
            var model = new GuidCount();

            var preRule = Substitute.For <IStateRule <GuidCount> >();

            preRule.IsSatisfied(Arg.Any <GuidCount>()).Returns(false);

            const string description = "This mock rule must be satisfied.";

            preRule.Description = description;

            var message = Assert.Throws(typeof(StateRuleException), () => new GuidCountIncrementWorkflow(preRule).Execute(model)).Message;

            Assert.Equal(description, message);
            Assert.Equal(0, model.Counter);
        }