Esempio n. 1
0
        public void ValidatesPreBusinessRuleAndExecutes()
        {
            var model = new CounterModel();

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

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

            new CounterIncrementWorkflow(preRule).Execute(model);

            Assert.Equal(1, model.Counter);
        }
Esempio n. 2
0
        public void AndPredicateFiltersCorrectly()
        {
            var validCandidate = new CounterModel {
                Counter = 1
            };
            var invalidCandidate = new CounterModel {
                Counter = -1
            };

            var candidates = new List <CounterModel> {
                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);
        }
Esempio n. 3
0
        public void ThrowsErrorOnInvalidPreBusinessRuleAndDoesNotExecute()
        {
            var model = new CounterModel();

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

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

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

            preRule.Description = description;

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

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