コード例 #1
0
        public void Details_ReturnsPerson(string expectedPhoneNumber)
        {
            var actual = _personController.Details(30);

            Assert.IsAssignableFrom <PersonViewModel>(actual);
            Assert.Equal(expectedPhoneNumber, actual.PhoneNumber);
        }
コード例 #2
0
        public void DetailsTest()
        {
            int id = 1;
            var um = new FakeUserManager();
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();

            uow.Setup(x => x.PersonRepository.GetByKey((long)id)).Returns(_fakePersons.Where(x => x.Id == id).FirstOrDefault());
            uow.Setup(x => x.FileRepository.GetByKey((long)id)).Returns(new Models.File()
            {
                Path = (Directory.GetCurrentDirectory() + "\\FilmSearch.dll"), FileType = "dll"
            });
            uow.Setup(x => x.PersonRoleRepository.GetAll()).Returns(fakePersonRoles);
            uow.Setup(x => x.PersonPerformanceRepository.GetAll()).Returns(fakePersonPerfomances);
            uow.Setup(x => x.FilmRepository.GetByKey(It.IsAny <int>())).Returns(new Film()
            {
                Id      = 1,
                PhotoId = 1,
                Title   = "title"
            }
                                                                                );
            uow.Setup(x => x.FilmRoleRepository.GetByKey(It.IsAny <int>())).Returns(new FilmRole()
            {
                Id   = 1,
                Name = "name"
            }
                                                                                    );

            Mock <IHostingEnvironment> env = new Mock <IHostingEnvironment>();
            PersonService    ps            = new FakePersonService(uow.Object);
            PersonController PC            = new PersonController(uow.Object, env.Object, ps, um);

            /*
             * var username = "******";
             * var identity = new GenericIdentity(username);
             * //create claim and add it to indentity
             * var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username);
             * identity.AddClaim(nameIdentifierClaim);
             *
             * var user = new Mock<IPrincipal>();
             * user.Setup(x => x.Identity).Returns(identity);
             * Thread.CurrentPrincipal = user.Object;
             */
            PC.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, "username")
                    }, "someAuthTypeName"))
                }
            };

            var result = PC.Details(id) as ViewResult;

            result.Should().NotBeNull();
        }
コード例 #3
0
        public void DetailsWithoutId()
        {
            // Arrange
            var controller = new PersonController();

            // Act
            var result = (RedirectToRouteResult)controller.Details(null);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #4
0
        public void DetailsWithId()
        {
            // Arrange
            var controller = new PersonController();

            // Act
            var result = (ViewResult)controller.Details(33);

            // Assert
            Assert.AreEqual("Details", result.ViewName);
        }
コード例 #5
0
        public void PersonDetails()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            ViewResult result = controller.Details(testPersonID) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Firstname_Updated", (result.Model as Models.Person).FirstName);
        }
コード例 #6
0
        public void PersonController_Details()
        {
            // Arrange
            PersonController controller = new PersonController();

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

            // Assert
            Assert.IsTrue(result.RouteValues["action"].ToString() == "FatalError");
        }
コード例 #7
0
        public void Details_Returns_NotFoundResult()
        {
            // Arrange
            var entity   = GetPersonEntity();
            var mockRepo = new Mock <IPersonRepository>();

            mockRepo.Setup(repo => repo.GetById(entity.Id)).Returns(entity);
            var controller = new PersonController(mockRepo.Object, CreateMapper());

            // Act
            var result = controller.Details(2);

            // Assert
            var notFoundResult = Assert.IsType <NotFoundResult>(result);
        }
コード例 #8
0
        public void Details_Returns_ViewResult()
        {
            // Arrange
            var entity   = GetPersonEntity();
            var mockRepo = new Mock <IPersonRepository>();

            mockRepo.Setup(repo => repo.GetById(entity.Id)).Returns(entity);
            var controller = new PersonController(mockRepo.Object, CreateMapper());

            // Act
            var result = controller.Details(entity.Id);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <Person>(viewResult.ViewData.Model);

            Assert.Equal(entity.Id, model.Id);
            Assert.Equal(entity.Code, model.Code);
            Assert.Equal(entity.Name, model.Name);
        }
コード例 #9
0
        public async Task Details_PersonExists_ReturnsAViewResultWithPerson()
        {
            //Arrange
            var personId   = 1;
            var testPerson = new PersonViewModel()
            {
                Id = personId
            };
            var personsRepo = new Mock <IPersonWebService>();

            personsRepo.Setup(g => g.Get(personId)).ReturnsAsync(testPerson);
            var controller = new PersonController(personsRepo.Object);

            // Act
            var result = await controller.Details(personId, 1);

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult.ViewData.Model as PersonViewModel;

            Assert.AreEqual(personId, model.Id);
        }