public void HotelOrder_Test() { //Arrange bool orderSucessful = false; var hotelsDbMock = new Mock <IRepository <Hotel> >(); hotelsDbMock.Setup(a => a.GetByID(1)).Returns(new Hotel { Id = 1 }); var hotelOrdMock = new Mock <IRepository <HotelBooking> >(); hotelOrdMock.Setup(a => a.Insert(It.IsAny <HotelBooking>())).Callback(() => orderSucessful = true); var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(uow => uow.Hotels).Returns(hotelsDbMock.Object); uowMock.Setup(uow => uow.HotelOrders).Returns(hotelOrdMock.Object); var entrance = new DateTime(2018, 6, 2); var eviction = new DateTime(2018, 6, 12); var orderService = new OtherOrderService(uowMock.Object); var hotelOrderDto = new HotelOrderDTO { HotelId = 1, EntranceDate = entrance, EvictionDate = eviction }; //Act orderService.OrderHotel(hotelOrderDto); //Assert Assert.IsTrue(orderSucessful); Assert.Throws <ValidationException>(() => orderService.OrderHotel(new HotelOrderDTO { HotelId = 2 })); }
public void GetCalculatePriceWrong() { var hotelsDbMock = new Mock <IRepository <Hotel> >(); hotelsDbMock.Setup(a => a.GetByID(1)).Returns(new Hotel { Id = 1 }); var eviction = new DateTime(2018, 6, 2); var entrance = new DateTime(2018, 6, 12); var hotelOrdMock = new Mock <IRepository <HotelBooking> >(); var hotelDto = new HotelOrderDTO { HotelId = 1, EntranceDate = entrance, EvictionDate = eviction }; var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(uow => uow.Hotels).Returns(hotelsDbMock.Object); uowMock.Setup(uow => uow.HotelOrders).Returns(hotelOrdMock.Object); var orderService = new OtherOrderService(uowMock.Object); Assert.Throws <ValidationException>(() => orderService.OrderHotel(hotelDto)); }