本文整理汇总了C#中ChangeTrackingCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ChangeTrackingCollection.Remove方法的具体用法?C# ChangeTrackingCollection.Remove怎么用?C# ChangeTrackingCollection.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChangeTrackingCollection
的用法示例。
在下文中一共展示了ChangeTrackingCollection.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShoudNotTrackRemovedItemAsModified
public void ShoudNotTrackRemovedItemAsModified()
{
var wordToAdd = new WordWrapper(new Word());
var collection = new ChangeTrackingCollection<WordWrapper>(words);
Assert.AreEqual(2, collection.Count);
Assert.IsFalse(collection.IsChanged);
collection.Add(wordToAdd);
Assert.AreEqual(3, collection.Count);
Assert.AreEqual(1, collection.AddedItems.Count);
Assert.AreEqual(0, collection.RemovedItems.Count);
Assert.AreEqual(0, collection.ModifiedItems.Count);
Assert.AreEqual(wordToAdd, collection.AddedItems.First());
Assert.IsTrue(collection.IsChanged);
collection.Remove(wordToAdd);
Assert.AreEqual(2, collection.Count);
Assert.AreEqual(0, collection.AddedItems.Count);
Assert.AreEqual(0, collection.RemovedItems.Count);
Assert.AreEqual(0, collection.ModifiedItems.Count);
Assert.IsFalse(collection.IsChanged);
}
示例2: Removed_Added_Items_Should_Be_Marked_As_Unchanged
public void Removed_Added_Items_Should_Be_Marked_As_Unchanged()
{
// Arrange
var database = new MockNorthwind();
var changeTracker = new ChangeTrackingCollection<Product>();
changeTracker.Tracking = true;
var product = new Product
{
ProductId = 100,
ProductName = "Test Beverage",
CategoryId = 1,
Category = database.Categories[0],
UnitPrice = 10M
};
// Act
changeTracker.Add(product);
product.UnitPrice++;
changeTracker.Remove(product);
// Assert
Assert.AreEqual(TrackingState.Unchanged, product.TrackingState);
}
示例3: Added_Parent_Then_Removed_Should_Have_Children_Marked_As_Unchanged
public void Added_Parent_Then_Removed_Should_Have_Children_Marked_As_Unchanged()
{
// Arrange
var database = new MockNorthwind();
var changeTracker = new ChangeTrackingCollection<Order>(true);
var order = database.Orders[0];
var orderDetails = (IList<OrderDetail>)order.OrderDetails;
var orderDetail = orderDetails[0];
// Act
changeTracker.Add(order);
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Unchanged, order.TrackingState);
Assert.Equal(TrackingState.Unchanged, orderDetail.TrackingState);
}
示例4: GetChanges_Should_Return_Added_Modified_Deleted_Items
public void GetChanges_Should_Return_Added_Modified_Deleted_Items()
{
// Arrange
var database = new MockNorthwind();
var addedProduct = database.Products[0];
var updatedProduct = database.Products[1];
var deletedProduct = database.Products[2];
var changeTracker = new ChangeTrackingCollection<Product>(updatedProduct, deletedProduct);
changeTracker.Add(addedProduct);
updatedProduct.UnitPrice++;
changeTracker.Remove(deletedProduct);
// Act
var changes = changeTracker.GetChanges();
// Assert
Assert.AreEqual(TrackingState.Added, changes.ElementAt(1).TrackingState);
Assert.AreEqual(TrackingState.Modified, changes.ElementAt(0).TrackingState);
Assert.AreEqual(TrackingState.Deleted, changes.ElementAt(2).TrackingState);
}
示例5: Removed_Items_Should_NOT_Disable_Change_Tracking_On_Related_Entities_OneToMany_ToOne
public void Removed_Items_Should_NOT_Disable_Change_Tracking_On_Related_Entities_OneToMany_ToOne()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var product = order.OrderDetails[0].Product;
var changeTracker = new ChangeTrackingCollection<Order>(order);
changeTracker.Remove(order);
// Act
product.ProductName = "XXX";
// Assert
Assert.AreEqual(TrackingState.Modified, product.TrackingState);
}
示例6: Removed_Items_Should_NOT_Disable_Change_Tracking_On_Related_Entities_OneToOne
public void Removed_Items_Should_NOT_Disable_Change_Tracking_On_Related_Entities_OneToOne()
{
// Arrange
var database = new MockNorthwind();
var customer = database.Orders[0].Customer;
var setting = customer.CustomerSetting = new CustomerSetting
{
CustomerId = customer.CustomerId,
Customer = customer,
Setting = "Setting1"
};
var changeTracker = new ChangeTrackingCollection<Customer>(customer);
changeTracker.Remove(customer);
// Act
setting.Setting = "XXX";
// Assert
Assert.AreEqual(TrackingState.Modified, setting.TrackingState);
}
示例7: Removed_Items_Should_Disable_Change_Tracking_On_Related_Entities_OneToMany
public void Removed_Items_Should_Disable_Change_Tracking_On_Related_Entities_OneToMany()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var detail = order.OrderDetails[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
changeTracker.Remove(order);
detail.TrackingState = TrackingState.Unchanged;
// Act
detail.Quantity++;
// Assert
Assert.AreEqual(TrackingState.Unchanged, detail.TrackingState);
}
示例8: Removed_Existing_Modified_Items_Should_Not_Have_ModifiedProperties
public void Removed_Existing_Modified_Items_Should_Not_Have_ModifiedProperties()
{
// Arrange
var database = new MockNorthwind();
var changeTracker = new ChangeTrackingCollection<Product>(database.Products[0]);
var product = changeTracker[0];
product.UnitPrice++;
// Act
changeTracker.Remove(product);
// Assert
Assert.IsTrue(product.ModifiedProperties == null
|| product.ModifiedProperties.Count == 0);
}
示例9: Existing_Parent_Removed_With_Modified_Children_Should_Have_Children_Modified_Properties_Cleared
public void Existing_Parent_Removed_With_Modified_Children_Should_Have_Children_Modified_Properties_Cleared()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var orderDetails = (IList<OrderDetail>)order.OrderDetails;
var orderDetail = orderDetails[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
orderDetail.Quantity++;
// Act
changeTracker.Remove(order);
// Assert
Assert.True(orderDetail.ModifiedProperties == null
|| orderDetail.ModifiedProperties.Count == 0);
}
示例10: Existing_Parent_Removed_With_Modified_Children_Should_Have_Children_Marked_As_Deleted
public void Existing_Parent_Removed_With_Modified_Children_Should_Have_Children_Marked_As_Deleted()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var orderDetails = (IList<OrderDetail>)order.OrderDetails;
var orderDetail = orderDetails[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
orderDetail.Quantity++;
// Act
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Deleted, order.TrackingState);
Assert.Equal(TrackingState.Deleted, orderDetail.TrackingState);
}
示例11: Existing_Order_Removed_With_Modified_Customer_Has_Children_ModifiedProperties_Cleared
public void Existing_Order_Removed_With_Modified_Customer_Has_Children_ModifiedProperties_Cleared()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
var modifiedCustomer = order.Customer;
modifiedCustomer.CustomerName = "xxx";
order.OrderDetails[0].ModifiedProperties = new List<string> { "UnitPrice "};
// Act
changeTracker.Remove(order);
// Assert
Assert.True(modifiedCustomer.ModifiedProperties.Count == 1);
Assert.True(order.OrderDetails[0].ModifiedProperties == null);
}
示例12: Removed_Order_With_Removed_Customer_Should_Mark_Customer_As_Unchanged
public void Removed_Order_With_Removed_Customer_Should_Mark_Customer_As_Unchanged()
{
// NOTE: Removed customer will not be marked as deleted. Instead to be deleted
// it must be independently marked as deleted.
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
var customer = order.Customer;
order.Customer = null;
// Act
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Deleted, order.TrackingState);
Assert.Equal(TrackingState.Unchanged, customer.TrackingState);
Assert.True(order.HasChanges());
}
示例13: Removed_Order_With_Manually_Added_Customer_Should_Mark_Customer_As_Added
public void Removed_Order_With_Manually_Added_Customer_Should_Mark_Customer_As_Added()
{
// NOTE: Manually marking reference as added will create a new entity
// when it is saved.
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
order.Customer = new Customer
{
CustomerId = "ABCD",
CustomerName = "Test",
TrackingState = TrackingState.Added
};
// Act
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Deleted, order.TrackingState);
Assert.Equal(TrackingState.Added, order.Customer.TrackingState);
Assert.True(order.HasChanges());
}
示例14: Removed_Order_With_New_Customer_Should_Mark_Customer_As_Unchanged
public void Removed_Order_With_New_Customer_Should_Mark_Customer_As_Unchanged()
{
// NOTE: Setting Order.Customer to null will not mark customer as deleted.
// Because customer not marked as deleted, it refers to an existing customer.
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
order.Customer = new Customer
{
CustomerId = "ABCD",
CustomerName = "Test"
};
// Act
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Deleted, order.TrackingState);
Assert.Equal(TrackingState.Unchanged, order.Customer.TrackingState);
Assert.True(order.HasChanges());
}
示例15: Removed_Order_With_Modified_Customer_Should_Mark_Customer_As_Modified
public void Removed_Order_With_Modified_Customer_Should_Mark_Customer_As_Modified()
{
// NOTE: Modified reference entity will remain modified if parent is deleted.
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
order.Customer.CustomerName = "xxx";
// Act
changeTracker.Remove(order);
// Assert
Assert.Equal(TrackingState.Deleted, order.TrackingState);
Assert.Equal(TrackingState.Modified, order.Customer.TrackingState);
Assert.True(order.HasChanges());
}