public void Entity_added_to_navigation_property_binding_list_is_added_to_context_after_DetectChanges()
        {
            using (var context = new F1Context())
            {
                var ferrari = context.Teams.Include(t => t.Drivers).Single(t => t.Id == Team.Ferrari);
                var navBindingList = ((IListSource)ferrari.Drivers).GetList();
                var localDrivers = context.Drivers.Local;

                var larry = new Driver
                                {
                                    Id = -1,
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                navBindingList.Add(larry);

                Assert.False(localDrivers.Contains(larry));

                GetObjectContext(context).DetectChanges();

                Assert.True(localDrivers.Contains(larry));
                Assert.Same(larry, context.Drivers.Find(-1));
            }
        }
        public void Entity_added_to_context_is_added_to_navigation_property_binding_list()
        {
            using (var context = new F1Context())
            {
                var ferrari = context.Teams.Include(t => t.Drivers).Single(t => t.Id == Team.Ferrari);
                var navBindingList = ((IListSource)ferrari.Drivers).GetList();

                var larry = new Driver
                                {
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                context.Drivers.Add(larry);

                Assert.True(navBindingList.Contains(larry));
            }
        }
        public void Entities_added_to_local_binding_list_are_added_to_state_manager()
        {
            using (var context = new F1Context())
            {
                var bindingList = context.Drivers.Local.ToBindingList();

                var larry = new Driver
                                {
                                    Id = -1,
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                bindingList.Add(larry);

                Assert.Same(larry, context.Drivers.Find(-1));
                Assert.Equal(
                    EntityState.Added,
                    GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(larry).State);
            }
        }
        public void Adding_entity_to_context_is_reflected_in_local_binding_list()
        {
            using (var context = new F1Context())
            {
                var bindingList = context.Drivers.Local.ToBindingList();

                var larry = new Driver
                                {
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                context.Drivers.Add(larry);

                Assert.True(bindingList.Contains(larry));
            }
        }
        private void Entities_added_to_local_view_are_added_to_state_manager_implementation(
            Func<F1Context, IList> getLocal)
        {
            using (var context = new F1Context())
            {
                var local = getLocal(context);

                var larry = new Driver
                                {
                                    Id = -1,
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                local.Add(larry);

                Assert.Same(larry, context.Drivers.Find(-1));
                Assert.Equal(
                    EntityState.Added,
                    GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(larry).State);
            }
        }
        private void Attaching_entity_to_context_is_reflected_in_local_view_implementation(
            Func<F1Context, IList> getLocal)
        {
            using (var context = new F1Context())
            {
                var local = getLocal(context);

                var larry = new Driver
                                {
                                    Name = "Larry David",
                                    TeamId = Team.Ferrari,
                                    CarNumber = 13
                                };
                context.Drivers.Attach(larry);

                Assert.True(local.Contains(larry));
            }
        }