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


C# ChangeTrackingCollection.Add方法代码示例

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


在下文中一共展示了ChangeTrackingCollection.Add方法的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: 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

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

示例4: WriteJson

        /// <summary>
        /// Serialize the object into JSON.
        /// </summary>
        /// <param name="writer">JSON writer.</param>
        /// <param name="value">PropertyValue to be serialized.</param>
        /// <param name="serializer">JSON serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                return;
            }

            ChangeTrackingCollection<GraphObject> graphObjects = value as ChangeTrackingCollection<GraphObject>;

            if (graphObjects == null)
            {
                if (!(value is IEnumerable))
                {
                    throw new ArgumentException("parameter 'value' is not of type IEnumerable.");
                }

                graphObjects = new ChangeTrackingCollection<GraphObject>();
                IEnumerable iEnumerableValue = value as IEnumerable;

                foreach (object valueObject in iEnumerableValue)
                {
                    GraphObject graphObject = valueObject as GraphObject;
                    if (graphObject == null)
                    {
                        throw new ArgumentException(
                            "Each value in the ChangeTrackingCollection should be of type GraphObject.");
                    }

                    graphObjects.Add(graphObject);
                }
            }

            if (graphObjects.Count > 0)
            {
                throw new ArgumentException("Updating links is not supported from entity.");
            }

            writer.WriteNull();
        }
开发者ID:shai-guy,项目名称:azuread-graphapi-library-for-dotnet,代码行数:45,代码来源:AadJsonConverter.cs

示例5: Removed_Added_Modified_Items_Should_Not_Have_ModifiedProperties

        public void Removed_Added_Modified_Items_Should_Not_Have_ModifiedProperties()
        {
            // Arrange
            var database = new MockNorthwind();
            var changeTracker = new ChangeTrackingCollection<Product>(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.IsTrue(product.ModifiedProperties == null
                || product.ModifiedProperties.Count == 0);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:23,代码来源:ChangeTrackingCollectionTests.cs

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

示例7: Added_Employee_After_Tracking_Enabled_Should_Not_Mark_Manually_Added_Territories_As_Unchanged

        public void Added_Employee_After_Tracking_Enabled_Should_Not_Mark_Manually_Added_Territories_As_Unchanged()
        {
            // Arrange
            var database = new MockNorthwind();
            var employee = database.Employees[0];
            employee.Territories.ToList().ForEach(t => t.TrackingState = TrackingState.Added);
            var changeTracker = new ChangeTrackingCollection<Employee>(true);

            // Act
            changeTracker.Add(employee);

            // Assert
            Assert.AreEqual(TrackingState.Added, employee.TrackingState);
            Assert.IsTrue(employee.Territories.All(t => t.TrackingState == TrackingState.Added));
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:15,代码来源:ChangeTrackingCollectionTests.cs

示例8: Added_Order_With_Modified_Customer_Should_Mark_Customer_As_Modified

        public void Added_Order_With_Modified_Customer_Should_Mark_Customer_As_Modified()
        {
            // NOTE: Modified reference entity will remain modified if parent is added.

            // Arrange
            var database = new MockNorthwind();
            var order = database.Orders[0];
            var changeTracker = new ChangeTrackingCollection<Order>(true);
            changeTracker.Add(order);

            // Act
            order.Customer.CustomerName = "xxx";

            // Assert
            Assert.Equal(TrackingState.Added, order.TrackingState);
            Assert.Equal(TrackingState.Modified, order.Customer.TrackingState);
            Assert.True(order.HasChanges());
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:18,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

示例9: Added_Items_With_Enumerable_Ctor_Should_Be_Marked_As_Added

        public void Added_Items_With_Enumerable_Ctor_Should_Be_Marked_As_Added()
        {
            // Arrange
            var database = new MockNorthwind();
            var products = new List<Product> { database.Products[0] };
            var changeTracker = new ChangeTrackingCollection<Product>(products);
            var product = new Product
                {
                    ProductId = 100,
                    ProductName = "Test Beverage",
                    CategoryId = 1,
                    Category = database.Categories[0],
                    UnitPrice = 10M
                };

            // Act
            changeTracker.Add(product);

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

示例10: GetChanges_Should_Return_Added_Items

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

            // Act
            var changes = changeTracker.GetChanges();

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

示例11: EntityChanged_Event_Should_Fire_When_Items_Added_Modified_Deleted

        public void EntityChanged_Event_Should_Fire_When_Items_Added_Modified_Deleted()
        {
            // Arrange
            int changesCount = 0;

            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.EntityChanged += (s, e) => changesCount++;

            // Act
            changeTracker.Add(addedProduct);
            updatedProduct.UnitPrice++;
            changeTracker.Remove(deletedProduct);

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

示例12: Added_Parent_With_Modified_Children_Should_Have_Children_Marked_As_Added

        public void Added_Parent_With_Modified_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);
            orderDetails[0].Quantity++;

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

示例13: HasChanges_Added_Parent_Should_Return_True

        public void HasChanges_Added_Parent_Should_Return_True()
        {
            // Arrange
            var parent = new Parent("Parent");
            var changeTracker = new ChangeTrackingCollection<Parent>(true);
            changeTracker.Add(parent);

            // Act
            bool hasChanges = parent.HasChanges();

            // Assert
            Assert.True(hasChanges);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:13,代码来源:ChangeTrackingExtensionsTests.cs

示例14: Added_Employee_Then_Removed_With_Territories_Should_Have_Territories_Marked_As_Unchanged

        public void Added_Employee_Then_Removed_With_Territories_Should_Have_Territories_Marked_As_Unchanged()
        {
            // NOTE: Removing an added parent should mark parent and children as unchanged.
            // This is so that GetChanges will not include parent or children.

            // Arrange
            var database = new MockNorthwind();
            var changeTracker = new ChangeTrackingCollection<Employee>(true);
            var employee = database.Employees[0];
            var unchangedTerritory = employee.Territories[0];
            var modifiedTerritory = employee.Territories[1];
            var deletedTerritory = employee.Territories[2];
            var addedTerritory = database.Territories[3];
            changeTracker.Add(employee);

            // Act
            modifiedTerritory.TerritoryDescription = "xxx";
            employee.Territories.Add(addedTerritory); // stays added
            employee.Territories.Remove(deletedTerritory); // from added to unchanged
            changeTracker.Remove(employee);

            // Assert
            Assert.Equal(TrackingState.Unchanged, employee.TrackingState);
            Assert.Equal(TrackingState.Unchanged, unchangedTerritory.TrackingState);
            Assert.Equal(TrackingState.Unchanged, modifiedTerritory.TrackingState);
            Assert.Equal(TrackingState.Unchanged, addedTerritory.TrackingState);
            Assert.Equal(TrackingState.Unchanged, deletedTerritory.TrackingState);
        }
开发者ID:luboshl,项目名称:trackable-entities,代码行数:28,代码来源:ChangeTrackingCollectionWithChildrenTests.cs

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


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