Beispiel #1
0
        public void Can_get_all_reference_entries()
        {
            using (var context = new FreezerContext())
            {
                Assert.Equal(
                    new List <string>
                {
                    "Garcia"
                },
                    context.Attach(new Chunky()).References.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string>
                {
                    "Baked"
                },
                    context.Attach(new Cherry()).References.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string>
                {
                    "Garcia"
                },
                    context.Attach(new Half()).References.Select(e => e.Metadata.Name).ToList());
            }
        }
Beispiel #2
0
    public void Can_get_all_member_entries()
    {
        using var context = new FreezerContext();
        Assert.Equal(
            new List <string>
        {
            "Id",
            "GarciaId",
            "Monkey",
            "Nonkey",
            "Garcia"
        },
            context.Attach(new Chunky()).Members.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string>
        {
            "Id",
            "Garcia",
            "Baked",
            "Monkeys"
        },
            context.Attach(new Cherry()).Members.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string>
        {
            "Id",
            "Baked",
            "GarciaId",
            "Garcia"
        },
            context.Attach(new Half()).Members.Select(e => e.Metadata.Name).ToList());
    }
Beispiel #3
0
        public void Can_get_all_navigation_entries()
        {
            using (var context = new FreezerContext())
            {
                Assert.Equal(
                    new List <string>
                {
                    "Garcia"
                },
                    context.Attach(new Chunky()).Navigations.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string>
                {
                    "Baked",
                    "Monkeys"
                },
                    context.Attach(new Cherry()).Navigations.Select(e => e.Metadata.Name).ToList());

                Assert.Equal(
                    new List <string>
                {
                    "Garcia"
                },
                    context.Attach(new Half()).Navigations.Select(e => e.Metadata.Name).ToList());
            }
        }
Beispiel #4
0
        public void IsModified_can_set_fk_to_modified_principal_with_Modified_dependents(
            EntityState principalState,
            EntityState dependentState)
        {
            using var context = new FreezerContext();
            var cherry = new Cherry { Id = 1 };
            var chunky1 = new Chunky { Id = 1, Garcia = cherry };
            var chunky2 = new Chunky { Id = 2, Garcia = cherry };
            cherry.Monkeys = new List<Chunky> { chunky1, chunky2 };

            context.Attach(chunky1);
            context.Attach(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.False(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.True(context.Entry(chunky1).Property(e => e.GarciaId).IsModified);
            Assert.True(context.Entry(chunky2).Property(e => e.GarciaId).IsModified);
            Assert.Equal(dependentState, context.Entry(chunky1).State);
            Assert.Equal(dependentState, context.Entry(chunky2).State);
        }
Beispiel #5
0
    public void Can_get_all_collection_entries()
    {
        using var context = new FreezerContext();
        Assert.Empty(context.Attach(new Chunky()).Collections.Select(e => e.Metadata.Name).ToList());

        Assert.Equal(
            new List <string> {
            "Monkeys"
        },
            context.Attach(new Cherry()).Collections.Select(e => e.Metadata.Name).ToList());

        Assert.Empty(context.Attach(new Half()).Collections.Select(e => e.Metadata.Name).ToList());
    }
Beispiel #6
0
        public void IsModified_can_set_fk_to_modified_principal_with_Modified_dependent(
            EntityState principalState,
            EntityState dependentState)
        {
            using var context = new FreezerContext();
            var half = new Half {
                Id = 7
            };
            var chunky = new Chunky {
                Id = 1, Baked = half
            };

            half.Monkey = chunky;

            context.Attach(half);

            context.Entry(chunky).State = principalState;
            context.Entry(half).State   = dependentState;

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

            Assert.True(reference.IsModified);

            reference.IsModified = false;

            Assert.False(reference.IsModified);
            Assert.False(context.Entry(half).Property(e => e.MonkeyId).IsModified);

            reference.IsModified = true;

            Assert.True(reference.IsModified);
            Assert.True(context.Entry(half).Property(e => e.MonkeyId).IsModified);
            Assert.Equal(dependentState, context.Entry(half).State);
        }
Beispiel #7
0
        public void Can_get_all_modified_properties()
        {
            using (var context = new FreezerContext())
            {
                var entity = context.Attach(new Chunky()).Entity;

                var modified = context.Entry(entity).Properties
                               .Where(e => e.IsModified).Select(e => e.Metadata.Name).ToList();

                Assert.Empty(modified);

                entity.Nonkey   = "Blue";
                entity.GarciaId = 77;

                context.ChangeTracker.DetectChanges();

                modified = context.Entry(entity).Properties
                           .Where(e => e.IsModified).Select(e => e.Metadata.Name).ToList();

                Assert.Equal(
                    new List <string>
                {
                    "GarciaId",
                    "Nonkey"
                }, modified);
            }
        }
Beispiel #8
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.Equal(1, context.ChangeTracker.Entries().Count());

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

                Assert.Equal(0, context.ChangeTracker.Entries().Count());

                context.ChangeTracker.DetectChanges();

                Assert.Equal(0, context.ChangeTracker.Entries().Count());

                context.Entry(entity);

                Assert.Equal(0, context.ChangeTracker.Entries().Count());
            }
        }
Beispiel #9
0
        public void Can_get_all_navigation_entries()
        {
            using var context = new FreezerContext();

            Assert.Equal(
                new List <string> {
                "Cherries"
            },
                context.Attach(new Chunky()).Navigations.Select(e => e.Metadata.Name).ToList());
        }