Пример #1
0
        public async Task Hanlde_Should_Return_Valid_Result_Test()
        {
            // Arrange
            string         path          = @"C:\temp\file.txt";
            SensorLogModel expectedModel = new SensorLogModel();
            CommandResult <SensorLogModel> expectedResult = new CommandResult <SensorLogModel>
            {
                Result            = expectedModel,
                CommandResultType = CommandResultType.Success
            };
            ParseSensorRecordCommand command = new ParseSensorRecordCommand
            {
                Path = path
            };

            _fileSystem
            .Setup(f => f.File.Exists(It.IsAny <string>()))
            .Returns(true);

            _repository
            .Setup(r => r.ParseInputLogFileAsync(It.IsAny <string>()))
            .ReturnsAsync(expectedModel);

            // Act
            CommandResult <SensorLogModel> actual = await _handler.Handle(command);

            // Assert
            actual
            .Should()
            .NotBeNull()
            .And
            .BeEquivalentTo(expectedResult);
        }
        /// <summary>
        /// Asynchronously sends command to handler
        /// </summary>
        /// <param name="path">The path to the sensor log record to be parsed</param>
        /// <returns>The result of the command</returns>
        private Task <CommandResult <SensorLogModel> > SendSensorLogCommandAsync(string path)
        {
            ParseSensorRecordCommand command = new ParseSensorRecordCommand
            {
                Path = path
            };

            return(_mediator.Send(command));
        }
Пример #3
0
        public async Task Handle_Null_SensorLogModel_Result_Test()
        {
            // Arrange
            string path            = @"C:\temp\file.txt";
            string expectedMessage = $"Parse Sensor Record Command with Path: {path} produced an invalid result.";
            CommandResult <SensorLogModel> expectedResult = new CommandResult <SensorLogModel>
            {
                Result            = null,
                CommandResultType = CommandResultType.Error
            };
            ParseSensorRecordCommand command = new ParseSensorRecordCommand
            {
                Path = path
            };

            _fileSystem
            .Setup(f => f.File.Exists(It.IsAny <string>()))
            .Returns(true);

            _repository
            .Setup(r => r.ParseInputLogFileAsync(It.IsAny <string>()))
            .ReturnsAsync((SensorLogModel)null);

            // Act
            CommandResult <SensorLogModel> 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());
            }
        }
Пример #4
0
        public async Task Handle_NullOrWhitespace_Path_Test()
        {
            // Arrange
            string expectedMessage = "Parse Sensor Record Command with Path: (null) produced errors on validation: Path cannot be null or whitespace.";
            CommandResult <SensorLogModel> expectedResult = new CommandResult <SensorLogModel>
            {
                Result            = null,
                CommandResultType = CommandResultType.InvalidInput
            };
            ParseSensorRecordCommand command = new ParseSensorRecordCommand
            {
                Path = null
            };

            // Act
            CommandResult <SensorLogModel> 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());
            }
        }