public void Can_get_back_reference_reference()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                var entityEntry = context.Entry(entity);
                Assert.Same(entityEntry.Entity, entityEntry.Navigation("Garcia").EntityEntry.Entity);
            }
        }
Ejemplo n.º 2
0
        public void Can_obtain_entity_instance()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                Assert.Same(entity, context.Entry(entity).Entity);
                Assert.Same(entity, context.Entry((object)entity).Entity);
            }
        }
        public void Can_get_back_reference_generic()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                var entityEntry = context.Entry(entity);
                Assert.Same(entityEntry.Entity, entityEntry.Reference(e => e.Garcia).EntityEntry.Entity);
            }
        }
Ejemplo n.º 4
0
        public void Can_get_back_reference_property()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                var entityEntry = context.Entry(entity);
                Assert.Same(entityEntry.Entity, entityEntry.Member("Monkey").EntityEntry.Entity);
            }
        }
        public void Can_obtain_entity_instance()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                context.Add(entity);

                Assert.Same(entity, context.Entry(entity).Entity);
                Assert.Same(entity, context.Entry((object)entity).Entity);
            }
        }
Ejemplo n.º 6
0
        public void IsModified_can_set_fk_to_modified_principal_with_Added_or_Deleted_dependents(
            EntityState principalState, EntityState dependentState)
        {
            using var context = new FreezerContext();
            var cherry  = new Cherry();
            var chunky1 = new Chunky {
                Id = 1, Garcia = cherry
            };
            var chunky2 = new Chunky {
                Id = 2, Garcia = cherry
            };

            cherry.Monkeys = new List <Chunky> {
                chunky1, chunky2
            };

            context.Entry(cherry).State  = principalState;
            context.Entry(chunky1).State = dependentState;
            context.Entry(chunky2).State = dependentState;

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.True(collection.IsModified);

            collection.IsModified = false;

            Assert.True(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);

            collection.IsModified = true;

            Assert.True(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
            Assert.Equal(dependentState, context.Entry(chunky1).State);
            Assert.Equal(dependentState, context.Entry(chunky2).State);

            if (dependentState == EntityState.Deleted)
            {
                context.Entry(chunky1).State = EntityState.Detached;
                context.Entry(chunky2).State = EntityState.Detached;
            }
            else
            {
                context.Entry(chunky1).State = EntityState.Unchanged;
                context.Entry(chunky2).State = EntityState.Unchanged;
            }

            Assert.False(collection.IsModified);
            Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
        }
Ejemplo n.º 7
0
    public void Cannot_set_invalid_state()
    {
        using var context = new FreezerContext();
        var entity = new Chunky();

        Assert.Equal(
            CoreStrings.InvalidEnumValue("-1", "value", typeof(EntityState).FullName),
            Assert.Throws <ArgumentException>(() => context.Entry(entity).State = (EntityState)(-1)).Message);

        Assert.Equal(
            CoreStrings.InvalidEnumValue("5", "value", typeof(EntityState).FullName),
            Assert.Throws <ArgumentException>(() => context.Entry(entity).State = (EntityState)(5)).Message);
    }
Ejemplo n.º 8
0
    public void Can_get_and_change_state()
    {
        using var context = new FreezerContext();
        var entity = new Chunky();
        var entry  = context.Add(entity).GetInfrastructure();

        context.Entry(entity).State = EntityState.Modified;
        Assert.Equal(EntityState.Modified, entry.EntityState);
        Assert.Equal(EntityState.Modified, context.Entry(entity).State);

        context.Entry((object)entity).State = EntityState.Unchanged;
        Assert.Equal(EntityState.Unchanged, entry.EntityState);
        Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
    }
Ejemplo n.º 9
0
        public void Setting_IsModified_false_reverts_changes_to_join_table_FKs()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            var joinEntity = context.ChangeTracker.Entries <Dictionary <string, object> >()
                             .Single(e => e.Property <int>("CherryId").CurrentValue == 1 && e.Property <int>("ChunkyId").CurrentValue == 2)
                             .Entity;

            joinEntity["CherryId"] = 2;
            context.ChangeTracker.DetectChanges();

            Assert.False(relatedToCherry1.IsModified);
            Assert.True(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            relatedToCherry2.IsModified = false;

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Unchanged, joinEntry.State);
            }
        }
Ejemplo n.º 10
0
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry = ((IAccessor<InternalEntityEntry>)context.Add(entity)).Service;

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
Ejemplo n.º 11
0
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity     = new Chunky();
                var stateEntry = context.Add(entity).StateEntry;

                context.Entry(entity).SetState(EntityState.Modified);
                Assert.Equal(EntityState.Modified, stateEntry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).SetState(EntityState.Unchanged);
                Assert.Equal(EntityState.Unchanged, stateEntry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
Ejemplo n.º 12
0
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry = context.Add(entity).GetInfrastructure();

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
Ejemplo n.º 13
0
        public void Can_get_and_change_state()
        {
            using (var context = new FreezerContext())
            {
                var entity = new Chunky();
                var entry  = ((IAccessor <InternalEntityEntry>)context.Add(entity)).Service;

                context.Entry(entity).State = EntityState.Modified;
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal(EntityState.Modified, context.Entry(entity).State);

                context.Entry((object)entity).State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal(EntityState.Unchanged, context.Entry((object)entity).State);
            }
        }
Ejemplo n.º 14
0
        public void Setting_IsModified_true_marks_all_join_table_FK_modified()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Unchanged, joinEntry.State);
            }

            relatedToCherry1.IsModified = true;

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.True(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            foreach (var joinEntry in context.ChangeTracker.Entries <Dictionary <string, object> >())
            {
                Assert.Equal(EntityState.Modified, joinEntry.State);
            }
        }
Ejemplo n.º 15
0
        public void Can_get_and_set_current_value_property()
        {
            using var context = new FreezerContext();
            var entity = new Chunky();

            context.Add(entity);

            var property = context.Entry(entity).Member("GarciaId");

            Assert.Null(property.CurrentValue);

            property.CurrentValue = 77;
            Assert.Equal(77, property.CurrentValue);

            property.CurrentValue = null;
            Assert.Null(property.CurrentValue);
        }
Ejemplo n.º 16
0
        public void IsModified_tracks_mutation_of_join_fks()
        {
            using var context = new ExplicitFreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            var joinEntity = context.ChangeTracker.Entries <Dictionary <string, object> >()
                             .Single(e => e.Property <int>("CherryId").CurrentValue == 1 && e.Property <int>("ChunkyId").CurrentValue == 2)
                             .Entity;

            joinEntity["CherryId"] = 2;
            context.ChangeTracker.DetectChanges();

            Assert.False(relatedToCherry1.IsModified);
            Assert.True(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            joinEntity["CherryId"] = 1;
            context.ChangeTracker.DetectChanges();

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);
        }
Ejemplo n.º 17
0
        public void IsModified_tracks_adding_new_related_entity(bool useExplicitPk)
        {
            using var context = useExplicitPk ? new ExplicitFreezerContext() : new FreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            var chunky3 = new Chunky {
                Id = 3
            };

            cherry1.Chunkies.Add(chunky3);
            context.ChangeTracker.DetectChanges();

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            context.Entry(chunky3).State = EntityState.Detached;

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);
        }
Ejemplo n.º 18
0
        public void IsModified_tracks_state_of_FK_property_principal()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky1 = new Chunky { Id = 1, Garcia = cherry };
            var chunky2 = new Chunky { Id = 2, Garcia = cherry };
            cherry.Monkeys = new List<Chunky> { chunky1, chunky2 };
            context.AttachRange(cherry, chunky1, chunky2);

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.False(collection.IsModified);

            context.Entry(chunky1).State = EntityState.Modified;

            Assert.True(collection.IsModified);

            context.Entry(chunky1).State = EntityState.Unchanged;

            Assert.False(collection.IsModified);
        }
Ejemplo n.º 19
0
        public void IsModified_tracks_removing_items_from_the_join_table(bool useExplicitPk)
        {
            using var context = useExplicitPk ? new ExplicitFreezerContext() : new FreezerContext();

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            cherry1.Chunkies.Remove(chunky2);
            context.ChangeTracker.DetectChanges();

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);

            cherry1.Chunkies.Add(chunky2);
            context.ChangeTracker.DetectChanges();

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.True(relatedToChunky2.IsModified);
        }
        public void IsModified_can_set_fk_to_modified_collection()
        {
            using (var context = new FreezerContext())
            {
                var cherry  = new Cherry();
                var chunky1 = new Chunky
                {
                    Garcia = cherry
                };
                var chunky2 = new Chunky
                {
                    Garcia = cherry
                };
                cherry.Monkeys = new List <Chunky>
                {
                    chunky1,
                    chunky2
                };
                context.AttachRange(cherry, chunky1, chunky2);

                var collection = context.Entry(cherry).Navigation("Monkeys");

                Assert.False(collection.IsModified);

                collection.IsModified = true;

                Assert.True(collection.IsModified);
                Assert.True(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
                Assert.True(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);

                collection.IsModified = false;

                Assert.False(collection.IsModified);
                Assert.False(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
                Assert.False(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
                Assert.Equal(EntityState.Unchanged, context.Entry(chunky1).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(chunky2).State);
            }
        }
Ejemplo n.º 21
0
        public void Can_get_and_set_current_value_generic_attched()
        {
            using (var context = new FreezerContext())
            {
                var cherry = new Cherry();
                var chunky = new Chunky();
                context.AttachRange(chunky, cherry);

                var collection = context.Entry(cherry).Collection(e => e.Monkeys);

                Assert.Null(collection.CurrentValue);

                collection.CurrentValue = new List <Chunky>
                {
                    chunky
                };

                Assert.Same(cherry, chunky.Garcia);
                Assert.Same(chunky, cherry.Monkeys.Single());
                Assert.Equal(cherry.Id, chunky.GarciaId);
                Assert.Same(chunky, collection.CurrentValue.Single());

                Assert.Equal(EntityState.Unchanged, context.Entry(cherry).State);
                Assert.Equal(EntityState.Modified, context.Entry(chunky).State);
                Assert.True(context.Entry(chunky).Property(e => e.GarciaId).IsModified);

                collection.CurrentValue = null;

                Assert.Null(chunky.Garcia);
                Assert.Null(cherry.Monkeys);
                Assert.Null(chunky.GarciaId);
                Assert.Null(collection.CurrentValue);

                Assert.Equal(EntityState.Unchanged, context.Entry(cherry).State);
                Assert.Equal(EntityState.Modified, context.Entry(chunky).State);
                Assert.True(context.Entry(chunky).Property(e => e.GarciaId).IsModified);
            }
        }
Ejemplo n.º 22
0
        public void IsModified_tracks_detects_deletion_of_related_entity(bool useExplicitPk, CascadeTiming cascadeTiming)
        {
            using var context = useExplicitPk ? new ExplicitFreezerContext() : new FreezerContext();

            context.ChangeTracker.CascadeDeleteTiming = cascadeTiming;

            var cherry1 = new Cherry {
                Id = 1
            };
            var cherry2 = new Cherry {
                Id = 2
            };
            var chunky1 = new Chunky {
                Id = 1
            };
            var chunky2 = new Chunky {
                Id = 2
            };

            AttachGraph(context, cherry1, cherry2, chunky1, chunky2);

            var relatedToCherry1 = context.Entry(cherry1).Collection(e => e.Chunkies);
            var relatedToCherry2 = context.Entry(cherry2).Collection(e => e.Chunkies);
            var relatedToChunky1 = context.Entry(chunky1).Collection(e => e.Cherries);
            var relatedToChunky2 = context.Entry(chunky2).Collection(e => e.Cherries);

            Assert.False(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.False(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);

            context.Entry(chunky1).State = EntityState.Deleted;

            Assert.True(relatedToCherry1.IsModified);
            Assert.False(relatedToCherry2.IsModified);
            Assert.True(relatedToChunky1.IsModified);
            Assert.False(relatedToChunky2.IsModified);
        }
Ejemplo n.º 23
0
    public void Detached_entities_are_not_returned_from_the_change_tracker()
    {
        using var context = new FreezerContext();
        var entity = new Chunky {
            Id = 808
        };

        context.Attach(entity);

        Assert.Single(context.ChangeTracker.Entries());

        context.Entry(entity).State = EntityState.Detached;

        Assert.Empty(context.ChangeTracker.Entries());

        context.ChangeTracker.DetectChanges();

        Assert.Empty(context.ChangeTracker.Entries());

        context.Entry(entity);

        Assert.Empty(context.ChangeTracker.Entries());
    }
Ejemplo n.º 24
0
        public void IsModified_tracks_state_of_FK_property_principal()
        {
            using var context = new FreezerContext();
            var half   = new Half();
            var chunky = new Chunky {
                Baked = half
            };

            half.Monkey = chunky;
            context.AttachRange(chunky, half);

            var reference = context.Entry(chunky).Reference(e => e.Baked);

            Assert.False(reference.IsModified);

            context.Entry(half).State = EntityState.Modified;

            Assert.True(reference.IsModified);

            context.Entry(half).State = EntityState.Unchanged;

            Assert.False(reference.IsModified);
        }
Ejemplo n.º 25
0
 // Update is called once per frame
 void Update()
 {
     if (Time.time - lastTime > 1f && MapManager.Instance.countdownTime > 0f)
     {
         MapManager.Instance.countdownTime -= 1;
         lastTime = Time.time;
         float d = Vector3.Distance(CameraBase.Instance.player.transform.position, Circlefield.transform.position);
         //超出半径时
         if (chunkyEffect == null)
         {
             chunkyEffect = Camera.main.gameObject.GetComponent <Chunky>();
         }
         if (isBegin)
         {
             //Debug.Log(d.ToString()+"  "+ Circlefield.transform.localScale.x);
             if (d > Circlefield.transform.localScale.x)
             {
                 if (chunkyEffect.enabled == false)
                 {
                     chunkyEffect.enabled = true;
                     AudioManager.PlayMusic2D("Poison", true).Play();
                 }
                 //发送毒圈伤害消息
                 NetworkManager.SendPlayerPoison();
             }
             else
             {
                 if (chunkyEffect.enabled == true)
                 {
                     chunkyEffect.enabled = false;
                     AudioManager.PlayMusic2D("Poison", true).Pause();
                 }
             }
         }
     }
 }
Ejemplo n.º 26
0
        public void Can_get_and_set_current_value_generic_not_tracked()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky = new Chunky();

            var collection = context.Entry(cherry).Collection(e => e.Monkeys);

            Assert.Null(collection.CurrentValue);

            collection.CurrentValue = new List<Chunky> { chunky };

            Assert.Null(chunky.Garcia);
            Assert.Same(chunky, cherry.Monkeys.Single());
            Assert.Null(chunky.GarciaId);
            Assert.Same(chunky, collection.CurrentValue.Single());

            collection.CurrentValue = null;

            Assert.Null(chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Null(collection.CurrentValue);
        }
Ejemplo n.º 27
0
        public void Can_get_and_set_current_value_not_tracked_generic()
        {
            using var context = new FreezerContext();
            var cherry = new Cherry();
            var chunky = new Chunky();

            var reference = context.Entry(chunky).Reference(e => e.Garcia);

            Assert.Null(reference.CurrentValue);

            reference.CurrentValue = cherry;

            Assert.Same(cherry, chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Same(cherry, reference.CurrentValue);

            reference.CurrentValue = null;

            Assert.Null(chunky.Garcia);
            Assert.Null(cherry.Monkeys);
            Assert.Null(chunky.GarciaId);
            Assert.Null(reference.CurrentValue);
        }
Ejemplo n.º 28
0
        public void Can_get_and_set_current_value_start_tracking_generic()
        {
            using (var context = new FreezerContext())
            {
                var cherry = new Cherry();
                var chunky = new Chunky();
                context.Add(cherry);

                var collection = context.Entry(cherry).Collection(e => e.Monkeys);

                Assert.Null(collection.CurrentValue);

                collection.CurrentValue = new List <Chunky>
                {
                    chunky
                };

                Assert.Same(cherry, chunky.Garcia);
                Assert.Same(chunky, cherry.Monkeys.Single());
                Assert.Equal(cherry.Id, chunky.GarciaId);
                Assert.Same(chunky, collection.CurrentValue.Single());

                Assert.Equal(EntityState.Added, context.Entry(cherry).State);
                Assert.Equal(EntityState.Added, context.Entry(chunky).State);

                collection.CurrentValue = null;

                Assert.Null(chunky.Garcia);
                Assert.Null(cherry.Monkeys);
                Assert.Null(chunky.GarciaId);
                Assert.Null(collection.CurrentValue);

                Assert.Equal(EntityState.Added, context.Entry(cherry).State);
                Assert.Equal(EntityState.Added, context.Entry(chunky).State);
            }
        }
Ejemplo n.º 29
0
        public void Can_get_and_set_current_value_start_tracking_generic(bool useExplicitPk)
        {
            using var context = useExplicitPk ? new ExplicitFreezerContext() : new FreezerContext();

            var cherry = new Cherry();
            var chunky = new Chunky();

            context.Add(cherry);

            var collection        = context.Entry(cherry).Collection(e => e.Chunkies);
            var inverseCollection = context.Entry(chunky).Collection(e => e.Cherries);

            Assert.Null(collection.CurrentValue);

            collection.CurrentValue = new List <Chunky> {
                chunky
            };

            Assert.Same(chunky, cherry.Chunkies.Single());
            Assert.Same(cherry, chunky.Cherries.Single());
            Assert.Same(chunky, collection.CurrentValue.Single());
            Assert.Same(cherry, inverseCollection.CurrentValue.Single());

            Assert.Equal(EntityState.Added, context.Entry(cherry).State);
            Assert.Equal(EntityState.Added, context.Entry(chunky).State);

            collection.CurrentValue = null;

            Assert.Empty(chunky.Cherries);
            Assert.Null(cherry.Chunkies);
            Assert.Null(collection.CurrentValue);
            Assert.Empty(inverseCollection.CurrentValue);

            Assert.Equal(EntityState.Added, context.Entry(cherry).State);
            Assert.Equal(EntityState.Added, context.Entry(chunky).State);
        }
Ejemplo n.º 30
0
        private static void AttachGraph(FreezerContext context, Cherry cherry1, Cherry cherry2, Chunky chunky1, Chunky chunky2)
        {
            cherry1.Chunkies = new List <Chunky> {
                chunky1, chunky2
            };
            cherry2.Chunkies = new List <Chunky>();

            if (context is ExplicitFreezerContext)
            {
                context.AddRange(cherry1, cherry2, chunky1, chunky2); // So that PKs get generated values
                context.ChangeTracker.Entries().ToList().ForEach(e => e.State = EntityState.Unchanged);
            }
            else
            {
                context.AttachRange(cherry1, cherry2, chunky1, chunky2);
            }
        }