Beispiel #1
0
        public void DB_Edit_test()
        {
            AnimalsController       animalController = new AnimalsController(db);
            VeterinariansController vetController    = new VeterinariansController(db2);
            Veterinarian            testVet          = new Veterinarian("Jesse", "Elephants");

            testVet.VeterinarianId = 1;
            Animal testAnimal = new Animal();

            testAnimal.AnimalId         = 1;
            testAnimal.Name             = "Ellie";
            testAnimal.Species          = "Elephant";
            testAnimal.Sex              = "Female";
            testAnimal.HabitatType      = "Savanna";
            testAnimal.MedicalEmergency = false;
            testAnimal.VeterinarianId   = 1;

            vetController.Create(testVet);
            animalController.Create(testAnimal);

            testAnimal.Name = "Eli";
            animalController.Edit(testAnimal);

            var collection = (animalController.Index() as ViewResult).ViewData.Model as List <Animal>;

            Assert.AreEqual(testAnimal.Name, "Eli");
        }
        public void Edit_ReturnsResult()
        {
            var    controller = new AnimalsController(DbContext);
            Animal animal     = new Animal();
            var    result     = controller.Edit(1, animal, null);

            var viewResult = Assert.IsType <Task <IActionResult> >(result);
        }
        public void Edit_Fail()
        {
            var service = GetMockedAnimalService();

            service.Setup(x => x.Edit(It.IsAny <AnimalContract>())).Returns(new OperationResult(false, "Fail"));
            var controller = new AnimalsController(service.Object);

            var result = (OperationResult)controller.Edit(new AnimalContract()).Data;

            Assert.IsFalse(result.Success);
            Assert.IsNotEmpty(result.Message);
        }
Beispiel #4
0
        public async Task EditGet_ReturnNotFoundException_WhenAnimalIdIsNull()
        {
            //Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

            var controller = new AnimalsController(repository, env);

            //Act
            var result = await controller.Edit(null);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
Beispiel #5
0
        public async Task Edit_ReturnsNotFoundResult_WhenIdDoesNotMatchWithAnimal()
        {
            //Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

            var controller = new AnimalsController(repository, env);
            var animal     = GetAnimal();
            //Act
            var result = await controller.Edit(-1, animal);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
Beispiel #6
0
        public async Task EditGet_ReturnNotFoundException_WhenAnimalsIsNull()
        {
            // Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

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

            A.CallTo(() => repository.Get(A <int> .Ignored)).Returns(animal);

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

            //Assert
            A.CallTo(() => repository.Get(A <int> .Ignored)).MustHaveHappened();
            Assert.IsType <NotFoundResult>(result);
        }
Beispiel #7
0
        public async Task Edit_ReturnsNotFoundResult_WhenDoesNotExist()
        {
            //Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

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

            A.CallTo(() => repository.Update(A <Animal> .Ignored)).Throws(new DbUpdateConcurrencyException());
            A.CallTo(() => repository.Exists(A <int> .Ignored)).Returns(false);

            //Act
            var result = await controller.Edit(1, animal);

            //Assert
            A.CallTo(() => repository.Exists(A <int> .Ignored)).MustHaveHappened();
            Assert.IsType <NotFoundResult>(result);
        }
Beispiel #8
0
        public async Task EditGet_ReturnsViewData_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(A <int> .Ignored)).Returns(animal);

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

            //Assert
            A.CallTo(() => repository.Get(A <int> .Ignored)).MustHaveHappened();
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsType <Animal>(viewResult.Model);
        }
Beispiel #9
0
        public async Task Edit_EditsAnimalAndReturnsToIndex_WhenAnimalAndIdAreValid()
        {
            //Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

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

            //Act
            var result = await controller.Edit(animal.ID, animal);

            //Assert
            A.CallTo(() => repository.Update(A <Animal> .Ignored)).MustHaveHappened();

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

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
Beispiel #10
0
        public async Task Edit_ReturnsAnimalViewResult_WhenModelStateIsInvalid()
        {
            //Arrange
            var repository = A.Fake <IRepository <Animal> >();
            var env        = A.Fake <IWebHostEnvironment>();

            var controller = new AnimalsController(repository, env);

            controller.ModelState.AddModelError("Name", "Required");

            var animal = GetAnimal();

            //Act
            var result = await controller.Edit(animal.ID, animal);

            //Assert
            var animalResult = Assert.IsType <ViewResult>(result);

            Assert.IsType <Animal>(animalResult.Model);
        }
Beispiel #11
0
        public void AnimalsEdits()
        {
            var result = animalsController.Edit(2) as ViewResult;

            Assert.IsNotNull(result);
        }