Exemplo n.º 1
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);
            }
        }
        public virtual async Task <IActionResult> Update([FromBody] T entity)
        {
            await Service.UpdateAsync(entity);

            return(Successful());
        }