Exemplo 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>>()));
        }
        public void ShouldResolve_Commands_Successfully()
        {
            var containerBuilder = new ContainerBuilder();
            containerBuilder.RegisterType(typeof(CommandTest)).AsSelf();
            ContextScopeProvider.RegisterTypes(containerBuilder);

            var httpContextMoq = new HttpContextMoq();
            var accessor = new Mock<IHttpContextAccessor>();
            accessor
                .Setup(a => a.GetCurrent())
                .Returns(() => httpContextMoq.HttpContextBase);

            var provider = new PerWebRequestContainerProvider(accessor.Object);
            var resolver = new DefaultCommandResolver(provider);

            var commandContext = new CommandContextTest();
            var command = resolver.ResolveCommand<CommandTest>(commandContext);
            Assert.IsNotNull(command);
            Assert.AreEqual(command.Context, commandContext);
        }
Exemplo n.º 3
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"});
            });
        }
Exemplo n.º 4
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> >()));
        }
Exemplo n.º 5
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"
                });
            });
        }
Exemplo n.º 6
0
        public void ShouldResolve_Commands_Successfully()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType(typeof(CommandTest)).AsSelf();
            ContextScopeProvider.RegisterTypes(containerBuilder);

            var httpContextMoq = new HttpContextMoq();
            var accessor       = new Mock <IHttpContextAccessor>();

            accessor
            .Setup(a => a.GetCurrent())
            .Returns(() => httpContextMoq.HttpContextBase);

            var provider = new PerWebRequestContainerProvider(accessor.Object);
            var resolver = new DefaultCommandResolver(provider);

            var commandContext = new CommandContextTest();
            var command        = resolver.ResolveCommand <CommandTest>(commandContext);

            Assert.IsNotNull(command);
            Assert.AreEqual(command.Context, commandContext);
        }