public async Task Create_MultipleEntities_CreatesEntities() { using var dbContextProvider = new AnyDbContextProvider(nameof(Create_MultipleEntities_CreatesEntities)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); var expected = new[] { new AnyEntity { AnyString = "FirstEntity" }, new AnyEntity { AnyString = "SecondEntity" } }; await repository.Create(expected); await repository.SaveChanges(); var actual = repository.GetAll(); actual.First().AnyString.Should().Be(expected.First().AnyString); actual.Last().AnyString.Should().BeEquivalentTo(expected.Last().AnyString); }
public async Task Delete_MultipleEntities_EntitiesDeleted() { using var dbContextProvider = new AnyDbContextProvider(nameof(Delete_MultipleEntities_EntitiesDeleted)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); var entities = new[] { new AnyEntity { Id = 1, AnyString = "AnyString" }, new AnyEntity { Id = 2, AnyString = "AnyString" }, new AnyEntity { Id = 3, AnyString = "AnyString" } }; dbContextProvider.Mock(entities); await repository.Delete(1, 2); await repository.SaveChanges(); var actual = repository.GetAll(); actual.Single().Should().BeEquivalentTo(entities.Last()); }
public async Task Delete_ExistingEntityWithAutoSave_EntityDeleted() { using var dbContextProvider = new AnyDbContextProvider(nameof(Delete_ExistingEntity_EntityDeleted)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger) { AutoSave = true }; var entities = new[] { new AnyEntity { Id = 1, AnyString = "AnyString" }, new AnyEntity { Id = 2, AnyString = "AnyString" } }; dbContextProvider.Mock(entities); await repository.Delete(1); var actual = repository.GetAll(); actual.Single().Should().BeEquivalentTo(entities.Last()); }
public async Task Create_AnyEntityWithAutoSave_EntityCreated() { using var dbContextProvider = new AnyDbContextProvider(nameof(Create_AnyEntityWithAutoSave_EntityCreated)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); var expected = new AnyEntity { AnyString = "AnyString" }; repository.AutoSave = true; await repository.Create(expected); var actual = repository.GetAll(); actual.Single().AnyString.Should().Be(expected.AnyString); }