public async Task Index_GetTestPersons_ReturnViewResult()
        {
            // Arrange
            persons.Setup(m => m.GetPersons("User")).ReturnsAsync(GetTestPersons());

            var contr = new PersonsController(log.Object, persons.Object);

            contr.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, "User")
                    }, "someAuthTypeName"))
                }
            };

            // Act
            var result = await contr.Index();

            // Assert
            Assert.That(result, Is.TypeOf <ViewResult>());
            Assert.IsAssignableFrom <List <Persons> >((result as ViewResult).Model);
            Assert.AreEqual(GetTestPersons().Count, ((result as ViewResult).Model as List <Persons>).Count);
            Assert.AreEqual("CCC", ((result as ViewResult).Model as List <Persons>)[2].Name);
        }
Ejemplo n.º 2
0
        public void GetAll_Invoke_ReturnView()
        {
            const int expectedId      = 1;
            var       personsDataMock = new Mock <IPersonsData>();

            personsDataMock.Setup(d => d.GetAll()).Returns(() =>
            {
                return(new[]
                {
                    new Person
                    {
                        Id = expectedId,
                    },
                    new Person(),
                    new Person(),
                });
            });
            var controller = new PersonsController(personsDataMock.Object);

            var result = controller.Index();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = (ViewResult)result;

            Assert.IsInstanceOfType(viewResult.Model, typeof(IEnumerable <Person>));
            var persons = (IEnumerable <Person>)viewResult.Model;

            Assert.AreEqual(expectedId, persons.FirstOrDefault().Id);
        }
Ejemplo n.º 3
0
        public void Index_ShouldSetTitle_AndSubTitle()
        {
            _personController.Index();

            Assert.Equal("Persons", _personController.ViewBag.Title);
            Assert.Equal("Persons for Gizzie", _personController.ViewBag.SubTitle);
        }
        public async Task Index_ReturnPersonsArray()
        {
            // Arrange

            // Act
            var result = await controllerWithContext.Index();

            // Assert
            Assert.That(result, Is.TypeOf <ViewResult>());
            Assert.IsAssignableFrom <Persons[]>((result as ViewResult).Model);
        }
Ejemplo n.º 5
0
        public void GetViewTest_Index4()
        {
            var mock = new Mock <IService>();

            mock.Setup(a => a.ReadAll()).Returns(people4);
            PersonsController controller = new PersonsController(mock.Object);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result.Model);
            Assert.AreEqual(people4, result.Model);
        }