• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ChangeTrackingCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ChangeTrackingCollection的典型用法代码示例。如果您正苦于以下问题:C# ChangeTrackingCollection类的具体用法?C# ChangeTrackingCollection怎么用?C# ChangeTrackingCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ChangeTrackingCollection类属于命名空间,在下文中一共展示了ChangeTrackingCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Existing_Parent_With_Added_Children_Should_Have_Children_Marked_As_Added

        public void Existing_Parent_With_Added_Children_Should_Have_Children_Marked_As_Added()
        {
            // Arrange
            var database = new MockNorthwind();
            var order = database.Orders[0];
            var changeTracker = new ChangeTrackingCollection<Order>(order);
            var orderDetails = (IList<OrderDetail>)changeTracker[0].OrderDetails;
            var addedDetail1 = new OrderDetail
            {
                ProductId = 1,
                Product = database.Products[0],
                Quantity = 10,
                UnitPrice = 20M
            };
            var addedDetail2 = new OrderDetail
            {
                ProductId = 2,
                Product = database.Products[1],
                Quantity = 20,
                UnitPrice = 30M
            };

            // Act
            orderDetails.Add(addedDetail1);
            orderDetails.Add(addedDetail2);

            // Assert
            Assert.Equal(TrackingState.Added, addedDetail1.TrackingState);
            Assert.Equal(TrackingState.Added, addedDetail2.TrackingState);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:30,代码来源:ChangeTrackingCollectionWithChildrenTests.cs


示例3: Existing_Parent_With_Children_Should_Have_Children_Marked

        public void Existing_Parent_With_Children_Should_Have_Children_Marked()
        {
            // Arrange
            var database = new MockNorthwind();
            var order = database.Orders[0];
            var changeTracker = new ChangeTrackingCollection<Order>(order);
            var orderDetails = (IList<OrderDetail>)changeTracker[0].OrderDetails;
            var addedDetail = new OrderDetail
                {
                    ProductId = 1,
                    Product = database.Products[0],
                    Quantity = 10,
                    UnitPrice = 20M
                };
            var modifiedDetail = orderDetails[0];
            var deletedDetail = orderDetails[1];
            addedDetail.Order = order;
            modifiedDetail.Order = order;
            deletedDetail.Order = order;

            // Act
            modifiedDetail.UnitPrice++;
            orderDetails.Remove(deletedDetail);
            orderDetails.Add(addedDetail);

            // Assert
            Assert.Equal(TrackingState.Added, addedDetail.TrackingState);
            Assert.Equal(TrackingState.Modified, modifiedDetail.TrackingState);
            Assert.Equal(TrackingState.Deleted, deletedDetail.TrackingState);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:30,代码来源:ChangeTrackingCollectionWithChildrenTests.cs


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


示例5: Tracking_Should_Be_Disabled_With_Default_Ctor

        public void Tracking_Should_Be_Disabled_With_Default_Ctor()
        {
            // Arrange
            var database = new MockNorthwind();
            var product = database.Products[0];
            var changeTracker = new ChangeTrackingCollection<Product>();

            // Act
            changeTracker.Add(product);

            // Assert
            Assert.AreEqual(TrackingState.Unchanged, changeTracker[0].TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:13,代码来源:ChangeTrackingCollectionTests.cs


示例6: Items_Should_Be_Added_As_Unchanged_With_Enumerable_Ctor

        public void Items_Should_Be_Added_As_Unchanged_With_Enumerable_Ctor()
        {
            // Arrange
            var database = new MockNorthwind();
            var product = database.Products[0];
            var products = new List<Product> { product };

            // Act
            var changeTracker = new ChangeTrackingCollection<Product>(products);

            // Assert
            Assert.AreEqual(TrackingState.Unchanged, changeTracker[0].TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:13,代码来源:ChangeTrackingCollectionTests.cs


示例7: Tracking_Should_Be_Enabled_With_Array_Ctor

        public void Tracking_Should_Be_Enabled_With_Array_Ctor()
        {
            // Arrange
            var database = new MockNorthwind();
            var product = database.Products[1];

            // Act
            var changeTracker = new ChangeTrackingCollection<Product>(database.Products[0]);
            changeTracker.Add(product);

            // Assert
            Assert.AreEqual(TrackingState.Added, changeTracker[1].TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:13,代码来源:ChangeTrackingCollectionTests.cs


示例8: Added_Parent_With_Children_Should_Have_Children_Marked_As_Added

        public void Added_Parent_With_Children_Should_Have_Children_Marked_As_Added()
        {
            // Arrange
            var database = new MockNorthwind();
            var changeTracker = new ChangeTrackingCollection<Order>(true);
            var order = database.Orders[0];
            var orderDetails = (IList<OrderDetail>)order.OrderDetails;

            // Act
            changeTracker.Add(order);

            // Assert
            Assert.Equal(TrackingState.Added, order.TrackingState);
            Assert.Equal(TrackingState.Added, orderDetails[0].TrackingState);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:15,代码来源:ChangeTrackingCollectionWithChildrenTests.cs


示例9: AddEdgeViewModel

        public AddEdgeViewModel(Attribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            attribute.IsEditable = true;
            Attributes =
                new ChangeTrackingCollection<AttributeWrapper>(new List<AttributeWrapper>
                {
                    new AttributeWrapper(attribute)
                });

            OkButtonCommand = new DelegateCommand(OkButtonCommandExecute, OkButtonCommandCanExecute);
        }
开发者ID:hflorin,项目名称:annotator,代码行数:15,代码来源:AddEdgeViewModel.cs


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


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


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


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


示例14: 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


示例15: Removed_Items_Should_Disable_Change_Tracking_On_Entity

        public void Removed_Items_Should_Disable_Change_Tracking_On_Entity()
        {
            // Arrange
            var database = new MockNorthwind();
            var order = database.Orders[0];

            var changeTracker = new ChangeTrackingCollection<Order>(order);
            changeTracker.Remove(order);
            order.TrackingState = TrackingState.Unchanged;

            // Act
            order.OrderDate = order.OrderDate.AddDays(1);

            // Assert
            Assert.AreEqual(TrackingState.Unchanged, order.TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:16,代码来源:ChangeTrackingCollectionTests.cs


示例16: 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


示例17: Removed_Existing_Modified_Items_Should_Be_Marked_As_Deleted

        public void Removed_Existing_Modified_Items_Should_Be_Marked_As_Deleted()
        {
            // 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.AreEqual(TrackingState.Deleted, product.TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:14,代码来源:ChangeTrackingCollectionTests.cs


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ChangeType类代码示例发布时间:2022-05-24
下一篇:
C# ChangeSet类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap