Beispiel #1
0
        public ICommandResults Process <TCommand>(TCommand command) where TCommand : ICommand
        {
            Validator.ValidateObject(command, new ValidationContext(command, null, null));

            var results = new CommandResults();

            var handlers = ServiceLocator.Current.GetAllInstances <ICommandHandler <TCommand> >();

            if (handlers == null || !handlers.Any())
            {
                throw new CommandHandlerNotFoundException(typeof(TCommand));
            }

            foreach (var result in handlers.Select(handler => handler.Handle(command)))
            {
                results.AddResult(result);
            }

            return(results);
        }
        public void ChangeCategory_With_ID_Not_Found()
        {
            //Arrange
            var routeData = new RouteData();
            var httpContext = MockRepository.GenerateStub<HttpContextBase>();
            var controllerContext = MockRepository.GenerateStub<ControllerContext>(httpContext, routeData, _controller);
            _controller.ControllerContext = controllerContext;
            var form = new FormCollection { { "category", "3" }, { "1", "true,false" }, { "2", "false" }, { "3", "true,false" } };
            _controller.ValueProvider = form.ToValueProvider();
            var results = new CommandResults();
            results.AddResult(new MassCategoryChangeResult(false));
            _commandProcessor.Expect(x => x.Process(Arg<MassCategoryChangeCommand>.Matches(y =>
                y.CategoryId == 3 && y.ProductIds.Count() == 2))).Return(results);

            //Act
            var result = _controller.ChangeCategory(form) as ContentResult;

            //Assert
            Assert.AreEqual("One or more categories failed to change!", result.Content);
            Assert.AreEqual("text/html", result.ContentType);
            _commandProcessor.VerifyAllExpectations();
        }