public void TestBookingControllerBookHotelActionBookHotelInvalidDates(string checkIn, string checkOut) { var mockHotelService = new Mock <IHotelService>(); var applicationDbcontext = new ApplicationDbContext(CreateNewContextOptions()); var mockRoomService = new Mock <IRoomService>(); var store = new Mock <IUserStore <ApplicationUser> >(); var mgr = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null); mgr.Object.UserValidators.Add(new UserValidator <ApplicationUser>()); mgr.Object.PasswordValidators.Add(new PasswordValidator <ApplicationUser>()); var testController = new BookingController(applicationDbcontext, mockHotelService.Object, mockRoomService.Object, mgr.Object); Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => testController.BookHotel(1, checkIn, checkOut, 1, 0)); }
public void TestIfBookingControllerBookHotelActionReturnsTaskIActionResult() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("TestDb") .Options; var mockHotelService = new Mock <IHotelService>(); var applicationDbcontext = new ApplicationDbContext(options); var mockRoomService = new Mock <IRoomService>(); var store = new Mock <IUserStore <ApplicationUser> >(); var mgr = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null); mgr.Object.UserValidators.Add(new UserValidator <ApplicationUser>()); mgr.Object.PasswordValidators.Add(new PasswordValidator <ApplicationUser>()); var testController = new BookingController(applicationDbcontext, mockHotelService.Object, mockRoomService.Object, mgr.Object); var result = testController.BookHotel(null, "test", "test", 1, 1); Assert.IsAssignableFrom <Task <IActionResult> >(result); }