protected void CreateItemsTest() { // Arrange var listToAdd = SubEntities.GetRange(1, 3); // Act SubItemRepository.AddRange(listToAdd); var actual = UnitOfWork.SaveChanges(); // Assert Assert.AreEqual(EntityCount * 3, actual); }
protected void DeleteRangeTest(string propertyName) { // Arrange var itemsToDelete = SubEntities.GetRange(1, 2); var valueToMatch1 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[1]); var valueToMatch2 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[2]); var valueToMatch3 = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(SubEntities[3]); // Act SubItemRepository.RemoveRange(itemsToDelete); var actual = UnitOfWork.SaveChanges(); var remainingItems = SubItemRepository.GetAll().ToList(); var found1 = false; var found2 = false; var found3 = false; foreach (var remainingItem in remainingItems) { var value = typeof(TSubEntity).GetProperty(propertyName)?.GetValue(remainingItem); if (value != null && value.Equals(valueToMatch1)) { found1 = true; } if (value != null && value.Equals(valueToMatch2)) { found2 = true; } if (value != null && value.Equals(valueToMatch3)) { found3 = true; } } // Assert Assert.AreEqual(2, actual); Assert.IsFalse(found1); Assert.IsFalse(found2); Assert.IsTrue(found3); }