예제 #1
0
        public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "PropertiesTestDb").Options;

            using var dbContext = new ApplicationDbContext(options);
            dbContext.Properties.Add(new Property());
            dbContext.Properties.Add(new Property());
            dbContext.Properties.Add(new Property());
            await dbContext.SaveChangesAsync();

            using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext);
            var propertiesService = new PropertiesService(propertyRepository);

            Assert.Equal(3, propertiesService.GetCount());
        }
        public async Task GetCountShouldReturnTheCorrectAmountOfProperties()
        {
            var db       = GetDatabase();
            var property = new Property()
            {
                Name = "Name",
            };
            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);

            await db.Properties.AddAsync(property);

            await db.SaveChangesAsync();

            Assert.Equal(1, service.GetCount());
        }