public void MultipleCollectionSteps_RevertFailed_RetryAndRevertAll()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformSixItemIndex = 1;
            codeBehind.ThrowFromRevertFiveItemIndex = 0;
            codeBehind.ThrowFromRevertFour          = true;

            var exception = Assert.Throws <AggregateException>(() => {
                sequence.Perform();
            });

            codeBehind.ThrowFromRevertFiveItemIndex = null;
            codeBehind.ThrowFromRevertFour          = false;
            codeBehind.TakeLog();

            //-- Act

            sequence.Revert();

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "RevertFiveItem(111,index=0,last=F)",
                "RevertFour()",
            });
        }
        public void OnceSteps_Revert_ReverseOrder()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind();
            var sequence   = new RevertableSequence(codeBehind);

            sequence.Perform();

            //-- Act

            var log1 = codeBehind.TakeLog();

            sequence.Revert();

            var log2 = codeBehind.TakeLog();

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(log1, new[] {
                "PerformOne()", "PerformTwo()", "PerformThree()"
            });
            Assert.Equal(log2, new[] {
                "RevertFour()", "RevertTwo()", "RevertOne()"
            });
        }
        public void MultipleCollectionSteps_RevertSucceeded_AllItemsReverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();
            codeBehind.TakeLog();

            //-- Act

            sequence.Revert();

            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "RevertSevenItem(Sunday,index=1,last=T)",
                "RevertSevenItem(Friday,index=0,last=F)",
                "RevertFiveItem(222,index=1,last=T)",
                "RevertFiveItem(111,index=0,last=F)",
                "RevertFour()",
                "RevertTwo()",
                "RevertOne()",
            });
        }
        public void CollectionSteps_PerformFailed_PerformedItemsReverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(fiveItems: new[] { 111, 222, 333 });
            var sequence   = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformFiveItemIndex = 2;

            //-- Act

            var exception = Assert.Throws <TestSequenceException>(() => {
                sequence.Perform();
            });

            //-- Assert

            Assert.Equal(exception.Message, "PerformFiveItem(333,index=2,last=T)");
            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "PerformOne()",
                "PerformTwo()",
                "PerformThree()",
                "PerformFiveItem(111,index=0,last=F)",
                "PerformFiveItem(222,index=1,last=F)",
                "THROWING-FROM:PerformFiveItem(333,index=2,last=T)",
                "RevertFiveItem(222,index=1,last=F)",
                "RevertFiveItem(111,index=0,last=F)",
                "RevertFour()",
                "RevertTwo()",
                "RevertOne()"
            });
        }
        public void OnceSteps_RevertFailed_RetryRevertAndSucceed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind()
            {
                ThrowFromRevertFour = true,
                ThrowFromRevertTwo  = true
            };
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();

            var exception = Assert.Throws <AggregateException>(() => {
                sequence.Revert();
            });

            codeBehind.TakeLog();

            codeBehind.ThrowFromRevertFour = false;
            codeBehind.ThrowFromRevertTwo  = false;

            //-- Act

            sequence.Revert();

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "RevertFour()", "RevertTwo()"
            });
        }
        public void OnceSteps_RevertFailed_AggregateExceptionThrown()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind()
            {
                ThrowFromRevertFour = true,
                ThrowFromRevertTwo  = true
            };
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();
            codeBehind.TakeLog();

            //-- Act

            var exception = Assert.Throws <AggregateException>(() => {
                sequence.Revert();
            });

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.RevertFailed);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "THROWING-FROM:RevertFour()", "THROWING-FROM:RevertTwo()", "RevertOne()"
            });

            Assert.True(exception.InnerExceptions.All(e => e is TestSequenceException), "Exception type");
            Assert.Equal(exception.InnerExceptions.Select(e => e.Message), new[] {
                "RevertFour()", "RevertTwo()"
            });
        }
        public void OnceSteps_PerformSucceeded_StatePerformed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind();
            var sequence   = new RevertableSequence(codeBehind);

            //-- Act

            sequence.Perform();

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.Performed);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "PerformOne()", "PerformTwo()", "PerformThree()"
            });
        }
        public void MultipleCollectionSteps_PerformFailedThenRevertFailed_AllErrorsInAggregateException()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformSixItemIndex = 1;
            codeBehind.ThrowFromRevertFiveItemIndex = 0;
            codeBehind.ThrowFromRevertFour          = true;

            //-- Act


            var exception = Assert.Throws <AggregateException>(() => {
                sequence.Perform();
            });

            Assert.Equal(sequence.State, RevertableSequenceState.RevertFailed);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "PerformOne()",
                "PerformTwo()",
                "PerformThree()",
                "PerformFiveItem(111,index=0,last=F)",
                "PerformFiveItem(222,index=1,last=T)",
                "PerformSixItem(AAA,index=0,last=F)",
                "THROWING-FROM:PerformSixItem(BBB,index=1,last=T)",
                "RevertFiveItem(222,index=1,last=T)",
                "THROWING-FROM:RevertFiveItem(111,index=0,last=F)",
                "THROWING-FROM:RevertFour()",
                "RevertTwo()",
                "RevertOne()",
            });

            Assert.True(exception.InnerExceptions.All(e => e is TestSequenceException), "Exception type");
            Assert.Equal(exception.InnerExceptions.Select(e => e.Message), new[] {
                "PerformSixItem(BBB,index=1,last=T)", "RevertFiveItem(111,index=0,last=F)", "RevertFour()"
            });
        }
        public void CollectionSteps_PerformSucceeded_CollectionItemsPerformed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(fiveItems: new[] { 111, 222, 333 });
            var sequence = new RevertableSequence(codeBehind);

            //-- Act

            sequence.Perform();

            //-- Assert

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Performed));
            Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                "PerformOne()",
                "PerformTwo()",
                "PerformThree()",
                "PerformFiveItem(111,index=0,last=F)",
                "PerformFiveItem(222,index=1,last=F)",
                "PerformFiveItem(333,index=2,last=T)"
            }));
        }
Esempio n. 10
0
        public void CollectionSteps_PerformSucceeded_CollectionItemsPerformed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(fiveItems: new[] { 111, 222, 333 });
            var sequence   = new RevertableSequence(codeBehind);

            //-- Act

            sequence.Perform();

            //-- Assert

            Assert.Equal(sequence.State, RevertableSequenceState.Performed);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "PerformOne()",
                "PerformTwo()",
                "PerformThree()",
                "PerformFiveItem(111,index=0,last=F)",
                "PerformFiveItem(222,index=1,last=F)",
                "PerformFiveItem(333,index=2,last=T)"
            });
        }
Esempio n. 11
0
        public void OnceSteps_PerformFailed_Reverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind()
            {
                ThrowFromPerformThree = true
            };
            var sequence = new RevertableSequence(codeBehind);

            //-- Act

            var exception = Assert.Throws <TestSequenceException>(() => {
                sequence.Perform();
            });

            //-- Assert

            Assert.Equal(exception.Message, "PerformThree()");
            Assert.Equal(sequence.State, RevertableSequenceState.Reverted);
            Assert.Equal(codeBehind.TakeLog(), new[] {
                "PerformOne()", "PerformTwo()", "THROWING-FROM:PerformThree()", "RevertTwo()", "RevertOne()"
            });
        }
        public void CollectionSteps_PerformFailed_PerformedItemsReverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(fiveItems: new[] { 111, 222, 333 });
            var sequence = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformFiveItemIndex = 2;

            //-- Act

            try
            {
                sequence.Perform();
            }
            catch ( TestSequenceException e )
            {
                //-- Assert

                Assert.That(e.Message, Is.EqualTo("PerformFiveItem(333,index=2,last=T)"));
                Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
                Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                    "PerformOne()",
                    "PerformTwo()",
                    "PerformThree()",
                    "PerformFiveItem(111,index=0,last=F)",
                    "PerformFiveItem(222,index=1,last=F)",
                    "THROWING-FROM:PerformFiveItem(333,index=2,last=T)",
                    "RevertFiveItem(222,index=1,last=F)",
                    "RevertFiveItem(111,index=0,last=F)",
                    "RevertFour()",
                    "RevertTwo()",
                    "RevertOne()"
                }));
            }
        }
        public void OnceSteps_Revert_ReverseOrder()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind();
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();

            //-- Act

            var log1 = codeBehind.TakeLog();

            sequence.Revert();

            var log2 = codeBehind.TakeLog();

            //-- Assert

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
            Assert.That(log1, Is.EqualTo(new[] {
                "PerformOne()", "PerformTwo()", "PerformThree()"
            }));
            Assert.That(log2, Is.EqualTo(new[] {
                "RevertFour()", "RevertTwo()", "RevertOne()"
            }));
        }
        public void OnceSteps_RevertFailed_RetryRevertAndSucceed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind() {
                ThrowFromRevertFour = true,
                ThrowFromRevertTwo = true
            };
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();

            try
            {
                sequence.Revert();
            }
            catch ( AggregateException )
            {
            }

            codeBehind.TakeLog();

            codeBehind.ThrowFromRevertFour = false;
            codeBehind.ThrowFromRevertTwo = false;

            //-- Act

            sequence.Revert();

            //-- Assert

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
            Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                "RevertFour()", "RevertTwo()"
            }));
        }
        public void OnceSteps_RevertFailed_AggregateExceptionThrown()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind() {
                ThrowFromRevertFour = true,
                ThrowFromRevertTwo = true
            };
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();
            codeBehind.TakeLog();

            //-- Act

            try
            {
                sequence.Revert();
            }
            catch ( AggregateException aggregate )
            {
                //-- Assert

                Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.RevertFailed));
                Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                    "THROWING-FROM:RevertFour()", "THROWING-FROM:RevertTwo()", "RevertOne()"
                }));

                Assert.That(aggregate.InnerExceptions.All(e => e is TestSequenceException), "Exception type");
                Assert.That(aggregate.InnerExceptions.Select(e => e.Message), Is.EqualTo(new[] {
                    "RevertFour()", "RevertTwo()"
                }));
            }
        }
        public void OnceSteps_PerformSucceeded_StatePerformed()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind();
            var sequence = new RevertableSequence(codeBehind);

            //-- Act

            sequence.Perform();

            //-- Assert

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Performed));
            Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                "PerformOne()", "PerformTwo()", "PerformThree()"
            }));
        }
        public void OnceSteps_PerformFailed_Reverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind() {
                ThrowFromPerformThree = true
            };
            var sequence = new RevertableSequence(codeBehind);

            //-- Act

            try
            {
                sequence.Perform();
            }
            catch ( TestSequenceException )
            {
                //-- Assert

                Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
                Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                    "PerformOne()", "PerformTwo()", "THROWING-FROM:PerformThree()", "RevertTwo()", "RevertOne()"
                }));

                throw;
            }
        }
        public void MultipleCollectionSteps_RevertSucceeded_AllItemsReverted()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            sequence.Perform();
            codeBehind.TakeLog();

            //-- Act

            sequence.Revert();

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
            Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                "RevertSevenItem(Sunday,index=1,last=T)",
                "RevertSevenItem(Friday,index=0,last=F)",
                "RevertFiveItem(222,index=1,last=T)",
                "RevertFiveItem(111,index=0,last=F)",
                "RevertFour()",
                "RevertTwo()",
                "RevertOne()",
            }));
        }
        public void MultipleCollectionSteps_PerformFailedThenRevertFailed_AllErrorsInAggregateException()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformSixItemIndex = 1;
            codeBehind.ThrowFromRevertFiveItemIndex = 0;
            codeBehind.ThrowFromRevertFour = true;

            //-- Act

            try
            {
                sequence.Perform();
            }
            catch ( AggregateException aggregate )
            {

                Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.RevertFailed));
                Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                    "PerformOne()",
                    "PerformTwo()",
                    "PerformThree()",
                    "PerformFiveItem(111,index=0,last=F)",
                    "PerformFiveItem(222,index=1,last=T)",
                    "PerformSixItem(AAA,index=0,last=F)",
                    "THROWING-FROM:PerformSixItem(BBB,index=1,last=T)",
                    "RevertFiveItem(222,index=1,last=T)",
                    "THROWING-FROM:RevertFiveItem(111,index=0,last=F)",
                    "THROWING-FROM:RevertFour()",
                    "RevertTwo()",
                    "RevertOne()",
                }));

                Assert.That(aggregate.InnerExceptions.All(e => e is TestSequenceException), "Exception type");
                Assert.That(aggregate.InnerExceptions.Select(e => e.Message), Is.EqualTo(new[] {
                    "PerformSixItem(BBB,index=1,last=T)", "RevertFiveItem(111,index=0,last=F)", "RevertFour()"
                }));
            }
        }
        public void MultipleCollectionSteps_RevertFailed_RetryAndRevertAll()
        {
            //-- Arrange

            var codeBehind = new TestCodeBehind(
                fiveItems: new[] { 111, 222 },
                sixItems: new[] { "AAA", "BBB" },
                sevenItems: new[] { DayOfWeek.Friday, DayOfWeek.Sunday });
            var sequence = new RevertableSequence(codeBehind);

            codeBehind.ThrowFromPerformSixItemIndex = 1;
            codeBehind.ThrowFromRevertFiveItemIndex = 0;
            codeBehind.ThrowFromRevertFour = true;

            try
            {
                sequence.Perform();
            }
            catch ( AggregateException )
            {
            }

            codeBehind.ThrowFromRevertFiveItemIndex = null;
            codeBehind.ThrowFromRevertFour = false;
            codeBehind.TakeLog();

            //-- Act

            sequence.Revert();

            //-- Assert

            Assert.That(sequence.State, Is.EqualTo(RevertableSequenceState.Reverted));
            Assert.That(codeBehind.TakeLog(), Is.EqualTo(new[] {
                "RevertFiveItem(111,index=0,last=F)",
                "RevertFour()",
            }));
        }