Exemple #1
0
        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.");
        }