예제 #1
0
        public void AnimalsDelete()
        {
            Animal animal = new Animal();

            animal.Name     = "Jeroen";
            animal.Price    = 100;
            animal.Category = "Boerderij";
            AnimalRepo.Add(animal);

            var result = animalsController.DeleteConfirmed(animal.Id) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["Action"]);
            Assert.IsNotNull(result.ToString());
        }
예제 #2
0
        public async Task DeleteConfirmed_DeleteAnimalsAndReturnsIndex_WhenAnimalIsValid()
        {
            // Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

            var    controller = new AnimalsController(repository, env);
            Animal animal     = GetAnimal();

            A.CallTo(() => repository.Get(1)).Returns(animal);

            //Act
            var result = await controller.DeleteConfirmed(1);

            //Assert
            A.CallTo(() => repository.Delete(animal)).MustHaveHappened();

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
        }