Пример #1
0
        public async Task EditAddressAsyncShouldEditAddressSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var addressService = new AddressesService(dbContext, null);

            var city = new City
            {
                Id       = Guid.NewGuid().ToString(),
                Name     = CityName,
                PostCode = CityPostCode,
            };

            await dbContext.Cities.AddAsync(city);

            await dbContext.SaveChangesAsync();

            var user = new ApplicationUser
            {
                FirstName = UserFirstName,
                LastName  = UserLastName,
            };

            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var address = new Address
            {
                Country = AddressCountryName,
                Street  = AddressStreet,
                CityId  = city.Id,
                UserId  = user.Id,
            };

            await dbContext.Addresses.AddAsync(address);

            await dbContext.SaveChangesAsync();

            var addressViewModel = new AddressAdminEditViewModel
            {
                Id      = address.Id,
                CityId  = city.Id,
                Country = AddressEditCountryName,
                UserId  = user.Id,
            };

            await addressService.EditAddressAsync(addressViewModel);

            Assert.Equal(address.Country, addressViewModel.Country);
        }
Пример #2
0
        public async Task EditAddressAsyncShouldThrowExceptionIfCityIdDoesNotExists()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var addressService = new AddressesService(dbContext, null);

            var city = new City
            {
                Id       = Guid.NewGuid().ToString(),
                Name     = CityName,
                PostCode = CityPostCode,
            };

            await dbContext.Cities.AddAsync(city);

            await dbContext.SaveChangesAsync();

            var user = new ApplicationUser
            {
                FirstName = UserFirstName,
                LastName  = UserLastName,
            };

            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var address = new Address
            {
                Country = AddressCountryName,
                Street  = AddressStreet,
                CityId  = city.Id,
                UserId  = user.Id,
            };

            await dbContext.Addresses.AddAsync(address);

            await dbContext.SaveChangesAsync();

            var addressViewModel = new AddressAdminEditViewModel
            {
                Id      = address.Id,
                CityId  = CityId,
                Country = AddressEditCountryName,
                UserId  = user.Id,
            };

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await addressService.EditAddressAsync(addressViewModel));

            Assert.IsType <ArgumentNullException>(exception);
        }
Пример #3
0
        public async Task EditAddressAsyncShouldThrowExceptionIfCityIsNull()
        {
            var option = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                         .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new MyCalisthenicAppDbContext(option);

            var addressService = new AddressesService(dbContext, null);

            var city = new City
            {
                Id       = Guid.NewGuid().ToString(),
                Name     = CityName,
                PostCode = CityPostCode,
            };

            await dbContext.Cities.AddAsync(city);

            await dbContext.SaveChangesAsync();

            var addressViewModel = new AddressAdminEditViewModel
            {
                CityId = Guid.NewGuid().ToString(),
            };

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await addressService.EditAddressAsync(addressViewModel));

            Assert.IsType <ArgumentNullException>(exception);
        }