Esempio n. 1
0
        public void ExecuteSuccessfulActionCommandTest()
        {
            CommandExecutionContext context = new CommandExecutionContext();

            CommandResult result = context.Execute("TestCommand", () => { }).Result;

            result.IsSuccessful.Should().BeTrue();
            result.Exception.Should().BeNull();

            result.Events.Should().HaveCount(1);
            result.Events.Single().ShouldBeEquivalentTo(CommandExecutionEventType.Success);
        }
        public void ShouldCorrectlyExecuteTheCommands()
        {
            //arrange
            var obj = new ValueObject() { Number = 1 };
            var context = new CommandExecutionContext(handler);

            //act
            context.Execute(new AddOneCommand(obj));

            //assert
            Assert.AreEqual(2, obj.Number);
        }
Esempio n. 3
0
        public void ExecuteSuccessfulFunctionCommandTest()
        {
            CommandExecutionContext context  = new CommandExecutionContext();
            const string            response = "test";

            CommandResult <string> result = context.Execute("TestCommand", () => response).Result;

            result.IsSuccessful.Should().BeTrue();
            result.Response.ShouldBeEquivalentTo(response);
            result.Exception.Should().BeNull();

            result.Events.Should().HaveCount(1);
            result.Events.Single().ShouldBeEquivalentTo(CommandExecutionEventType.Success);
        }
Esempio n. 4
0
        public void ShouldCorrectlyExecuteTheCommands()
        {
            //arrange
            var obj = new ValueObject()
            {
                Number = 1
            };
            var context = new CommandExecutionContext(handler);

            //act
            context.Execute(new AddOneCommand(obj));

            //assert
            Assert.AreEqual(2, obj.Number);
        }
        public void ShouldProperlyRemoveCommandsBoundToAGivenExecutionContext()
        {
            //arrange
            var cmd1 = new AddOneCommand(new ValueObject() { Number = 1 });
            var cmd2 = new AddOneCommand(new ValueObject() { Number = 1 });
            var context1 = new CommandExecutionContext(handler);
            var context2 = new CommandExecutionContext(handler);

            //act
            context1.Execute(cmd1);
            context2.Execute(cmd2);

            //assert
            Assert.AreEqual(2, stack.UndoItems().Count(), "there should be 2 undo entries");
            context1.Dispose();
            Assert.AreEqual(1, stack.UndoItems().Count(), "there should be 1 undo entry left");
            Assert.AreEqual(cmd2, stack.UndoItems().ElementAt(0), "should be the correct command obj");
        }
Esempio n. 6
0
        public void ExceptionThrownInFunctionCommandTest()
        {
            CommandExecutionContext context = new CommandExecutionContext();

            CommandResult <string> result =
                context.Execute(
                    "TestCommand",
                    () =>
            {
                object obj = null;
                return(obj.ToString());
            })
                .Result;

            result.IsSuccessful.Should().BeFalse();
            result.Exception.Should().BeOfType <CommandExecutionException>();

            result.Events.Should().HaveCount(1);
            result.Events.Single().ShouldBeEquivalentTo(CommandExecutionEventType.CommandException);
        }
Esempio n. 7
0
        public void ShouldProperlyRemoveCommandsBoundToAGivenExecutionContext()
        {
            //arrange
            var cmd1 = new AddOneCommand(new ValueObject()
            {
                Number = 1
            });
            var cmd2 = new AddOneCommand(new ValueObject()
            {
                Number = 1
            });
            var context1 = new CommandExecutionContext(handler);
            var context2 = new CommandExecutionContext(handler);

            //act
            context1.Execute(cmd1);
            context2.Execute(cmd2);

            //assert
            Assert.AreEqual(2, stack.UndoItems().Count(), "there should be 2 undo entries");
            context1.Dispose();
            Assert.AreEqual(1, stack.UndoItems().Count(), "there should be 1 undo entry left");
            Assert.AreEqual(cmd2, stack.UndoItems().ElementAt(0), "should be the correct command obj");
        }
Esempio n. 8
0
        private Task <CommandResult <string> > Execute(BaseCommand <string> command)
        {
            CommandExecutionContext context = new CommandExecutionContext();

            return(context.Execute(command));
        }