public async Task CreateCountry_Fail_IfAlreadyExists()
        {
            var options      = TestUtils.GetOptions(nameof(CreateCountry_Fail_IfAlreadyExists));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var country = new Country
            {
                Name = "Bulgaria"
            };

            var countryDTO = new CountryDTO
            {
                Name = "Bulgaria"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Countries.AddAsync(country);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new CountryService(assertContext, mockDateTime.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateCountryAsync(countryDTO));
            }
        }
示例#2
0
        public void Insert_NewObject_ReturnsTrue()
        {
            mockUnitOfWork.Setup(c => c.CountryRepository.Insert(country));

            var res = countryService.CreateCountryAsync(country);

            Assert.IsTrue(res.Result.Successed);
        }
        public async Task Should_ThrowArgumentNullException_WhenNameIsWhitespace()
        {
            string countryName = "countryTest";
            var    options     = TestUtilities.GetOptions(nameof(Should_ThrowArgumentNullException_WhenNameIsWhitespace));

            using (var assertContext = new CocktailDatabaseContext(options))
            {
                var sut = new CountryService(assertContext);
                await sut.CreateCountryAsync("");
            }
        }
        public async Task Create_Country_Correctly()
        {
            //arrange

            string countryName = "countryTest";
            var    options     = TestUtilities.GetOptions(nameof(Create_Country_Correctly));

            using (var assertContext = new CocktailDatabaseContext(options))
            {
                var sut = new CountryService(assertContext);
                await sut.CreateCountryAsync(countryName);;
                Assert.AreEqual(1, assertContext.Countries.Count());
                var city = await assertContext.Countries.FirstOrDefaultAsync(u => u.Name == countryName);

                Assert.IsNotNull(city);
            }
        }
        public async Task CreateCountry_If_ParamsAreValid()
        {
            var options      = TestUtils.GetOptions(nameof(CreateCountry_If_ParamsAreValid));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var countryDTO = new CountryDTO
            {
                Name = "Bulgaria"
            };

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut    = new CountryService(assertContext, mockDateTime.Object);
                var result = await sut.CreateCountryAsync(countryDTO);

                Assert.AreEqual(1, result.Id);
                Assert.AreEqual("Bulgaria", result.Name);
            }
        }
        public async Task Should_ThrowArgumentException_WhenNameExist()
        {
            string countryName = "countryTest";
            var    options     = TestUtilities.GetOptions(nameof(Should_ThrowArgumentException_WhenNameExist));

            using (var arrangeContext = new CocktailDatabaseContext(options))
            {
                arrangeContext.Countries.Add(new Country()
                {
                    Name = countryName
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new CocktailDatabaseContext(options))
            {
                var sut = new CountryService(assertContext);
                await sut.CreateCountryAsync(countryName);
            }
        }