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


C# ChangeTrackingCollection类代码示例

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


ChangeTrackingCollection类属于命名空间,在下文中一共展示了ChangeTrackingCollection类的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: 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


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