Esempio n. 1
0
        public async Task EditAsyncReturnsIfAddressDoesntExists()
        {
            var options = new DbContextOptionsBuilder<ApplicationDbContext>()
                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository<Address>(dbContext);

            var address = new Address()
            {
                Id = 1,
            };

            var editedAddress = new AddressServiceModel()
            {
                Id = 2,
            };

            dbContext.Add(address);
            await dbContext.SaveChangesAsync();
            var service = new AddressesService(repository);
            await service.EditAsync(editedAddress);
            var addressesInDbCount = repository.All().ToList().Count();

            Assert.Equal(1, addressesInDbCount);
        }
Esempio n. 2
0
        public async Task EditWorksCorrectly()
        {
            var options = new DbContextOptionsBuilder<ApplicationDbContext>()
                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository<Address>(dbContext);

            var address = new Address()
            {
                Id = 1,
                CityId = 1,
                Appartment = "1",
                BuildingNumber = "1",
                Neighborhood = "1",
                PostCode = "1",
                StreetName = "1",
            };

            dbContext.Add(address);
            await dbContext.SaveChangesAsync();
            var service = new AddressesService(repository);

            var editedAddress = new AddressServiceModel()
            {
                Id = 1,
                CityId = 2,
                Appartment = "2",
                BuildingNumber = "2",
                Neighborhood = "2",
                PostCode = "2",
                StreetName = "2",
            };

            await service.EditAsync(editedAddress);
            var addressInDb = repository.All().FirstOrDefault();

            Assert.Equal(editedAddress.CityId, addressInDb.CityId);
            Assert.Equal(editedAddress.Appartment, addressInDb.Appartment);
            Assert.Equal(editedAddress.BuildingNumber, addressInDb.BuildingNumber);
            Assert.Equal(editedAddress.Neighborhood, addressInDb.Neighborhood);
            Assert.Equal(editedAddress.PostCode, addressInDb.PostCode);
            Assert.Equal(editedAddress.StreetName, addressInDb.StreetName);
        }