Exemplo n.º 1
0
        public void CreateNewPerson_AndAddToMockDatabase_TestValid()
        {
            //-- Arrange
            var mockRepo   = new Mock <IPersonData>();
            var controller = new HomeController(mockRepo.Object);

            //-- Act
            var resultModel = controller.Create(MockPeople.Person_1());

            //-- Assert
            var viewResult = resultModel as RedirectToRouteResult;

            Assert.AreEqual("Details", viewResult.RouteValues["action"]);
        }
Exemplo n.º 2
0
        public void DisplayDeleteView_FromMockDatabase_TestValid()
        {
            //-- Arrange
            var mockRepo = new Mock <IPersonData>();

            mockRepo.Setup(repo => repo.Get(1)).Returns(MockPeople.Person_1());
            var controller = new HomeController(mockRepo.Object);

            //-- Act
            var resultView = controller.Delete(1);

            //-- Assert
            var view = resultView as ViewResult;

            Assert.AreEqual("Delete", view.ViewName);
        }
Exemplo n.º 3
0
        public void GetListOfPeople_FromMockDatabase_TestValid()
        {
            //-- Arrange
            var mockRepo = new Mock <IPersonData>();

            mockRepo.Setup(repo => repo.GetAll()).Returns(MockPeople.People());
            var controller = new HomeController(mockRepo.Object);

            //-- Act
            var result = controller.Index();

            //-- Assert
            var viewResult = result as ViewResult;
            var actual     = viewResult.Model as List <Person>;

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual("Index", viewResult.ViewName);
        }
Exemplo n.º 4
0
        public void GetSpecificPerson_FromMockDatabase_TestValid()
        {
            //-- Arrange
            var mockRepo = new Mock <IPersonData>();

            mockRepo.Setup(repo => repo.Get(1)).Returns(MockPeople.Person_1());
            var controller          = new HomeController(mockRepo.Object);
            var expectedFirstName   = "John";
            var expectedPhoneNumber = "07700900223";

            //-- Act
            var result = controller.Details(1);

            //-- Assert
            var viewResult = result as ViewResult;
            var actual     = viewResult.Model as Person;

            Assert.AreEqual(expectedFirstName, actual.FirstName);
            Assert.AreEqual(expectedPhoneNumber, actual.PhoneNumber);
            Assert.AreEqual("Details", viewResult.ViewName);
        }
Exemplo n.º 5
0
        public void EditSpecificPerson_FromMockDatabase_TestValid()
        {
            //-- Arrange
            var newPerson = MockPeople.Person_1();

            newPerson.FirstName    = "Jane";
            newPerson.Surname      = "Doe";
            newPerson.Gender       = GenderType.Female;
            newPerson.EmailAddress = "*****@*****.**";

            var mockRepo = new Mock <IPersonData>();

            mockRepo.Setup(repo => repo.Get(1)).Returns(MockPeople.Person_1());
            mockRepo.Setup(r => r.Update(newPerson)).Verifiable();
            var controller = new HomeController(mockRepo.Object);

            //-- Act
            var result = controller.Edit(newPerson);

            //-- Assert
            var viewResult = result as RedirectToRouteResult;

            Assert.AreEqual("Details", viewResult.RouteValues["action"]);
        }