private static void EnsureTestTerritory(NorthwindDbContext context, string territoryId)
 {
     var territory = context.Territories
         .SingleOrDefault(t => t.TerritoryId == territoryId);
     if (territory == null)
     {
         territory = new Territory { TerritoryId = territoryId, TerritoryDescription = "Test Territory" };
         context.Territories.Add(territory);
     }
 }
        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);
        }
        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));
        }