public async void CanUpdateHotelRoom() { /// Can update an existing hotel room DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("UpdateHotelRoom").Options; using (AsyncInnDbContext context = new AsyncInnDbContext(options)) { HotelRoom hoRoom = new HotelRoom(); hoRoom.HotelID = 90; hoRoom.RoomNumber = 87; hoRoom.RoomID = 81; hoRoom.Rate = 350; hoRoom.PetFriendly = true; HotelRoomController hotController = new HotelRoomController(context); await hotController.Create(hoRoom); HotelRoom upRoom = hoRoom; upRoom.HotelID = 90; upRoom.RoomNumber = 87; upRoom.RoomID = 81; upRoom.Rate = 250; upRoom.PetFriendly = true; await hotController.Edit(90, 87, upRoom); var result = await context.HotelRoom.FirstOrDefaultAsync(ho => ho.HotelID == hoRoom.HotelID && ho.RoomNumber == hoRoom.RoomNumber); Assert.Equal(250, result.Rate); } }
public async void Task_DeleteHotelRoom_Return_OkResult() { var controller = new HotelRoomController(context); var HotelRoomId = 20; var data = await controller.Delete(HotelRoomId); Assert.IsType <OkObjectResult>(data); }
public async void Task_DeleteHotelRoom_Return_BadResultResult() { var controller = new HotelRoomController(context); int?HotelRoomId = null; var data = await controller.Delete(HotelRoomId); Assert.IsType <BadRequestResult>(data); }
public async void Task_GetHotelRoomById_BadRequestResult() { var controller = new HotelRoomController(context); int?HotelRoomId = null; var data = await controller.Get(HotelRoomId); Assert.IsType <BadRequestResult>(data); }
public async void Task_GetHotelRoomById_Return_NotFoundResult() { var controller = new HotelRoomController(context); var HotelRoomId = 15; var data = await controller.Get(HotelRoomId); Assert.IsType <NotFoundResult>(data); }
public MainForm() { InitializeComponent(); _customerController = new CustomerController(); _bookingController = new BookingController(); _hotelRoomController = new HotelRoomController(); CheckInvoicesIfPaid(); }
public async void Task_GetHotelRoom_Return_OkResult() { //Arrange var controller = new HotelRoomController(context); //Act var data = await controller.Get(); Assert.IsType <OkObjectResult>(data); }
public void Task_Get_All_HotelRoom_Return_OkResult() { //Arrange var controller = new HotelRoomController(context); //Act var data = controller.Index(); //Assert Assert.IsType <ViewResult>(data); }
public void Task_Details_HotelRoom_Return_OkResult() { //Arrange var controller = new HotelRoomController(context); int RoomId = 5; //Act var data = controller.Details(RoomId); //Assert Assert.IsType <ViewResult>(data); }
public async void Task_DeleteHotelRoom_return_NotFound() { //Arrange var controller = new HotelRoomController(context); var id = 29; //Act var data = await controller.Delete(id); //Assert Assert.IsType <NotFoundResult>(data); }
public async void Task_GetHotelRoomById_Return_NotFound() { //Arrange var controller = new HotelRoomController(context); var Id = 100; //Act var data = await controller.Get(Id); //Asert Assert.IsType <NotFoundResult>(data); }
public async void Task_DeleteHotelRoom_return_BadResult() { //Arrange var controller = new HotelRoomController(context); int?Id = null; //Act var data = await controller.Get(Id); //Asert Assert.IsType <BadRequestResult>(data); }
public async void Task_Add_AddHotelRoom_Return_OkResult() { var controller = new HotelRoomController(context); var hotelRoom = new HotelRoom() { RoomType = "Double2", RoomDescription = "Nice!", RoomPrice = 18000, RoomImage = "abc", HotelId = 7 }; var data = await controller.Post(hotelRoom); Assert.IsType <CreatedAtActionResult>(data); }
public async void Task_Add_AddHotelRoom_Return_BadRequest() { var controller = new HotelRoomController(context); var hotelRoom = new HotelRoom() { RoomType = "Double Delux2222222222222222222222222222", RoomDescription = "Nice!", RoomPrice = 18000, RoomImage = "abc", HotelId = 17 }; var data = await controller.Post(hotelRoom); Assert.IsType <BadRequestResult>(data); }
public async void Task_GetHotelRoom_Return_NotFound() { //Arrange var controller = new HotelRoomController(context); var data = await controller.Get(); data = null; if (data != null) { Assert.IsType <OkObjectResult>(data); } //else //{ // Assert.Equal(data, null); //} }
public async void Task_GetHotelRoomById_MatchResult() { var controller = new HotelRoomController(context); var HotelRoomId = 4; var data = await controller.Get(HotelRoomId); Assert.IsType <OkObjectResult>(data); var okResult = data.Should().BeOfType <OkObjectResult>().Subject; var hotelRoom = okResult.Value.Should().BeAssignableTo <HotelRoom>().Subject; Assert.Equal("Single1", hotelRoom.RoomType); Assert.Equal("abc", hotelRoom.RoomDescription); Assert.Equal(10000, hotelRoom.RoomPrice); Assert.Equal("abcd", hotelRoom.RoomImage); Assert.Equal(2, hotelRoom.HotelId); }
public async void Task_GetHotelRoomById_Return_MatchResult() { //Arrange var controller = new HotelRoomController(context); var Id = 1; //Act var data = await controller.Get(Id); //Asert Assert.IsType <OkObjectResult>(data); var okresult = data.Should().BeOfType <OkObjectResult>().Subject; var hotelRoom = okresult.Value.Should().BeAssignableTo <HotelRoom>().Subject; Assert.Equal("Single Bed", hotelRoom.RoomType); Assert.Equal(2500, hotelRoom.RoomPrice); }
public void Task_Add_Hotel_Return_OkResult() {//Arrange var controller = new HotelRoomController(context); //Act var hotel = new HotelRoom() { RoomType = "Delux", RoomPrice = 2500, RoomDescription = "Delux Description", RoomImage = "https://media-cdn.tripadvisor.com/media/photo-s/14/f4/d4/24/oyo-9674-hotel-oberoi.jpg", HotelId = 2 }; var data = controller.Create(hotel); //Assert Assert.IsType <RedirectToActionResult>(data); }
public async void Task_PutHotelRoom_Return_BadRequestResult() { var controller = new HotelRoomController(context); int?id = null; var hotelRoom = new HotelRoom() { RoomId = 18, RoomType = "Delux", RoomDescription = "desc!", RoomPrice = 15000, RoomImage = "abc", HotelId = 20 }; var data = await controller.Put(id, hotelRoom); Assert.IsType <BadRequestResult>(data); }
public async void Task_PutHotelRoom_Return_NoContentResult() { var controller = new HotelRoomController(context); var id = 12; var hotelRoom = new HotelRoom() { RoomId = 12, RoomType = "Double12", RoomDescription = "Nice!", RoomPrice = 18000, RoomImage = "abc", HotelId = 7 }; var data = await controller.Put(id, hotelRoom); Assert.IsType <NoContentResult>(data); }
public async void Task_Add_AddHotelRoom_return_BadResult() { //Arrange var controller = new HotelRoomController(context); var hotelRoom = new HotelRoom() { RoomType = "Single Bed , This is Room Type", RoomPrice = 2500, RoomDescription = "Good V", RoomImage = "n available", HotelId = 42 }; //Act var data = await controller.Post(hotelRoom); //Assert Assert.IsType <BadRequestResult>(data); }
public async void Task_UpdateHotelRoomById_Return_BadRequest() { //Arrange var controller = new HotelRoomController(context); int?Id = null; var hotelRoom = new HotelRoom() { RoomId = 28, RoomType = "Single Bed", RoomPrice = 2500, RoomDescription = "Good V", RoomImage = "n available", HotelId = 42 }; //Act var data = await controller.Put(Id, hotelRoom); //Asert Assert.IsType <BadRequestResult>(data); }
public void Test_DeleteConfirmed() { HotelRoomViewModel t = new HotelRoomViewModel() { Size = 2, Type = HotelRoomType.Workroom }; IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; tc.Create(t); tc.DeleteConfirmed(t.Id); Assert.IsFalse(tr.GetAll().Contains(t)); }
public void Task_Edit_Hotelroom_Return_View() { //Arrange var controller = new HotelRoomController(context); int id = 14; var h = new HotelRoom() { RoomType = "Delux1", RoomPrice = 2500, RoomDescription = "Delux Description", RoomImage = "https://media-cdn.tripadvisor.com/media/photo-s/14/f4/d4/24/oyo-9674-hotel-oberoi.jpg", HotelId = 2 }; //Act var EditData = controller.Edit(id, h); //Assert Assert.IsType <RedirectToActionResult>(EditData); }
public async void CanCreateHotelRoom() { /// Can create a new hotel room DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("CreateHotelRoom").Options; using (AsyncInnDbContext context = new AsyncInnDbContext(options)) { HotelRoom hoRoom = new HotelRoom(); hoRoom.HotelID = 80; hoRoom.RoomNumber = 77; hoRoom.RoomID = 81; hoRoom.Rate = 350; hoRoom.PetFriendly = true; HotelRoomController hotController = new HotelRoomController(context); await hotController.Create(hoRoom); var result = context.HotelRoom.FirstOrDefault(ho => ho.HotelID == hoRoom.HotelID && ho.RoomNumber == hoRoom.RoomNumber); Assert.Equal(hoRoom, result); } }
public void Test_Errors() { IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; var r = tc.Delete(null); var r2 = tc.Delete(0); var r3 = tc.Edit(0); //Untestable because null is ambigious between a int? and an object //var r3 = tc.Edit(null); Assert.That(r, Is.TypeOf <HttpStatusCodeResult>()); Assert.That(r2, Is.TypeOf <HttpNotFoundResult>()); Assert.That(r3, Is.TypeOf <HttpNotFoundResult>()); }
public void Test_Edit() { HotelRoomViewModel t = new HotelRoomViewModel() { Size = 2, Type = HotelRoomType.Workroom }; IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; tc.Create(t); t.Size = 5; tc.Edit(t); Assert.AreEqual(tr.Find(t.Id).Size, 5); tr.Remove(t); }
public async void Task_Update_UpdateHotelRoomById_return_OkResult() { //Arrange var controller = new HotelRoomController(context); var id = 2; var hotelRoom = new HotelRoom() { RoomId = 2, RoomType = "Single Bed", RoomPrice = 2500, RoomDescription = "Good V", RoomImage = "n available", HotelId = 1 }; //Act var data = await controller.Put(id, hotelRoom); //Assert Assert.IsType <NoContentResult>(data); }
public void Test_Dispose() { IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; tc.Dispose(); InvalidOperationException e = new InvalidOperationException("Wrong exception"); try { tc.Details(1); } catch (InvalidOperationException exception) { e = exception; } Assert.AreEqual(e.Message, "The operation cannot be completed because the DbContext has been disposed."); }