Пример #1
0
        public async Task DeleteAsyncSucceeds()
        {
            // Arrange
            var options    = GetTestDbContextOptions("Delete_ScrapeJob_Database");
            var testEntity = GenerateTestEntity();

            using (var context = new WaasDbContext(options))
            {
                await context.AddAsync(testEntity);

                await context.SaveChangesAsync();
            }

            // Act
            bool result;

            using (var context = new WaasDbContext(options))
            {
                var testRepository = new BaseDomainService <ScrapeJob, long>(context);
                await testRepository.DeleteAsync(testEntity.Id);

                result = await context.CommitAsync();
            }

            // Assert
            Assert.True(result);
            using (var context = new WaasDbContext(options))
            {
                Assert.Null(await context.ScrapeJobs.FindAsync(testEntity.Id));
            }
        }
Пример #2
0
        public async Task GetAllSucceeds()
        {
            // Arrange
            var options = GetTestDbContextOptions("GetAll_ScrapeJob_Database");

            const int count          = 100;
            var       testScrapeJobs = Enumerable.Range(1, count).Select(e => GenerateTestEntity(e)).ToArray();

            using (var context = new WaasDbContext(options))
            {
                foreach (ScrapeJob scrapeJob in testScrapeJobs)
                {
                    await context.AddAsync(scrapeJob);
                }
                await context.SaveChangesAsync();
            }

            // Act
            using (var context = new WaasDbContext(options))
            {
                var testRepository = new BaseDomainService <ScrapeJob, long>(context);
                var result         = testRepository.GetAll();

                Assert.Equal(count, await result.CountAsync());
                Assert.Equal(testScrapeJobs.AsQueryable(), result);
            }
        }
Пример #3
0
        public async Task UpdateAsyncSucceeds()
        {
            // Arrange
            var options    = GetTestDbContextOptions("Update_ScrapeJob_Database");
            var testEntity = GenerateTestEntity();

            using (var context = new WaasDbContext(options))
            {
                await context.AddAsync(testEntity);

                await context.SaveChangesAsync();
            }

            // Act
            bool result;

            using (var context = new WaasDbContext(options))
            {
                var testRepository = new BaseDomainService <ScrapeJob, long>(context);
                await testRepository.UpdateAsync(testEntity.Id, job =>
                {
                    job.Pattern = "updatedPattern";
                    job.Url     = "updatedUrl";
                    job.Enabled = !testEntity.Enabled;
                });

                result = await context.CommitAsync();
            }

            // Assert
            Assert.True(result);
            using (var context = new WaasDbContext(options))
            {
                var updatedEntity = await context.ScrapeJobs.FindAsync(testEntity.Id);

                Assert.NotEqual(testEntity.Pattern, updatedEntity.Pattern);
                Assert.NotEqual(testEntity.Url, updatedEntity.Url);
                Assert.NotEqual(testEntity.Enabled, updatedEntity.Enabled);
            }
        }
Пример #4
0
        public async Task GetAsyncSucceeds()
        {
            // Arrange
            var options = GetTestDbContextOptions("Get_ScrapeJob_Database");

            var testEntity = GenerateTestEntity();

            using (var context = new WaasDbContext(options))
            {
                await context.AddAsync(testEntity);

                await context.SaveChangesAsync();
            }

            // Act
            using (var context = new WaasDbContext(options))
            {
                var testRepository = new BaseDomainService <ScrapeJob, long>(context);
                var result         = await testRepository.GetAsync(testEntity.Id);

                // Assert
                Assert.Equal(testEntity, result);
            }
        }