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


C# Mocks.MockNorthwind类代码示例

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


MockNorthwind类属于TrackableEntities.EF.Tests.Mocks命名空间,在下文中一共展示了MockNorthwind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Accept_Changes_Should_Mark_Employee_With_Territories_Unchanged

        public void Accept_Changes_Should_Mark_Employee_With_Territories_Unchanged()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var employee = northwind.Employees[0];
            employee.TrackingState = TrackingState.Modified;
            employee.Territories[0].TrackingState = TrackingState.Modified;
            employee.Territories[1].TrackingState = TrackingState.Deleted;
            var territory = new Territory
            {
                TerritoryId = "75070",
                TerritoryDescription = "North Dallas",
                TrackingState = TrackingState.Added,
                Employees = new List<Employee> { employee }
            };
            employee.Territories.Add(territory);

            // Act
            employee.AcceptChanges();

            // Assert
            Assert.IsTrue(employee.GetTrackingStates().All(s => s == TrackingState.Unchanged));
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:23,代码来源:TrackableExtensionsTests.cs

示例2: Apply_Changes_Should_Mark_Order_Modified_With_OrderDetails_Added_Modified_Deleted_Unchanged

        public void Apply_Changes_Should_Mark_Order_Modified_With_OrderDetails_Added_Modified_Deleted_Unchanged()
        {
            // Arrange
            var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
            var order = new MockNorthwind().Orders[0];
            var detail1 = order.OrderDetails[0];
            detail1.OrderDetailId = 0;
            var detail2 = order.OrderDetails[1];
            var detail3 = order.OrderDetails[2];
            var detail4 = order.OrderDetails[3];
            order.TrackingState = TrackingState.Modified;
            detail1.TrackingState = TrackingState.Added;
            detail2.TrackingState = TrackingState.Modified;
            detail3.TrackingState = TrackingState.Deleted;
            detail4.TrackingState = TrackingState.Unchanged;

            // Act
            context.ApplyChanges(order);

            // Assert
            Assert.AreEqual(EntityState.Modified, context.Entry(order).State);
            Assert.AreEqual(EntityState.Added, context.Entry(detail1).State);
            Assert.AreEqual(EntityState.Modified, context.Entry(detail2).State);
            Assert.AreEqual(EntityState.Deleted, context.Entry(detail3).State);
            Assert.AreEqual(EntityState.Unchanged, context.Entry(detail4).State);
            Assert.AreEqual(EntityState.Unchanged, context.Entry(detail1.Product).State);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:27,代码来源:NorthwindDbContextTests.cs

示例3: Apply_Changes_Should_Mark_Modified_Order_With_Multiple_OrderDetails_Added

        public void Apply_Changes_Should_Mark_Modified_Order_With_Multiple_OrderDetails_Added()
        {
            // Arrange
            var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
            var order = new MockNorthwind().Orders[0];
            var detail1 = order.OrderDetails[0];
            var detail2 = order.OrderDetails[1];
            detail1.OrderDetailId = 0;
            detail2.OrderDetailId = 0;
            detail1.TrackingState = TrackingState.Added;
            detail2.TrackingState = TrackingState.Added;
            order.TrackingState = TrackingState.Modified;
            order.ModifiedProperties = new List<string> {"OrderDate"};

            // Act
            context.ApplyChanges(order);

            // Assert
            Assert.AreEqual(EntityState.Modified, context.Entry(order).State);
            Assert.AreEqual(EntityState.Added, context.Entry(detail1).State);
            Assert.AreEqual(EntityState.Added, context.Entry(detail2).State);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:22,代码来源:NorthwindDbContextTests.cs

示例4: Apply_Changes_Should_Mark_Deleted_Customer_As_Deleted_And_Deleted_Setting_As_Deleted

		public void Apply_Changes_Should_Mark_Deleted_Customer_As_Deleted_And_Deleted_Setting_As_Deleted()
		{
			// NOTE: CustomerSetting will be set to null because customer is deleted.

			// Arrange
			var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
			var nw = new MockNorthwind();
			var customer = nw.Customers[0];
			customer.TrackingState = TrackingState.Deleted;
			var setting = customer.CustomerSetting = new CustomerSetting { CustomerId = customer.CustomerId, Setting = "Setting1", Customer = customer };
			setting.TrackingState = TrackingState.Deleted;

			// Act
			context.ApplyChanges(customer);

			// Assert
			Assert.AreEqual(EntityState.Deleted, context.Entry(customer).State);
			Assert.AreEqual(EntityState.Deleted, context.Entry(setting).State);
			Assert.IsNull(customer.CustomerSetting);
		}
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:20,代码来源:NorthwindDbContextTests.cs

示例5: Apply_Changes_Should_Mark_Deleted_Order_As_Deleted_And_Deleted_Customer_As_Unchanged

		public void Apply_Changes_Should_Mark_Deleted_Order_As_Deleted_And_Deleted_Customer_As_Unchanged()
		{
			// NOTE: We ignore deletes of related M-1 entities to because it may be related
			// to other entities.

			// Arrange
			var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
			var nw = new MockNorthwind();
			var order = nw.Orders[0];
			order.TrackingState = TrackingState.Deleted;
			var customer = order.Customer;
			customer.TrackingState = TrackingState.Deleted;

			// Act
			context.ApplyChanges(order);

			// Assert
			Assert.AreEqual(EntityState.Deleted, context.Entry(order).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(customer).State);
			Assert.IsNull(order.Customer);
			Assert.IsNull(order.CustomerId);
		}
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:22,代码来源:NorthwindDbContextTests.cs

示例6: Apply_Changes_Should_Mark_Deleted_Employee_As_Deleted_And_Added_Territories_As_Unchanged

		public void Apply_Changes_Should_Mark_Deleted_Employee_As_Deleted_And_Added_Territories_As_Unchanged()
		{
			// NOTE: Because parent is deleted, added children will be marked as unchanged
			// but removed from the M-M relation

			// Arrange
			var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
			var nw = new MockNorthwind();
			var employee = nw.Employees[0];
			employee.TrackingState = TrackingState.Deleted;
			var territory1 = employee.Territories[0];
			var territory2 = employee.Territories[1];
			var territory3 = employee.Territories[2];
			var territory4 = nw.Territories[3];
			territory4.TrackingState = TrackingState.Added;
			employee.Territories.Add(territory4);

			// Act
			context.ApplyChanges(employee);

			// Assert
			Assert.AreEqual(EntityState.Deleted, context.Entry(employee).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory1).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory2).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory3).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory4).State);
			Assert.IsTrue(context.RelatedItemHasBeenRemoved(employee, territory1));
			Assert.IsTrue(context.RelatedItemHasBeenRemoved(employee, territory2));
			Assert.IsTrue(context.RelatedItemHasBeenRemoved(employee, territory3));
			Assert.IsTrue(context.RelatedItemHasBeenRemoved(employee, territory4));
			Assert.AreEqual(0, employee.Territories.Count);
		}
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:32,代码来源:NorthwindDbContextTests.cs

示例7: Apply_Changes_Should_Mark_Added_Customer_As_Added_And_Unchanged_Setting_As_Added

		public void Apply_Changes_Should_Mark_Added_Customer_As_Added_And_Unchanged_Setting_As_Added()
		{
			// Arrange
			var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
			var nw = new MockNorthwind();
			var customer = nw.Customers[0];
			customer.TrackingState = TrackingState.Added;
			var setting = customer.CustomerSetting = new CustomerSetting
				{ CustomerId = customer.CustomerId, Setting = "Setting1", Customer = customer };

			// Act
			context.ApplyChanges(customer);

			// Assert
			Assert.AreEqual(EntityState.Added, context.Entry(customer).State);
			Assert.AreEqual(EntityState.Added, context.Entry(setting).State);
		}
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:17,代码来源:NorthwindDbContextTests.cs

示例8: Accept_Changes_Should_Remove_ModifiedProperties_From_Customer_With_CustomerSetting

        public void Accept_Changes_Should_Remove_ModifiedProperties_From_Customer_With_CustomerSetting()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var customer = northwind.Customers[0];
            customer.TrackingState = TrackingState.Modified;
            customer.ModifiedProperties = new List<string> { "CustomerName" };
            customer.CustomerSetting = new CustomerSetting
                { TrackingState = TrackingState.Modified };
            customer.CustomerSetting.ModifiedProperties = new List<string> { "Setting" };

            // Act
            customer.AcceptChanges();

            // Assert
            Assert.IsFalse(customer.GetModifiedProperties().Any(p => p != null));
            Assert.IsFalse(customer.CustomerSetting.GetModifiedProperties().Any(p => p != null));
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:18,代码来源:TrackableExtensionsTests.cs

示例9: Accept_Changes_Should_Not_Remove_Deleted_CustomerSetting_From_Customer

        public void Accept_Changes_Should_Not_Remove_Deleted_CustomerSetting_From_Customer()
        {
            // NOTE: Reference entities cannot be deleted from a related entity, because
            // of possible referential constraints, but they can be deleted independently.

            // Arrange
            var northwind = new MockNorthwind();
            var customer = northwind.Customers[0];
            customer.TrackingState = TrackingState.Modified;
            customer.CustomerSetting = new CustomerSetting { TrackingState = TrackingState.Deleted };

            // Act
            customer.AcceptChanges();

            // Assert
            Assert.IsNotNull(customer.CustomerSetting);
            Assert.AreEqual(TrackingState.Unchanged, customer.CustomerSetting.TrackingState);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:18,代码来源:TrackableExtensionsTests.cs

示例10: Accept_Changes_Should_Remove_ModifiedProperties_From_Order_With_Customer

        public void Accept_Changes_Should_Remove_ModifiedProperties_From_Order_With_Customer()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var order = northwind.Orders[0];
            order.TrackingState = TrackingState.Modified;
            order.ModifiedProperties = new List<string> { "OrderDate" };
            order.Customer.TrackingState = TrackingState.Modified;
            order.Customer.ModifiedProperties = new List<string> { "CustomerName" };

            // Act
            order.AcceptChanges();

            // Assert
            Assert.IsFalse(order.GetModifiedProperties().Any(p => p != null));
            Assert.IsFalse(order.Customer.GetModifiedProperties().Any(p => p != null));
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:17,代码来源:TrackableExtensionsTests.cs

示例11: Accept_Changes_Should_Mark_Customer_With_Deleted_CustomerSetting_Unchanged

        public void Accept_Changes_Should_Mark_Customer_With_Deleted_CustomerSetting_Unchanged()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var customer = northwind.Customers[0];
            customer.TrackingState = TrackingState.Modified;
            customer.CustomerSetting = new CustomerSetting
            { TrackingState = TrackingState.Deleted };

            // Act
            customer.AcceptChanges();

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

示例12: Accept_Changes_Should_Mark_Order_With_Deleted_Customer_Unchanged

        public void Accept_Changes_Should_Mark_Order_With_Deleted_Customer_Unchanged()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var order = northwind.Orders[0];
            order.TrackingState = TrackingState.Modified;
            order.Customer.TrackingState = TrackingState.Deleted;

            // Act
            order.AcceptChanges();

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

示例13: Accept_Changes_Should_Remove_Deleted_Territories_From_Employee

        public void Accept_Changes_Should_Remove_Deleted_Territories_From_Employee()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var employee = northwind.Employees[0];
            employee.TrackingState = TrackingState.Modified;
            employee.Territories[0].TrackingState = TrackingState.Modified;
            employee.Territories[1].TrackingState = TrackingState.Deleted;
            var territory = new Territory
            {
                TerritoryId = "75070",
                TerritoryDescription = "North Dallas",
                TrackingState = TrackingState.Added,
                Employees = new List<Employee> { employee }
            };
            employee.Territories.Add(territory);

            // Act
            employee.AcceptChanges();

            // Assert
            Assert.AreEqual(3, employee.Territories.Count);
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:23,代码来源:TrackableExtensionsTests.cs

示例14: Accept_Changes_Should_Remove_ModifiedProperties_From_Employee_With_Territories

        public void Accept_Changes_Should_Remove_ModifiedProperties_From_Employee_With_Territories()
        {
            // Arrange
            var northwind = new MockNorthwind();
            var employee = northwind.Employees[0];
            employee.TrackingState = TrackingState.Modified;
            employee.ModifiedProperties = new List<string> { "LastName" };
            employee.Territories[0].ModifiedProperties = new List<string> { "TerritoryDescription" };

            // Act
            employee.AcceptChanges();

            // Assert
            IEnumerable<IEnumerable<string>> modifiedProps = employee.GetModifiedProperties();
            Assert.IsFalse(modifiedProps.Any(p => p != null));
        }
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:16,代码来源:TrackableExtensionsTests.cs

示例15: Apply_Changes_Should_Mark_Added_Employee_As_Added_And_Modified_Territories_As_Modified

		public void Apply_Changes_Should_Mark_Added_Employee_As_Added_And_Modified_Territories_As_Modified()
		{
			// NOTE: Modified children of an added parent will remain modified,
			// but they will be added to the M-M relation.

			// Arrange
			var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
			var nw = new MockNorthwind();
			var employee = nw.Employees[0];
			employee.TrackingState = TrackingState.Added;
			var territory1 = employee.Territories[0];
			var territory2 = employee.Territories[1];
			var territory3 = employee.Territories[2];
			territory3.TrackingState = TrackingState.Modified;

			// Act
			context.ApplyChanges(employee);

			// Assert
			Assert.AreEqual(EntityState.Added, context.Entry(employee).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory1).State);
			Assert.AreEqual(EntityState.Unchanged, context.Entry(territory2).State);
			Assert.AreEqual(EntityState.Modified, context.Entry(territory3).State);
			Assert.IsTrue(context.RelatedItemHasBeenAdded(employee, territory1));
			Assert.IsTrue(context.RelatedItemHasBeenAdded(employee, territory2));
			Assert.IsTrue(context.RelatedItemHasBeenAdded(employee, territory3));
		}
开发者ID:stevedelong,项目名称:trackable-entities,代码行数:27,代码来源:NorthwindDbContextTests.cs


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