public async Task GetById_WorksCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var addressRepository = new EfDeletableEntityRepository <Address>(context);
            var addressService    = new AddressService(addressRepository);
            var addressSeeder     = new AddressTestSeeder();
            await addressSeeder.SeedOneAddress(context);

            var address = await context.Addresses.SingleOrDefaultAsync(x => x.City == "FourthCity");

            Assert.Throws <ArgumentNullException>(() =>
            {
                addressService.GetById <AddressViewModel>(null);
            });

            var actualAddress = addressService.GetById <AddressViewModel>(address.Id);

            Assert.Equal(address.City, actualAddress.City);
        }
        public async Task Edit_WorksCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var addressRepository = new EfDeletableEntityRepository <Address>(context);
            var addressService    = new AddressService(addressRepository);
            var addressSeeder     = new AddressTestSeeder();
            await addressSeeder.SeedOneAddress(context);

            var address = await context.Addresses.SingleOrDefaultAsync(x => x.City == "FourthCity");

            var addressEditInputModel = new AddressEditInputModel()
            {
                Id             = address.Id,
                City           = "FourthCityEdit",
                Street         = "TestStreet",
                BuildingNumber = "123",
                PostCode       = "223",
            };

            var addressEditInputModelNullInt = new AddressEditInputModel()
            {
                City           = "FourthCityEdit",
                Street         = "TestStreet",
                BuildingNumber = "123",
                PostCode       = "223",
            };

            var booleanResult = await addressService.Edit(addressEditInputModel);

            var edited = await context.Addresses.SingleOrDefaultAsync(x => x.City == "FourthCityEdit");

            Assert.True(booleanResult);

            Assert.NotNull(edited);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await addressService.Edit(addressEditInputModelNullInt);
            });
        }
Exemple #3
0
        public async Task CreateAsync_AddsAddress_ReturnsTrueAndAddsAddress_WithCorrectData()
        {
            var errorMessage = "Method did not return true upon adding an address to user;";

            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userAddressRepository = new EfDeletableEntityRepository <UserAddress>(context);
            var userAddressService    = new UsersAddressesService(userAddressRepository);
            var userSeeder            = new UserTestSeeder();
            await userSeeder.SeedUsersWithAddressesAsync(context);

            var addressSeeder = new AddressTestSeeder();
            await addressSeeder.SeedOneAddress(context);

            var user    = context.Users.First(x => x.UserName == "UserWithoutAddresses");
            var address = context.Addresses.First(x => x.City == "FourthCity");

            var booleanResult = await userAddressService.CreateAsync(user.Id, address.Id);

            var actualAddressesCount = user.UserAddresses.Count();

            Assert.True(booleanResult, errorMessage);
            Assert.Equal(1, actualAddressesCount);
        }
        public async Task DeleteAsync_WorksCorectly()
        {
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var addressRepository = new EfDeletableEntityRepository <Address>(context);
            var addressService    = new AddressService(addressRepository);

            var addressTestSeeder = new AddressTestSeeder();
            await addressTestSeeder.SeedOneAddress(context);

            var address = await context.Addresses.SingleOrDefaultAsync(x => x.City == "FourthCity");

            var booleanResult = await addressService.DeleteAsync(address.Id);

            var addressesCount = await context.Addresses.CountAsync();

            Assert.True(booleanResult, "Servcie did not return true with correct data to be deleten");
            Assert.Equal(0, addressesCount);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await addressService.DeleteAsync(null);
            });
        }