public void CanEditPerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            PersonSectionAddEditModel personSection = new PersonSectionAddEditModel();

            personSection.id = 5;
            personSection.name = "Zbigniew";
            personSection.surname = "Strzelec";
            personSection.area_code = 44;
            personSection.email = "*****@*****.**";
            personSection.section_name = "4";
            personSection.phone_number = 12345;
            personSection.phone_number2 = 666666;

            var redirectToRouteResult = controller.Edit(personSection) as RedirectToRouteResult;

            Person temp = mock_person.Object.Repository.FirstOrDefault(x => x.id == 5);
            Assert.AreEqual(temp.name, "ZBIGNIEW");
            Assert.AreEqual(temp.surname, "STRZELEC");
            Assert.AreEqual(temp.area_code, 44);
            Assert.AreEqual(temp.email, "*****@*****.**");
            Assert.AreEqual(temp.id_section, 4);
            Assert.AreEqual(temp.phone_number, 12345);
            Assert.AreEqual(temp.phone_number2, 666666);

            mock_person.Verify(m => m.EditObject(temp), Times.Once());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }
        public void CanAddPerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            PersonSectionAddEditModel personSection = new PersonSectionAddEditModel();

            personSection.id = 5;
            personSection.name = "Zbigniew";
            personSection.surname = "Strzelec";
            personSection.area_code = 44;
            personSection.email = "*****@*****.**";
            personSection.section_name = "4";
            personSection.phone_number = 12345;
            personSection.phone_number2 = 666666;

            var redirectToRouteResult = controller.Add(personSection) as RedirectToRouteResult;
            mock_person.Verify(m => m.AddObject(It.IsAny<Person>()), Times.Once());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }
        public void CanDeletePerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            DeleteObjectById model = new DeleteObjectById() { Description = "XXXX", Id = 5 };

            var redirectToRouteResult = controller.Delete(model) as RedirectToRouteResult;
            mock_person.Verify(m => m.DeleteObject(It.IsAny<Person>()), Times.Once());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }
        public void GetAllPeople()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);

            Assert.AreEqual(mock_person.Object.Repository.Count(), 6);
        }
        public void CantEditPerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            PersonSectionAddEditModel personSection = null;

            var redirectToRouteResult = controller.Edit(personSection) as RedirectToRouteResult;

            mock_person.Verify(m => m.EditObject(It.IsAny<Person>()), Times.Never());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }
        public void CantDeletePerson()
        {
            Mock<HttpRequestBase> request = new Mock<HttpRequestBase>();
            Mock<HttpResponseBase> response = new Mock<HttpResponseBase>();
            Mock<HttpContextBase> context = new Mock<HttpContextBase>();

            context.Setup(c => c.Request).Returns(request.Object);
            context.Setup(c => c.Response).Returns(response.Object);
            //Add XMLHttpRequest request header
            request.Setup(req => req["X-Requested-With"]).
                Returns("XMLHttpRequest");

            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            controller.ControllerContext = new ControllerContext(
            context.Object, new RouteData(), controller);
            DeleteObjectById model = new DeleteObjectById() { Description = "XXXX", Id = 155 };
            var viewResult = controller.Delete(model.Id) as PartialViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual("_Info", viewResult.ViewName);
            Assert.AreEqual("Podany pracownik nie istnieje", ((InfoModel)viewResult.Model).Description);
            Assert.AreEqual("Index", ((InfoModel)viewResult.Model).Action);
            Assert.AreEqual("Person", ((InfoModel)viewResult.Model).Controller);
            mock_person.Verify(m => m.DeleteObject(It.IsAny<Person>()), Times.Never());
        }