Пример #1
0
        public void TamagotchiControllerDetail()
        {
            // Arrange
            var tamagotchiRepo = new Mock <TamagotchiRepository>();
            var userRepo       = new Mock <PlayerUserRepository>();
            var controller     = new TamagotchiController(tamagotchiRepo.Object, userRepo.Object);

            // Act
            var lastDatabaseItem = tamagotchiRepo.Object.GetAll().LastOrDefault();


            // Assert
            if (lastDatabaseItem != null)
            {
                ViewResult result = controller.Details(lastDatabaseItem.TamagotchiId) as ViewResult;

                // Assert
                Assert.IsNotNull(result);
            }
            else
            {
                ViewResult result = controller.Details(null) as ViewResult;

                // Assert
                Assert.IsNull(result);
            }
        }
        public void Test_Dispose()
        {
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            ITamagotchiRepository   tr = new TamagotchiRepository(c);
            TamagotchiController    tc = new TamagotchiController(tr);
            var ccMock = new Mock <ControllerContext>();

            ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser");
            ccMock.SetupGet(x => x.HttpContext.Session["UserId"]).Returns(1);
            ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Customer);
            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.");
        }
Пример #3
0
        public void GetTamagotchiDetails()
        {
            // Arrange
            TamagotchiController controller = new TamagotchiController();

            // Act
            ViewResult result = controller.Details(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }