public void The_message_processor_should_process_this_message() { //Application Startup code var configuration = new CommandEngineConfiguration(); configuration.Initialize(typeof(MessageProcessorTester).Assembly); var locator = S <IServiceLocator>(); locator.Stub(ioC => ioC.GetAllInstances(null)).IgnoreArguments().Return(new[] { new TestMessageCommandHandler() }); ServiceLocator.SetLocatorProvider(() => locator); //request startup code. var invoker = new CommandInvoker(new ValidationEngine(new ValidationRuleFactory()), new CommandFactory()); var unitOfWork = S <IUnitOfWork>(); var mapper = S <IMessageMapper>(); mapper.Stub(messageMapper => messageMapper.MapUiMessageToCommandMessage(null, null, null)).IgnoreArguments().Return( new TestCommandMessage()); var processor = new MessageProcessor(mapper, invoker, unitOfWork, configuration); ExecutionResult result = processor.Process(new TestViewModel { Message = "foo" }, typeof(TestViewModel)); Assert.True(result.Successful); Assert.AreEqual(0, result.Messages.Count()); Assert.NotNull(result.ReturnItems.Get <TestCommandMessage>()); }
public IMessageProcessor Create(IUnitOfWork unitOfWork, IMessageMapper mappingEngine, CommandEngineConfiguration configuration) { return(new MessageProcessor(mappingEngine, new CommandInvoker(new ValidationEngine(new ValidationRuleFactory()), new CommandFactory()), unitOfWork, configuration)); }
public MessageProcessor(IMessageMapper mappingEngine, ICommandInvoker commandInvoker, IUnitOfWork unitOfWork, CommandEngineConfiguration configuration ) { _mappingEngine = mappingEngine; _commandInvoker = commandInvoker; _unitOfWork = unitOfWork; _configuration = configuration; }
public void Initialize(Assembly assembly, IMessageMapper messageMapper) { if (_mappingEngine == null) { lock (_lock) { if (_configuration == null) { Configuration = new CommandEngineConfiguration(); Configuration.Initialize(assembly); _mappingEngine = messageMapper; } } } }
private static void ConventionConfiguration(CommandEngineConfiguration configuration, Type inputType, Type messageType) { var inputTypes = inputType.Assembly.GetTypes() .Where(t => TypeIsAnInputModel(t, inputType)).ToArray(); var messageTypes = messageType.Assembly.GetTypes() .Where(t => TypeIsACommandMessage(t, messageType)); foreach (Type input in inputTypes) { if (!configuration.MessageConfigurations.ContainsKey(input)) { Type actualMessageType = messageTypes.FirstOrDefault(type => InputToCommandMessage(type, input)); if (actualMessageType != null) { configuration.MessageConfigurations.Add(input, new ConventionMessageConfiguration(actualMessageType)); } } } }
public IMessageProcessor Create(IUnitOfWork unitOfWork, IMessageMapper mappingEngine, CommandEngineConfiguration configuration) { return(new FakeProcessor()); }