public async Task SaveAsync_IncludesTag() { var tag1 = new Tag { Id = 1 }; SeedDbWith(tag1); var mutatedTag = new Tag { Id = 1, Color = "other_color" }; var item1 = new DataSeries { TagId = 1, Tag = mutatedTag, }; await dataService.SaveAsync(item1); using var context = new PlappDbContext(options); Assert.IsTrue(context.Set <Tag>().Count() == 1); var resultTag = context.Set <Tag>().FirstOrDefault(t => t.Id == 1); Assert.IsNotNull(resultTag); resultTag.Should().BeEquivalentTo(mutatedTag); }
public async Task SaveAllAsync_IdsAreZero_AddsThemWithNewIds() { var item1 = CreateStub(id: 0); var item2 = CreateStub(id: 0); await dataService.SaveAllAsync(new List <T>() { item1, item2 }); using var context = new PlappDbContext(options); context.Set <T>().Should().HaveCount(2); context.Set <T>().Should().NotContain(item => item.Id == 0); }
public async Task SaveAsync_EntityExists_UpdatesIt() { var item1 = CreateStub(id: 1); SeedDbWith(item1); var mutatedItem = AlteredCopy(item1); await dataService.SaveAsync(mutatedItem); using var context = new PlappDbContext(options); context.Set <T>().Should().HaveCount(1); context.Set <T>().Should().ContainEquivalentOf(mutatedItem); }
protected void SeedDb(IEnumerable <T> stubs) { using var context = new PlappDbContext(options); context.Set <T>().AddRange(stubs); var c = context.SaveChanges(); }
protected void SeedDbWith <TOther>(params TOther[] stubs) where TOther : DomainObject { using var context = new PlappDbContext(options); context.Set <TOther>().AddRange(stubs); context.SaveChanges(); }
public async Task DeleteAsync_ById_EntityDoesNotExist_Noop() { await dataService.DeleteAsync(1); using var context = new PlappDbContext(options); context.Set <T>().Should().BeEmpty(); }
public async Task SaveAllAsync_OneNew_OneExisting_TwoItemsInDb() { var item1 = CreateStub(id: 1); SeedDbWith(item1); var mutatedItem = AlteredCopy(item1); var item2 = AlteredCopy(CreateStub(id: 0)); await dataService.SaveAllAsync(new List <T>() { mutatedItem, item2 }); using var context = new PlappDbContext(options); context.Set <T>().Should().HaveCount(2); context.Set <T>().Should().ContainEquivalentOf(mutatedItem); context.Set <T>().Should().ContainEquivalentOf(item2); }
public async Task DeleteAsync_ByEntity_EntityDoesNotExist_Noop() { var item1 = CreateStub(id: 1); await dataService.DeleteAsync(item1); using var context = new PlappDbContext(options); context.Set <T>().Should().BeEmpty(); }
public async Task DeleteAsync_ByEntity_EntityExists_DeletesIt() { var item1 = CreateStub(id: 1); SeedDbWith(item1); await dataService.DeleteAsync(item1); using var context = new PlappDbContext(options); context.Set <T>().Should().NotContain(item => item.Id == 1); }
public async Task SaveAsync_IncludesDataPoints() { var item1 = new DataSeries { DataPoints = new Collection <DataPoint>() { new DataPoint { Value = 1 }, new DataPoint { Value = 2 }, } }; await dataService.SaveAsync(item1); using var context = new PlappDbContext(options); Assert.IsTrue(context.Set <DataPoint>().Count() == 2); Assert.IsFalse(context.Set <DataPoint>().Any(item => item.Id == 0)); }
public async Task SaveAsync_IdIsZero_AddsItWithNewId() { var item1 = CreateStub(id: 0); await dataService.SaveAsync(item1); using var context = new PlappDbContext(options); var result = context.Set <T>(); result.Should().HaveCount(1); result.Should().NotContain(item => item.Id == 0); }