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

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

            if (deleteItem == null)
            {
                Assert.IsNull(deleteItem);
            }
            else
            {
                controller.DeleteConfirmed(deleteItem.TamagotchiId);
                var lastDatabaseItem = tamagotchiRepo.Object.GetAll().LastOrDefault();

                // Assert
                if (lastDatabaseItem == null)
                {
                    Assert.IsNull(lastDatabaseItem);
                }
                else
                {
                    Assert.AreNotEqual(lastDatabaseItem.TamagotchiId, deleteItem.TamagotchiId);
                }
            }
        }
        public void Test_DeleteConfirmed()
        {
            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name  = "Test_Remov",
                Alive = false
            };
            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.Create(t);
            tc.DeleteConfirmed(t.Id);

            Assert.IsFalse(tr.GetAll().Contains(t));
        }
Пример #3
0
        public void TestDeleteConfirmed()
        {
            Assert.IsInstanceOfType(_controller.DeleteConfirmed(1), typeof(RedirectToRouteResult));

            _service.Verify(m => m.DeleteTamagotchi(It.IsAny <int>()), Times.Once);
        }