Ejemplo n.º 1
0
        public void Should_resolve_command()
        {
            var mockCommand = new Mock<ICommand>();
            var mockCommandCatalog = new Mock<ICommandCatalog>();
            var mockCommandInvoker = new Mock<ICommandInvoker>();

            mockCommandCatalog.Setup(x => x.GetEnumerator()).Returns(() => new List<ICommand> {
                mockCommand.Object
            }.GetEnumerator());

            mockCommand.Setup(x => x.Match(It.IsAny<IEnumerable<string>>()))
                .Returns(() => new CommandResult());

            var defaultCommandResolver = new DefaultCommandResolver(mockCommandCatalog.Object, mockCommandInvoker.Object);

            defaultCommandResolver.Resolve(new List<string> { "fake" });

            mockCommand.Verify(x => x.Match(It.IsAny<IEnumerable<string>>()));
        }
Ejemplo n.º 2
0
        public void Should_throw_exception_when_no_commands_are_matched()
        {
            var mockCommand = new Mock<ICommand>();
            var mockCommandCatalog = new Mock<ICommandCatalog>();
            var mockCommandInvoker = new Mock<ICommandInvoker>();

            mockCommandCatalog.Setup(x => x.GetEnumerator()).Returns(() => new List<ICommand> {
                mockCommand.Object
            }.GetEnumerator());

            mockCommand.Setup(x => x.Match(It.IsAny<IEnumerable<string>>()))
                .Returns(() => null);

            var defaultCommandResolver = new DefaultCommandResolver(mockCommandCatalog.Object, mockCommandInvoker.Object);

            Assert.Throws<Exception>(() =>
            {
                defaultCommandResolver.Resolve(new List<string> {"fake"});
            });
        }
Ejemplo n.º 3
0
        public void Should_resolve_command()
        {
            var mockCommand        = new Mock <ICommand>();
            var mockCommandCatalog = new Mock <ICommandCatalog>();
            var mockCommandInvoker = new Mock <ICommandInvoker>();

            mockCommandCatalog.Setup(x => x.GetEnumerator()).Returns(() => new List <ICommand> {
                mockCommand.Object
            }.GetEnumerator());

            mockCommand.Setup(x => x.Match(It.IsAny <IEnumerable <string> >()))
            .Returns(() => new CommandResult());

            var defaultCommandResolver = new DefaultCommandResolver(mockCommandCatalog.Object, mockCommandInvoker.Object);

            defaultCommandResolver.Resolve(new List <string> {
                "fake"
            });

            mockCommand.Verify(x => x.Match(It.IsAny <IEnumerable <string> >()));
        }
Ejemplo n.º 4
0
        public void Should_throw_exception_when_no_commands_are_matched()
        {
            var mockCommand        = new Mock <ICommand>();
            var mockCommandCatalog = new Mock <ICommandCatalog>();
            var mockCommandInvoker = new Mock <ICommandInvoker>();

            mockCommandCatalog.Setup(x => x.GetEnumerator()).Returns(() => new List <ICommand> {
                mockCommand.Object
            }.GetEnumerator());

            mockCommand.Setup(x => x.Match(It.IsAny <IEnumerable <string> >()))
            .Returns(() => null);

            var defaultCommandResolver = new DefaultCommandResolver(mockCommandCatalog.Object, mockCommandInvoker.Object);

            Assert.Throws <Exception>(() =>
            {
                defaultCommandResolver.Resolve(new List <string> {
                    "fake"
                });
            });
        }