本文整理汇总了C#中ChangeTrackingCollection.MergeChanges方法的典型用法代码示例。如果您正苦于以下问题:C# ChangeTrackingCollection.MergeChanges方法的具体用法?C# ChangeTrackingCollection.MergeChanges怎么用?C# ChangeTrackingCollection.MergeChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChangeTrackingCollection
的用法示例。
在下文中一共展示了ChangeTrackingCollection.MergeChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhenISubmitPostToCreateAnEntity
public void WhenISubmitPostToCreateAnEntity()
{
ScenarioContext.Current.Pending();
var customer = ScenarioContext.Current.Get<Customer>("Customer");
var changeTracker = new ChangeTrackingCollection<Customer>(true) { customer };
Customer result = _client.CreateEntity(customer);
changeTracker.MergeChanges(result);
}
示例2: MergeChanges_Should_Set_ModifiedProperties_To_Null_For_Modified_Order_With_Updated_Customer
public void MergeChanges_Should_Set_ModifiedProperties_To_Null_For_Modified_Order_With_Updated_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder);
origOrder.CustomerId = "ALFKI";
var origModifiedProps = origOrder.ModifiedProperties;
var updatedOrder = UpdateOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Contains("CustomerId", origModifiedProps);
Assert.Null(origOrder.ModifiedProperties);
}
示例3: MergeChanges_Should_Set_TrackingState_To_Unchanged_For_Modified_Order_With_Updated_Customer
public void MergeChanges_Should_Set_TrackingState_To_Unchanged_For_Modified_Order_With_Updated_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder);
origOrder.CustomerId = "ALFKI";
TrackingState origTrackingState = origOrder.TrackingState;
var updatedOrder = UpdateOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Equal(TrackingState.Modified, origTrackingState);
Assert.Equal(TrackingState.Unchanged, origOrder.TrackingState);
}
示例4: MergeChanges_Should_Set_Properties_For_Modified_Order_With_Updated_Customer
public void MergeChanges_Should_Set_Properties_For_Modified_Order_With_Updated_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder);
origOrder.CustomerId = "ALFKI";
var updatedOrder = UpdateOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.AreEqual(updatedOrder.CustomerId, origOrder.CustomerId);
Assert.AreEqual(updatedOrder.Customer.CustomerId, origOrder.Customer.CustomerId);
Assert.AreEqual(updatedOrder.OrderDate, origOrder.OrderDate);
}
示例5: MergeChanges_On_Equatable_PromotionalProduct_Should_Not_Throw_ArgumentException
public void MergeChanges_On_Equatable_PromotionalProduct_Should_Not_Throw_ArgumentException()
{
// Arrange
var product = new MockNorthwind().Products.OfType<PromotionalProduct>().First();
var changeTracker = new ChangeTrackingCollection<PromotionalProduct>(product);
var clonedProduct = product.Clone();
// Act
changeTracker.MergeChanges(clonedProduct);
// Assert
Assert.True(true);
}
示例6: MergeChanges_On_Equatable_Customer_Should_Not_Throw_ArgumentException
public void MergeChanges_On_Equatable_Customer_Should_Not_Throw_ArgumentException()
{
// Arrange
var customer = new Customer { CustomerId = "ALFKI" };
var changeTracker = new ChangeTrackingCollection<Customer>(customer);
// Act
changeTracker.MergeChanges();
// Assert
Assert.True(true);
}
示例7: MergeChanges_Should_Merge_Updates_For_Unchanged_Employee_With_Changed_Territories
public void MergeChanges_Should_Merge_Updates_For_Unchanged_Employee_With_Changed_Territories()
{
// Arrange
var database = new MockNorthwind();
var employee = database.Employees[0];
var unchangedTerritory = employee.Territories[0];
var modifiedTerritory = employee.Territories[1];
var deletedTerritory = employee.Territories[2];
var addedExistingTerritory = database.Territories[3];
var area1 = new Area { AreaId = 1, AreaName = "Northern", Territories = new ChangeTrackingCollection<Territory> { unchangedTerritory } };
var area2 = new Area { AreaId = 2, AreaName = "Southern", Territories = new ChangeTrackingCollection<Territory> { modifiedTerritory } };
var area3 = new Area { AreaId = 3, AreaName = "Eastern", Territories = new ChangeTrackingCollection<Territory> { deletedTerritory } };
var area4 = new Area { AreaId = 4, AreaName = "Western", Territories = new ChangeTrackingCollection<Territory> { addedExistingTerritory } };
var addedNewTerritory = new Territory
{
TerritoryId = "91360",
TerritoryDescription = "SouthernCalifornia",
Employees = new ChangeTrackingCollection<Employee> { employee },
AreaId = 5,
TrackingState = TrackingState.Added // Must explicitly mark as added
};
unchangedTerritory.Area = area1;
unchangedTerritory.AreaId = area1.AreaId;
modifiedTerritory.Area = area2;
modifiedTerritory.AreaId = area2.AreaId;
deletedTerritory.Area = area3;
deletedTerritory.AreaId = area3.AreaId;
addedExistingTerritory.Area = area4;
addedExistingTerritory.AreaId = area4.AreaId;
var changeTracker = new ChangeTrackingCollection<Employee>(employee);
modifiedTerritory.TerritoryDescription = "xxx"; // mod prop
modifiedTerritory.AreaId = 6; // mod FK prop
employee.Territories.Remove(deletedTerritory); // should mark area deleted
employee.Territories.Add(addedExistingTerritory); // should keep area unchanged
employee.Territories.Add(addedNewTerritory); // should keep territory added
addedExistingTerritory.Area.AreaName = "zzz"; // should mark area modified
var changes = changeTracker.GetChanges(); // should exclude unchanged territory
var updatedEmployee = UpdateEmployeesWithTerritories(changes)[0]; // rel entities, db-gen vals
// Act
changeTracker.MergeChanges(updatedEmployee);
// Assert
Assert.Contains(unchangedTerritory, employee.Territories); // Unchanged present
Assert.Equal("zzz", addedExistingTerritory.Area.AreaName); // Area name updated
Assert.Equal("yyy", addedNewTerritory.Data); // Db-generated value set
Assert.Equal(addedNewTerritory.AreaId, addedNewTerritory.Area.AreaId); // Added territory Area set
Assert.Equal(modifiedTerritory.AreaId, modifiedTerritory.Area.AreaId); // Modified territory Area set
Assert.Same(addedExistingTerritory, employee.Territories.Single(t => t.TerritoryId == "02116")); // Ref equality
Assert.Same(addedNewTerritory, employee.Territories.Single(t => t.TerritoryId == "91360")); // Ref equality
Assert.Same(modifiedTerritory, employee.Territories.Single(t => t.TerritoryId == "01730")); // Ref equality
Assert.DoesNotContain(deletedTerritory, employee.Territories); // Detail deleted
ICollection cachedDeletes = ((ITrackingCollection)employee.Territories).GetChanges(true);
Assert.Empty(cachedDeletes); // Cached deletes have been removed
}
示例8: MergeChanges_Should_Set_Order_With_Modified_Customer_With_Db_Generated_Values
public void MergeChanges_Should_Set_Order_With_Modified_Customer_With_Db_Generated_Values()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
var customer = order.Customer;
var name = customer.CustomerName = "xxx";
var changes = changeTracker.GetChanges();
var updatedOrder = changes[0].Clone<Order>();
var data = updatedOrder.Customer.Data = "yyy"; // simulate db-generated values
updatedOrder.AcceptChanges();
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Equal(name, order.Customer.CustomerName);
Assert.Equal(data, order.Customer.Data);
}
示例9: MergeChanges_Should_Set_Modified_Customer_With_Unchanged_Setting
public void MergeChanges_Should_Set_Modified_Customer_With_Unchanged_Setting()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var customer = order.Customer;
customer.CustomerSetting = new CustomerSetting
{
CustomerId = customer.CustomerId,
Customer = customer,
Setting = "Setting1"
};
var changeTracker = new ChangeTrackingCollection<Order>(order);
var name = customer.CustomerName = "xxx";
var origState = customer.TrackingState;
var changes = changeTracker.GetChanges();
var changedCustomer = changes[0].Customer;
var updatedOrder = changes[0].Clone<Order>();
updatedOrder.AcceptChanges();
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Equal(name, customer.CustomerName); // Changed customer name is preserved
Assert.Null(changedCustomer.CustomerSetting); // GetChanges sets unchanges ref props to null
Assert.NotNull(order.Customer.CustomerSetting); // Unchanged ref props not overwritten
Assert.Equal(TrackingState.Modified, origState); // Changed state is modified
Assert.Equal(TrackingState.Unchanged, customer.TrackingState); // State set to unchanged
}
示例10: MergeChanges_Should_Merge_Updates_For_Unchanged_Order_With_Changed_OrderDetails
public void MergeChanges_Should_Merge_Updates_For_Unchanged_Order_With_Changed_OrderDetails()
{
// Arrange
var database = new MockNorthwind();
var origOrder = database.Orders[0];
var product = database.Products.Single(p => p.ProductId == 14);
origOrder.OrderDetails.Add(new OrderDetail { ProductId = 14, OrderId = 10249, Quantity = 9, UnitPrice = 18.6000M, Product = product });
var unchangedDetail = origOrder.OrderDetails[0];
var modifiedDetail = origOrder.OrderDetails[1];
var deletedDetail = origOrder.OrderDetails[3];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder);
origOrder.OrderDetails[1].Product.ProductName = "xxx";
origOrder.OrderDetails[2].Quantity++;
origOrder.OrderDetails[2].ProductId = 1;
var newUnitPrice = origOrder.OrderDetails[2].UnitPrice + 1;
origOrder.OrderDetails.RemoveAt(3);
var addedDetail = new OrderDetail {ProductId = 51, OrderId = 10249, Quantity = 40, UnitPrice = 42.4000M};
origOrder.OrderDetails.Add(addedDetail);
var changes = changeTracker.GetChanges();
var updatedOrder = UpdateOrdersWithDetails(database, changes)[0];
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Contains(unchangedDetail, origOrder.OrderDetails); // Unchanged present
Assert.Equal("xxx", origOrder.OrderDetails[1].Product.ProductName); // Prod name updated
Assert.Equal(updatedOrder.OrderDetails[1].ProductId, origOrder.OrderDetails[2].Product.ProductId); // Changed Product set
Assert.Equal(newUnitPrice, origOrder.OrderDetails[2].UnitPrice); // Db-generated value set
Assert.Equal(updatedOrder.OrderDetails[2].Product.ProductId, origOrder.OrderDetails[3].Product.ProductId); // Added detail Product set
Assert.True(origOrder.OrderDetails.All(d => d.TrackingState == TrackingState.Unchanged)); // Details unchanged
Assert.Same(addedDetail, origOrder.OrderDetails.Single(d => d.ProductId == 51)); // Ref equality
Assert.Same(modifiedDetail, origOrder.OrderDetails.Single(d => d.ProductId == 42)); // Ref equality
Assert.DoesNotContain(deletedDetail, origOrder.OrderDetails); // Detail deleted
ICollection cachedDeletes = ((ITrackingCollection)origOrder.OrderDetails).GetChanges(true);
Assert.Empty(cachedDeletes); // Cached deletes have been removed
}
示例11: MergeChanges_Should_Set_Modified_Order_With_Unchanged_Customer
public void MergeChanges_Should_Set_Modified_Order_With_Unchanged_Customer()
{
// Arrange
var database = new MockNorthwind();
var order = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(order);
var date = order.OrderDate = order.OrderDate.AddDays(1);
var origState = order.TrackingState;
var changes = changeTracker.GetChanges();
var changedOrder = changes[0];
var updatedOrder = changes[0].Clone<Order>();
updatedOrder.AcceptChanges();
// Act
changeTracker.MergeChanges(updatedOrder);
// Assert
Assert.Equal(date, order.OrderDate); // Changed order date is preserved
Assert.Null(changedOrder.Customer); // GetChanges sets unchanges ref props to null
Assert.NotNull(order.Customer); // Unchanged order.Customer is not overwritten
Assert.Equal(TrackingState.Modified, origState); // Changed state is modified
Assert.Equal(TrackingState.Unchanged, order.TrackingState); // State set to unchanged
}
示例12: MergeChanges_Should_Set_Properties_For_Multiple_Modified_Orders_With_Updated_Customer
public void MergeChanges_Should_Set_Properties_For_Multiple_Modified_Orders_With_Updated_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder1 = database.Orders[0];
var origOrder2 = database.Orders[1];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder1, origOrder2);
origOrder1.CustomerId = "ALFKI";
origOrder2.CustomerId = "ANATR";
var updatedOrders = UpdateOrders(database, origOrder1, origOrder2);
// Act
changeTracker.MergeChanges(updatedOrders.ToArray());
// Assert
Assert.Equal(updatedOrders[0].CustomerId, origOrder1.CustomerId);
Assert.Equal(updatedOrders[0].Customer.CustomerId, origOrder1.Customer.CustomerId);
Assert.Equal(updatedOrders[0].OrderDate, origOrder1.OrderDate);
Assert.Equal(updatedOrders[1].CustomerId, origOrder2.CustomerId);
Assert.Equal(updatedOrders[1].Customer.CustomerId, origOrder2.Customer.CustomerId);
Assert.Equal(updatedOrders[1].OrderDate, origOrder2.OrderDate);
}
示例13: MergeChanges_Should_Set_TrackingState_To_Unchanged_For_Added_Order_With_Null_Customer
public void MergeChanges_Should_Set_TrackingState_To_Unchanged_For_Added_Order_With_Null_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = new PriorityOrder
{
PriorityPlan = "Silver",
OrderDate = DateTime.Parse("1996-07-04"),
CustomerId = "ALFKI"
};
var changeTracker = new ChangeTrackingCollection<Order>(true) { origOrder };
var addedOrder = AddOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(addedOrder);
// Assert
Assert.Equal(addedOrder.CustomerId, origOrder.CustomerId);
Assert.Equal(addedOrder.Customer.CustomerId, origOrder.Customer.CustomerId);
Assert.Equal(addedOrder.OrderDate, origOrder.OrderDate);
}
示例14: MergeChanges_Should_Set_ChangeTracker_For_Modified_Order_With_Updated_Customer
public void MergeChanges_Should_Set_ChangeTracker_For_Modified_Order_With_Updated_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = database.Orders[0];
var changeTracker = new ChangeTrackingCollection<Order>(origOrder);
origOrder.CustomerId = "ALFKI";
var updatedOrder = UpdateOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(updatedOrder);
TrackingState origTrackingState = origOrder.Customer.TrackingState;
origOrder.Customer.CustomerName = "xxx";
// Assert
Assert.AreEqual(TrackingState.Unchanged, origTrackingState);
Assert.AreEqual(TrackingState.Modified, origOrder.Customer.TrackingState);
Assert.Contains("CustomerName", (ICollection)origOrder.Customer.ModifiedProperties);
}
示例15: MergeChanges_Should_Set_Properties_For_Added_Order_With_Null_Customer
public void MergeChanges_Should_Set_Properties_For_Added_Order_With_Null_Customer()
{
// Arrange
var database = new MockNorthwind();
var origOrder = new Order
{
OrderDate = DateTime.Parse("1996-07-04"),
CustomerId = "ALFKI"
};
var changeTracker = new ChangeTrackingCollection<Order>(true) {origOrder};
TrackingState origTrackingState = origOrder.TrackingState;
var addedOrder = AddOrders(database, origOrder)[0];
// Act
changeTracker.MergeChanges(addedOrder);
// Assert
Assert.Equal(TrackingState.Added, origTrackingState);
Assert.Equal(TrackingState.Unchanged, origOrder.TrackingState);
}