/// <summary> /// Asynchronously sends command to handler /// </summary> /// <param name="sensorLogModel">The sensor log model to validate</param> /// <returns>The result of the command</returns> private Task <CommandResult <ValidateSensorLogModel> > SendValidateSensorRecordCommandAsync(SensorLogModel sensorLogModel) { ValidateSensorRecordCommand command = new ValidateSensorRecordCommand { SensorLogModel = sensorLogModel }; return(_mediator.Send(command));; }
public async Task Handle_Null_Or_Empty_Result_Should_Produce_Validation_Error() { // Arrange string expectedMessage = "Validate Sensor Record produced an invalid result."; CommandResult <string> expectedResult = new CommandResult <string> { Result = null, CommandResultType = CommandResultType.Error }; ValidateSensorRecordCommand command = new ValidateSensorRecordCommand { SensorLogModel = new SensorLogModel() }; _repository .Setup(r => r.ValidateSensorLogRecords(It.IsAny <SensorLogModel>())) .Returns((ValidateSensorLogModel)null); // Act CommandResult <ValidateSensorLogModel> actual = await _handler.Handle(command); // Assert using (new AssertionScope()) { actual .Should() .NotBeNull() .And .BeEquivalentTo(expectedResult); _logger.Invocations.Count .Should() .Be(1); _logger.Invocations[0].Arguments[0] .Should() .Be(LogLevel.Error); _logger .Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.Is <It.IsAnyType>((x, t) => string.Equals(x.ToString(), expectedMessage)), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once()); } }
public async Task Handle_Null_SensorLogModel_Should_Produce_Validation_Error() { // Arrange string expectedMessage = "Validate Sensor Record produced errors: 'Sensor Log Model' must not be empty."; CommandResult <string> expectedResult = new CommandResult <string> { Result = null, CommandResultType = CommandResultType.InvalidInput }; ValidateSensorRecordCommand command = new ValidateSensorRecordCommand { SensorLogModel = null }; // Act CommandResult <ValidateSensorLogModel> actual = await _handler.Handle(command); // Assert using (new AssertionScope()) { actual .Should() .NotBeNull() .And .BeEquivalentTo(expectedResult); _logger.Invocations.Count .Should() .Be(1); _logger.Invocations[0].Arguments[0] .Should() .Be(LogLevel.Error); _logger .Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.Is <It.IsAnyType>((x, t) => string.Equals(x.ToString(), expectedMessage)), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once()); } }