コード例 #1
0
        public async Task GetAllAsync_ShouldReturnIEnumerableCountryDTOAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnIEnumerableCountryDTOAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name = "Bulgaria"
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <CountryDTO>));
            }
        }
コード例 #2
0
        public async Task GetAllAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var countriesRepository = new EfDeletableEntityRepository <Country>(context);
            var countriesService    = new CountriesService(countriesRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCountriesAsync(context);

            var countries = await countriesService.GetAllAsync <CountriesServiceAllModel>();

            var count = countries.ToList().Count;

            Assert.True(count == 8, ErrorMessage);
        }
コード例 #3
0
        public async Task GetAllAsync_ShouldReturnEmptyIfNoCountriesAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnEmptyIfNoCountriesAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.AreEqual(result.Count(), 0);
            }
        }
コード例 #4
0
        public async Task GetAllAsync_ShouldReturnNullIfModelHasNoNameFailsAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("GetAllAsync_ShouldReturnNullIfModelHasNoNameFailsAsync");

            using (var context = new BOContext(options))
            {
                var country = new Country();
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new CountriesService(context);
                var result = await sut.GetAllAsync();

                //Assert
                Assert.AreEqual(result, null);
            }
        }