コード例 #1
0
ファイル: CommandChainTest.cs プロジェクト: s4xack/Oop
        public void Execute_ShouldCompleteAction()
        {
            var result   = 0;
            var expected = 10;
            var command  = new Command(() => result += expected / 2, () => result -= expected / 2);

            CommandChain.StartWith(command).Then(command).Execute();

            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #2
0
        internal WalletTransferTransaction(Decimal amount, AbstractWallet sourceWallet, AbstractWallet destinationWallet)
            : base
            (
                amount,
                CommandChain
                .StartWith(new ReduceBalanceCommand(sourceWallet, amount))
                .Then(new IncreaseBalanceCommand(destinationWallet, amount))
            )

        {
        }
コード例 #3
0
ファイル: CommandChainTest.cs プロジェクト: s4xack/Oop
        public void Execute_ShouldThrowExceptionAndRevertAction()
        {
            var result     = 0;
            var expected   = result;
            var command    = new Command(() => result += 2, () => result -= 2);
            var badCommand = new Command(() => throw new InvalidOperationException(), () => throw new InvalidOperationException());

            var chain = CommandChain.StartWith(command).Then(badCommand);

            Assert.Throws <CommandExecutionException>(chain.Execute);
            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #4
0
ファイル: CommandChainTest.cs プロジェクト: s4xack/Oop
        public void Revert_ShouldCompleteRevertAction()
        {
            var result   = 0;
            var expected = result;
            var command  = new Command(() => result += 2, () => result -= 2);

            var chain = CommandChain.StartWith(command).Then(command);

            chain.Execute();
            chain.Revert();

            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #5
0
ファイル: CommandChainTest.cs プロジェクト: s4xack/Oop
        public void ExecuteWithRevertExceptions_ShouldThrowExceptionWithCorrectRevertExceptionsAndRevertAction()
        {
            var result           = 0;
            var expected         = 4;
            var command          = new Command(() => result += 2, () => result -= 2);
            var badRevertCommand = new Command(() => result += 2, () => throw new InvalidOperationException());
            var badCommand       = new Command(() => throw new InvalidOperationException(), () => throw new InvalidOperationException());

            var chain = CommandChain.StartWith(command).Then(badRevertCommand).Then(badRevertCommand).Then(badCommand);

            try
            {
                chain.Execute();
            }
            catch (CommandChainExecutionException exception)
            {
                Assert.That(exception.RevertException.InnerExceptions.Count, Is.EqualTo(2));
            }

            Assert.That(result, Is.EqualTo(expected));
        }