public void GetAvailableCars() { // Arrange var inventoryService = new Mock <IInventoryService>(); var rentalService = new Mock <IRentalService>(); var reservationApiController = new ReservationApiController(inventoryService.Object, rentalService.Object); Car[] cars = { new Car { CarId = 1 }, new Car{ CarId = 2 } }; inventoryService.Setup(x => x.GetAvailableCars(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(cars); // Act HttpResponseMessage response = reservationApiController.GetAvailableCars(base._request, DateTime.Now, DateTime.Now.AddDays(1)); Car[] data = base._GetResponseData <Car[]>(response); // Assert Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); Assert.AreSame(cars, data); }
public void GetAvailableCars() { Mock <IInventoryService> mockInventoryService = new Mock <IInventoryService>(); Mock <IRentalService> mockRentalService = new Mock <IRentalService>(); Car[] cars = { new Car() { CarId = 1 }, new Car() { CarId = 2 } }; mockInventoryService.Setup(obj => obj.GetAvailableCars(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(cars); ReservationApiController controller = new ReservationApiController(mockInventoryService.Object, mockRentalService.Object); HttpResponseMessage response = controller.GetAvailableCars(_Request, DateTime.Now, DateTime.Now.AddDays(1)); Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); Car[] data = GetResponseData <Car[]>(response); Assert.IsTrue(data == cars); }