當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。