/// <summary> /// It handles a <see cref="PayLoadCreatedEvent"/> creating a <see cref="AnalyzeDiffCommand"/> from that sending it to the bus /// </summary> /// <param name="notification"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task Handle(PayLoadCreatedEvent notification, CancellationToken cancellationToken) { /* Whenever a PayLoadCreatedEvent occurs, this event handler sends a command to the * bus that reaches the AnalyzeDiffCommandHandler. I created this class to decouple the PayLoadCreateCommand from the AnalyzeDiffCommand */ var command = new AnalyzeDiffCommand(notification.CorrelationId); return(_bus.SendCommand(command)); }
public async void Handle_WhenRightPayLoadIsNotFound_ShouldReturnFalse(AnalyzeDiffCommand command, byte[] content) { var payLoads = new List <PayLoad> { new PayLoad(command.CorrelationId, content, SideEnum.Left) }; _payLoadRepository.GetByCorrelationId(command.CorrelationId).Returns(payLoads); var result = await _sut.Handle(command, new CancellationToken()); result.Should().BeFalse(); }
public async void Handle_WhenPayLoadIsFound_ShouldReturnTrue(AnalyzeDiffCommand command, byte[] leftContent, byte[] rightContent, NotOfEqualSizeDiff diff) { var payLoads = new List <PayLoad> { new PayLoad(command.CorrelationId, leftContent, SideEnum.Left), new PayLoad(command.CorrelationId, rightContent, SideEnum.Right) }; _payLoadRepository.GetByCorrelationId(command.CorrelationId).Returns(payLoads); _diffEngine.ProcessDiff(command.CorrelationId, leftContent, rightContent).Returns(diff); var result = await _sut.Handle(command, new CancellationToken()); result.Should().BeTrue(); }
public async void Handle_WhenPayLoadIsFound_ShouldProcessDiffAndSaveItInTheCache(AnalyzeDiffCommand command, byte[] leftContent, byte[] rightContent, NotOfEqualSizeDiff diff) { var payLoads = new List <PayLoad> { new PayLoad(command.CorrelationId, leftContent, SideEnum.Left), new PayLoad(command.CorrelationId, rightContent, SideEnum.Right) }; _payLoadRepository.GetByCorrelationId(command.CorrelationId).Returns(payLoads); _diffEngine.ProcessDiff(command.CorrelationId, leftContent, rightContent).Returns(diff); _ = await _sut.Handle(command, new CancellationToken()); await _cache.Received(1).SetAsync($"diff_{command.CorrelationId}", diff, 86400); }
public void Validate_WhenCorrelationIdIsEmpty_IsValidShouldBeFalse(AnalyzeDiffCommandValidation sut) { var command = new AnalyzeDiffCommand(string.Empty); sut.Validate(command).IsValid.Should().BeFalse(); }
public void Validate_WhenCorrelationIdIsNull_IsValidShouldBeFalse(AnalyzeDiffCommandValidation sut) { var command = new AnalyzeDiffCommand(null); sut.Validate(command).IsValid.Should().BeFalse(); }
public void Validate_WhenCorrelationIdIsFilled_IsValidShouldBeTrue(AnalyzeDiffCommandValidation sut, AnalyzeDiffCommand command) { sut.Validate(command).IsValid.Should().BeTrue(); }