예제 #1
0
        public async Task GetUserAddressesWorksCorrectly()
        {
            var options = new DbContextOptionsBuilder<ApplicationDbContext>()
                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

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

            var userId = Guid.NewGuid().ToString();

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

            var addressTwo = new Address()
            {
                Id = 2,
                UserId = userId,
            };

            var addressThree = new Address()
            {
                Id = 3,
                UserId = Guid.NewGuid().ToString(),
            };

            dbContext.Add(address);
            dbContext.Add(addressTwo);
            dbContext.Add(addressThree);
            await dbContext.SaveChangesAsync();
            var service = new AddressesService(repository);
            var addresses = service.GetUserAddresses<AddressServiceModel>(userId);

            Assert.Equal(2, addresses.Count());
        }