Exemplo n.º 1
0
        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 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);
        }
Exemplo n.º 3
0
        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>());
        }
Exemplo n.º 4
0
        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);
        }