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 Update_MultipleEntities_EntitiesUpdated() { using var dbContextProvider = new AnyDbContextProvider(nameof(Update_MultipleEntities_EntitiesUpdated)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); dbContextProvider.Mock(new AnyEntity { Id = 1, AnyString = "AnyString" }, new AnyEntity { Id = 2, AnyString = "AnyString" }); var expected = new[] { new AnyEntity { Id = 1, AnyString = "AnyNewString" }, new AnyEntity { Id = 2, AnyString = "AnyNewString" } }; await repository.Update(expected); var actual = repository.Get(1, 2); await repository.SaveChanges(); actual.Should().BeEquivalentTo(expected); }
public async Task Create_AnyEntity_EntityCreated() { using var dbContextProvider = new AnyDbContextProvider(nameof(Create_AnyEntity_EntityCreated)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); var expected = new AnyEntity { AnyString = "AnyString" }; await repository.Create(expected); await repository.SaveChanges(); var actual = repository.GetAll(); actual.Single().AnyString.Should().Be(expected.AnyString); }
public async Task Update_ExistingEntity_EntityUpdated() { using var dbContextProvider = new AnyDbContextProvider(nameof(Update_ExistingEntity_EntityUpdated)); var repository = new AnyRepository(dbContextProvider.DbContext, _logger); dbContextProvider.Mock(new AnyEntity { Id = 1, AnyString = "AnyString" }); var expected = new AnyEntity { Id = 1, AnyString = "AnyNewString" }; await repository.Update(expected); var actual = repository.Get(1); await repository.SaveChanges(); actual.Single().Should().BeEquivalentTo(expected); }