public async void GetAll_ReturnsData() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var vehicleServiceMoq = new Mock <IVehicleService>(); vehicleServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, TestVehicles())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.ConvertAndMap <IEnumerable <VehicleModel>, IEnumerable <Vehicle> >(It.IsAny <string>(), It.IsAny <IEnumerable <Vehicle> >())) .Returns(new Dictionary <string, object> { { "vehicles", TestVehicles() } }); var sut = new VehiclesController(vehicleServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public async void GetAll_WhenNotFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var vehicleServiceMoq = new Mock <IVehicleService>(); vehicleServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.NotFound)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new VehiclesController(vehicleServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var notFoundResult = result as NotFoundResult; // assert Assert.NotNull(notFoundResult); }
public async Task GetAll_Sucess() { var mock = new Mock <IVehicleService>(); VehiclesController controller = new VehiclesController(mock.Object); var result = await controller.GetAll(); mock.Verify(service => service.GetAllAsync(), Times.AtLeastOnce()); }
public void Getall_WhenCalled_ReturnsOkResult() { // Arrange filterVehicle = new FilterVehicle() { CustomerID = -1, IsConnected = -1 }; // Act var okResult = vehiclesController.GetAll(filterVehicle); // Assert Assert.IsType <OkObjectResult>(okResult); }
public async Task GetAll_Sucess() { var mockRepository = new Mock <IVehicleRepository>(); mockRepository.Setup(repository => repository.GetAllAsync()).Returns(Task.FromResult(new List <Vehicle>())); var mockUnit = new Mock <IUnitOfWork>(); VehicleService VehicleService = new VehicleService(mockUnit.Object, mockRepository.Object); VehiclesController controller = new VehiclesController(VehicleService); var result = await controller.GetAll(); mockRepository.Verify(repository => repository.GetAllAsync(), Times.AtLeastOnce()); Assert.IsInstanceOfType(result, typeof(ActionResult <IEnumerable <VehicleDto> >)); }