当前位置: 首页>>代码示例>>C#>>正文


C# ChangeTrackingCollection.Remove方法代码示例

本文整理汇总了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);
        }
开发者ID:hflorin,项目名称:annotator,代码行数:25,代码来源:ChangeTrackingCollectionPropertyTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:23,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:17,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:22,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:16,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:21,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:17,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:15,代码来源:ChangeTrackingCollectionTests.cs

示例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);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:17,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:17,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:17,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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());
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:20,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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());
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:24,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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());
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:23,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例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());
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:18,代码来源:ChangeTrackingCollectionWithChildrenTests.cs


注:本文中的ChangeTrackingCollection.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。