Exemplo n.º 1
0
        public async Task ReadAll_PersonsExist_ReturnsAllPersons()
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            int expectedAmount = 2;

            dbContext.Persons.AddRange(
                Enumerable.Range(1, expectedAmount).Select(x => new Domain.Person
            {
                ID          = x,
                BirthDate   = "04-10-2010",
                BirthPlace  = $"Birth Place {x}",
                Description = $"Description {x}",
                FirstName   = $"First Name {x}",
                LastName    = $"Last Name {x}"
            })
                );

            await dbContext.SaveChangesAsync();

            var appPerson = new Person(dbContext);
            #endregion

            #region Act
            var result = await appPerson.ReadAll();

            #endregion

            #region Assert
            var actualAmount = Assert.IsAssignableFrom <IEnumerable <PersonModel> >(result).Count();
            Assert.Equal(expectedAmount, actualAmount);
            #endregion
        }
Exemplo n.º 2
0
        public async Task ReadAll_NoPersonsExist_ReturnsEmptyList()
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            int expectedAmount = 0;

            var appPerson = new Person(dbContext);
            #endregion

            #region Act
            var result = await appPerson.ReadAll();

            #endregion

            #region Assert
            var actualAmount = Assert.IsAssignableFrom <IEnumerable <PersonModel> >(result).Count();
            Assert.Equal(expectedAmount, actualAmount);
            #endregion
        }