private async void GetAllVehicles_ReturnsData() { // arrange var locationId = IdentifierHelper.LocationId; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetVehicles(It.IsAny <Guid>())) .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", VehicleModelHelper.GetMany() } }); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAllVehicles(locationId); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public async void GetAllVehicles_WithBadId() { // arrange var targetId = Guid.Empty; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetVehicles(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, TestVehicles())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAllVehicles(targetId); var badRequestResult = result as BadRequestObjectResult; // assert Assert.NotNull(badRequestResult); }