public void ProperlyHandleUnknownCommands() { DomainResult result = null; _resultPublisherMock.Setup(x => x.Publish(It.IsAny <DomainResult>())).Callback <DomainResult>(r => result = r); var testCommand = DomainMessageTranslator.TranslateCommand(new TestDomainEvent3(Guid.NewGuid()), new CommandType("TestDomainEvent3")); Assert.IsTrue(_eventHandler.Dispatch(testCommand)); Assert.IsFalse(_handleCommandInstance.Handled.Any()); Assert.AreEqual(ResultCode.OK, result.ResultCode); }
public bool Dispatch(ICommand message) { _logger.InfoFormat("Dispatching message {0}", message.Type.Value); InitCache(); HandlerStore handlerStore; _handlersCache.TryGetValue(message.Type.Value, out handlerStore); if (handlerStore != null) { var cqrsMessage = DomainMessageTranslator.TranslateCommand(message, handlerStore.CqrsMessageType); if (cqrsMessage is IDomainCommand) { _logger.DebugFormat("Handling command"); HandleCommand(handlerStore, cqrsMessage as IDomainCommand); } else { _logger.DebugFormat("Handling event"); HandleMessage(handlerStore, cqrsMessage); } } else { var cqrsMessage = DomainMessageTranslator.TranslateCommand(message, typeof(GenericDomainMessage)); _logger.DebugFormat("No known handler for {0}, returning", message.Type.Value); var cqrsResult = new DomainResult { Id = message.Id, TrackingId = cqrsMessage.TrackingId, ResultCode = ResultCode.OK }; _resultPublisher.Publish(cqrsResult); } return(true); }