示例#1
0
        public async Task VehicleController_GetVehicleDetails_WhenVehicleDoesNotExists_ShouldReturnNotFound()
        {
            // Arrange
            var vinReference = StringHelper.RandomString(6);

            _mockVehicleRepository
            .Setup(m => m.GetByVinAsync(It.IsAny <string>()))
            .ReturnsAsync(default(Vehicle))
            .Verifiable();

            // Act
            var vehiclesController = new VehiclesController(_mockVehicleRepository.Object, _mockLogger.Object);
            var result             = await vehiclesController.GetVehicleDetails(vinReference);

            // Assert
            Assert.IsNotNull(result as NotFoundObjectResult);
            _mockVehicleRepository.Verify(m => m.GetByVinAsync(It.IsAny <string>()), Times.Once);
        }
示例#2
0
        public async Task VehicleController_GetVehicleDetails_WhenVehicleExists_ShouldReturnOk()
        {
            // Arrange
            var vinReference = StringHelper.RandomString(6);

            _mockVehicleRepository
            .Setup(m => m.GetByVinAsync(It.IsAny <string>()))
            .ReturnsAsync(TestDataHelper.GetVehicle(vinReference))
            .Verifiable();

            // Act
            var vehiclesController = new VehiclesController(_mockVehicleRepository.Object, _mockLogger.Object);
            var result             = await vehiclesController.GetVehicleDetails(vinReference);

            var objResult = result as OkObjectResult;

            // Assert
            Assert.IsNotNull(objResult);
            var vehicleResponse = objResult.Value as VehicleModel;

            Assert.AreEqual(vinReference, vehicleResponse.VehicleNumber);
            _mockVehicleRepository.Verify(m => m.GetByVinAsync(It.IsAny <string>()), Times.Once);
        }