示例#1
0
        public async Task GetAddressOrCreateByCountryNameAndTownName_WhitNewTownName_ShouldReturnCorrectAddress()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository     = new EfDeletableEntityRepository <Address>(context);
            var countryService = new Mock <ICountriesService>();

            countryService.Setup(x => x.GetCountryByName("Bulgaria")).Returns(new Country()
            {
                Name = "Bulgaria"
            });
            var townService = new Mock <ITownsService>();

            townService.Setup(x => x.GetOrCreateTownByName("Sofia")).Returns(new Town()
            {
                Name = "Sofia"
            });

            var service = new AddressesService(repository, countryService.Object, townService.Object);

            var actualResult = service.GetAddressOrCreateByCoutryNameAndTownName("Bulgaria", "Sofia");

            Assert.Equal("Bulgaria", actualResult.Country.Name);
            Assert.Equal("Sofia", actualResult.Town.Name);
        }
示例#2
0
        public async Task GetAddressOrCreateByCoutryNameAndTownName_WithNullTownTest_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();
            var repository     = new EfDeletableEntityRepository <Address>(context);
            var countryService = new Mock <ICountriesService>();
            var townService    = new Mock <ITownsService>();

            var service = new AddressesService(repository, countryService.Object, townService.Object);

            Assert.Throws <ArgumentNullException>(() => service.GetAddressOrCreateByCoutryNameAndTownName("Bulgaria", null));
        }
示例#3
0
        public async Task GetAddressOrCreateByCoutryNameAndTownNameTest_WhitCorrectData_ShouldReturnAddress()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();
            var repository     = new EfDeletableEntityRepository <Address>(context);
            var countryService = new Mock <ICountriesService>();
            var townService    = new Mock <ITownsService>();

            var service = new AddressesService(repository, countryService.Object, townService.Object);

            var actualResult   = service.GetAddressOrCreateByCoutryNameAndTownName("Bulgaria", "Sofia");
            var expectedResult = this.GetDummyData()[0];

            Assert.Equal(expectedResult.Country.Name, actualResult.Country.Name);
            Assert.Equal(expectedResult.Town.Name, actualResult.Town.Name);
        }