private static object[] ConstructEventWithSource <T>(SourceSystem sourceSystem) where T : IMessage { var payload = PayloadHelpers.Construct <T>(); PayloadHelpers.SetField(payload, "source_", sourceSystem); // the name of field is found with decompiler return(new object[] { payload }); }
public void Should_not_process_payload_if_it_is_disabled() { var eventValidator = new Mock <IEventValidator>(); eventValidator.Setup(m => m.IsEnabled(It.IsAny <PriceBandUpdated>())).Returns(false); var handler = new PriceBandEventHandler(Mock.Of <IDatabaseCommands>(), eventValidator.Object, Mock.Of <IMessagingLogger>(), Mock.Of <IConfiguration>()); var priceBandUpdated = PayloadHelpers.Construct <PriceBandUpdated>(); var result = handler.HandleAsync(priceBandUpdated, Guid.Empty.ToString()).Result; Assert.Equal(MessageHandlerResult.Success, result); eventValidator.Verify(m => m.IsValidPayload(It.IsAny <PriceBandUpdated>()), Times.Never); }
public void Should_register_error_with_model() { // arrange var payload = PayloadHelpers.Construct <AccountUpdated>(); var dbCommands = new Mock <IDatabaseCommands>(); var validator = new Mock <IEventValidator>(); validator.Setup(m => m.IsAllowedEvent(It.IsAny <object>())).Returns(true); validator.Setup(m => m.IsValidPayload(It.IsAny <object>())).Returns(false); var messagingLogger = new Mock <IMessagingLogger>(); var handler = new AccountUpdatedEventHandler(dbCommands.Object, validator.Object, messagingLogger.Object); // act var result = handler.HandleAsync(payload, "1").Result; // assert Assert.Equal(MessageHandlerResult.Fatal, result); messagingLogger.Verify(m => m.ReceivedInvalidModel(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>()), Times.Once); }