public void Apply_Changes_Should_Mark_Modified_Order_Unchanged_Customer_With_Addresses_Multiple_Added_And_Unchanged()
        {
            // Arrange
            var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
            var order = new MockNorthwind().Orders[0];
            order.OrderDetails = null;
            var address1 = new CustomerAddress
            {
                CustomerAddressId = 0,
                Street = "Street1",
                CustomerId = order.Customer.CustomerId,
                Customer = order.Customer
            };
            var address2 = new CustomerAddress
            {
                CustomerAddressId = 0,
                Street = "Street2",
                CustomerId = order.Customer.CustomerId,
                Customer = order.Customer
            };
            var address3 = new CustomerAddress
            {
                CustomerAddressId = 1,
                Street = "Street3",
                CustomerId = order.Customer.CustomerId,
                Customer = order.Customer
            };
            order.Customer.CustomerAddresses = new List<CustomerAddress> { address1, address2, address3 };
            order.TrackingState = TrackingState.Modified;
            address1.TrackingState = TrackingState.Added;
            address2.TrackingState = TrackingState.Added;
            address3.TrackingState = TrackingState.Unchanged;

            // Act
            context.ApplyChanges(order);

            // Assert
            Assert.AreEqual(EntityState.Modified, context.Entry(order).State);
            Assert.AreEqual(EntityState.Unchanged, context.Entry(order.Customer).State);
            Assert.AreEqual(EntityState.Added, context.Entry(address1).State);
            Assert.AreEqual(EntityState.Added, context.Entry(address2).State);
            Assert.AreEqual(EntityState.Unchanged, context.Entry(address3).State);
        }
        public void Apply_Changes_Should_Mark_Unchanged_Order_Deleted_Customer_With_Addresses_Multiple_Added()
        {
            // Arrange
            var context = TestsHelper.CreateNorthwindDbContext(CreateNorthwindDbOptions);
            var order = new MockNorthwind().Orders[0];
            order.OrderDetails = null;
            var address1 = new CustomerAddress
            {
                CustomerAddressId = 0,
                Street = "Street1",
                CustomerId = order.Customer.CustomerId,
                Customer = order.Customer
            };
            var address2 = new CustomerAddress
            {
                CustomerAddressId = 0,
                Street = "Street2",
                CustomerId = order.Customer.CustomerId,
                Customer = order.Customer
            };
            order.Customer.CustomerAddresses = new List<CustomerAddress> { address1, address2 };
            order.Customer.TrackingState = TrackingState.Deleted;

            // Act / Assert
            Exception ex = Assert.Throws(typeof(InvalidOperationException), () => context.ApplyChanges(order));

            // Assert
            Assert.Equal(Constants.ExceptionMessages.DeletedWithAddedChildren, ex.Message);
        }