public void AddRangeAddsRange(List <MockPoco> input) { // Arrange var testSettings = new TestProjectSettings(); DbContext testContext = null; Repository <MockPoco> tested = null; try { testContext = new MockPocoContext(testSettings); tested = new Repository <MockPoco>(testContext); testContext.Database.EnsureCreated(); // Act testContext.AddRange(input); testContext.SaveChanges(); // Assert Assert.Equal(input.Count, testContext.Set <MockPoco>().Count()); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void PredicateGetAllReturnsAccurateResult(List <MockPoco> input) { // Arrange var testSettings = new TestProjectSettings(); var inputList = input.ToList(); DbContext testContext = null; Repository <MockPoco> tested = null; var predicate = new Func <MockPoco, bool>(x => x.Value == "test3"); var expected = input.Where(predicate); try { testContext = new MockPocoContext(testSettings); tested = new Repository <MockPoco>(testContext); testContext.Database.EnsureCreated(); testContext.AddRange(inputList); testContext.SaveChanges(); // Act var actual = tested.GetAll(x => predicate(x)); // Assert Assert.Equal(expected, actual); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void UpdateUpdates(MockPoco input) { // Arrange const string expected = "newValue1"; var testSettings = new TestProjectSettings(); DbContext testContext = null; Repository <MockPoco> tested = null; try { testContext = new MockPocoContext(testSettings); tested = new Repository <MockPoco>(testContext); testContext.Database.EnsureCreated(); testContext.Add(input); testContext.SaveChanges(); // Act input.Value = expected; testContext.SaveChanges(); // Assert Assert.Equal(input.Value, testContext.Set <MockPoco>().First().Value); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public void CountReturnsAccurateCount(List <MockPoco> input) { // Arrange var testSettings = new TestProjectSettings(); var inputList = input.ToList(); DbContext testContext = null; Repository <MockPoco> tested = null; var expected = input.Count; try { testContext = new MockPocoContext(testSettings); tested = new Repository <MockPoco>(testContext); testContext.Database.EnsureCreated(); testContext.AddRange(inputList); testContext.SaveChanges(); // Act var actual = tested.Count(); // Assert Assert.Equal(expected, actual); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }