Пример #1
0
        public void PersonController_DeleteConfirmed()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            // this person does not exist - will redirect to error page
            var result = (RedirectToRouteResult)controller.DeleteConfirmed(0);

            // Assert
            Assert.IsTrue(result.RouteValues["action"].ToString() == "FatalError");
        }
Пример #2
0
        public void PersonDeleteConfirmed()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            RedirectToRouteResult routeResult = controller.DeleteConfirmed(testPersonID) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(routeResult);
            Assert.AreEqual(routeResult.RouteValues["action"], "../Home/Index");
            // Make sure the person was deleted
            Models.Person person = controller.GetPerson(testPersonID);
            Assert.IsNull(person);
        }
        public void DeleteConfirmed_Returns_RedirectToActionResult()
        {
            // Arrange
            var mockRepo   = new Mock <IPersonRepository>();
            var controller = new PersonController(mockRepo.Object, CreateMapper());

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

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

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal(nameof(controller.Index), redirectToActionResult.ActionName);
        }
Пример #4
0
        public void TestDeleteConfMoq()
        {
            Person person = new Person();

            person.imie     = "Basia";
            person.nazwisko = "Kowalska";
            Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>();

            context.Setup(x => x.FindPersonById(2)).Returns(person);
            context.Setup(s => s.SaveChanges()).Returns(0);
            var controller = new PersonController(context.Object);
            var result     = controller.DeleteConfirmed(2) as RedirectToRouteResult;

            Assert.AreEqual("All", result.RouteValues["Action"]);
            Assert.AreEqual("Person", result.RouteValues["Controller"]);
        }
        public void TestDeleteConf()
        {
            var context = new FakePersonSharingContext();

            context.Persons = new[] {
                new Person {
                    personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1
                },
                new Person {
                    personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2
                },
                new Person {
                    personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3
                }
            }.AsQueryable();
            var controller = new PersonController(context);
            var result     = controller.DeleteConfirmed(2) as RedirectToRouteResult;

            Assert.AreEqual("All", result.RouteValues["Action"]);
            Assert.AreEqual("Person", result.RouteValues["Controller"]);
        }