Example #1
0
        internal static IHttpActionResult GetAll()
        {
            Insert();
            var response = baseController.GetAll();

            return(response);
        }
        public void GetAllPersones()
        {
            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.GetAll()).Returns(GetAllTest());
            var factoryMock = new Mock <IRepositoryFactory>();

            factoryMock.Setup(f => f.GetRepository <Person>()).Returns(mock.Object);
            _personController = new PersonController(factoryMock.Object);

            var json   = _personController.GetAll();
            var person = json.Value as List <Person>;

            Assert.NotNull(json);
            Assert.NotNull(person);
            Assert.AreEqual(person.Count, 2);

            //var mock1 = new Mock<IRepository<Person>>();
            //mock1.Setup(repo => repo.GetAll().FirstOrDefault()).Returns(GetFirstOrDefaultTest(1));
            //var factoryMock1 = new Mock<IRepositoryFactory>();
            //factoryMock1.Setup(f => f.GetRepository<Person>()).Returns(mock1.Object);
            //_personController = new PersonController(factoryMock1.Object);

            //json = _personController.GetAll();
            //person = json.Value as List<Person>;
            //Assert.AreEqual();
        }
Example #3
0
        public void GetAll_ShouldReturnAllPersons()
        {
            // arrange
            var expected = new List <Person>
            {
                new Person {
                    Id = 1, FirstName = "Andrew", LastName = "Armstrong"
                },
                new Person {
                    Id = 2, FirstName = "Peter", LastName = "Celver"
                }
            }.AsQueryable();

            dataService.Setup(ds => ds.GetAll()).Returns(expected);
            PersonController controller = new PersonController(dataService.Object);

            // act
            var actionResult = controller.GetAll();
            var result       = actionResult.Result as OkObjectResult;

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual((int)HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual(expected, result.Value);
        }
Example #4
0
        public void GetAll()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            IHttpActionResult result = controller.GetAll();

            // Assert
            Assert.IsNotNull(result);
        }
        public void Create()
        {
            var    memoryStore = new List <Person>();
            Person personStub  = new Person {
                Id = 1
            };
            var mock = new Mock <IRepository <Person> >();

            mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable());
            mock.Setup(repo => repo.Create(It.IsAny <Person>())).Returns((Person person) => {
                person.Id = 1;
                memoryStore.Add(person);
                return(person);
            });
            var factoryMock = new Mock <IRepositoryFactory>();

            factoryMock.Setup(f => f.GetRepository <Person>()).Returns(mock.Object);
            _personController = new PersonController(factoryMock.Object);
            var emptyJson = _personController.GetAll();

            Assert.IsNotNull(emptyJson);
            var emptyStore = emptyJson.Value as List <Person>;

            Assert.IsNotNull(emptyStore);
            Assert.AreEqual(emptyStore.Count, 0);
            var json = _personController.Create(personStub);

            Assert.IsNotNull(json);
            var result = json.Value as Person;

            Assert.NotNull(result);
            Assert.AreEqual(result.Id, 1);
            Assert.AreEqual(result.Address, personStub.Address);
            var notEmptyJson = _personController.GetAll();

            Assert.IsNotNull(notEmptyJson);
            var notEmptyStore = notEmptyJson.Value as List <Person>;

            Assert.IsNotNull(notEmptyStore);
            Assert.AreEqual(notEmptyStore.Count, 1);
        }
        public void GetAll()
        {
            // Arrange
            PersonController target = new PersonController(_mockLogger, _context);

            // Act
            var actual = target.GetAll() as OkObjectResult;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsTrue(
                ((List <Person>)actual.Value).ToList().Count == 1);
        }
Example #7
0
        public void Test_Get_All()
        {
            // Arrange
            var telemetryClient = new TelemetryClient();
            var loggingService  = new TestLoggingService();

            // Act
            PersonController personController = new PersonController(loggingService);
            var response = personController.GetAll().Result;

            // Assert
            Assert.IsType <string>(response);
            Assert.IsType <List <Person> >(JsonConvert.DeserializeObject <List <Person> >(response));
        }
Example #8
0
        public void GetSinglePageFromControllerReturnsPartialResults()
        {
            // Arrange
            var mockRepository = new Mock <IPersonRepository>();

            mockRepository.Setup(x => x.GetAll(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(people.Where(q => q.ActiveFlag == true).OrderBy(q => q.FirstName).Take(10));
            var controller = new PersonController(mockRepository.Object);

            // Act
            var actionResult = controller.GetAll(1, 10, "");

            // Assert
            var response = actionResult as OkNegotiatedContentResult <IEnumerable <Person> >;

            Assert.IsNotNull(response);
            Assert.AreEqual(10, response.Content.Count());
        }
        public void Get_all_person_sucess()
        {
            _apiContext.Persons.RemoveRange(_apiContext.Persons);

            const int count = 10;

            for (int i = 0; i < count; i++)
            {
                _apiContext.Persons.Add(new PersonModel {
                    Name = $"Person Get All {i}"
                });
            }
            _apiContext.SaveChanges();

            var persons = _personController.GetAll();

            Assert.Equal(count, persons.Count);
        }