Пример #1
0
        public void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(EntityState initialState)
        {
            using (var context = new PrimateContext())
            {
                var entity = new Wotty {
                    Id = 1
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(initialState);

                Assert.False(new PropertyEntry(entry, "Primate").IsModified);
                Assert.False(new PropertyEntry(entry, "RequiredPrimate").IsModified);

                new PropertyEntry(entry, "Primate").IsModified         = true;
                new PropertyEntry(entry, "RequiredPrimate").IsModified = true;
                Assert.True(new PropertyEntry(entry, "Primate").IsModified);
                Assert.True(new PropertyEntry(entry, "RequiredPrimate").IsModified);

                context.ChangeTracker.DetectChanges();
                Assert.True(new PropertyEntry(entry, "Primate").IsModified);
                Assert.True(new PropertyEntry(entry, "RequiredPrimate").IsModified);

                new PropertyEntry(entry, "Primate").IsModified         = false;
                new PropertyEntry(entry, "RequiredPrimate").IsModified = false;
                Assert.False(new PropertyEntry(entry, "Primate").IsModified);
                Assert.False(new PropertyEntry(entry, "RequiredPrimate").IsModified);

                context.ChangeTracker.DetectChanges();
                Assert.False(new PropertyEntry(entry, "Primate").IsModified);
                Assert.False(new PropertyEntry(entry, "RequiredPrimate").IsModified);
            }
        }
Пример #2
0
        public void Can_set_and_get_original_value_starting_null()
        {
            using (var context = new PrimateContext())
            {
                var entity = new Wotty {
                    Id = 1
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Unchanged);

                Assert.Null(new PropertyEntry(entry, "Primate").OriginalValue);
                Assert.Null(new PropertyEntry(entry, "RequiredPrimate").OriginalValue);

                new PropertyEntry(entry, "Primate").OriginalValue         = "Chimp";
                new PropertyEntry(entry, "RequiredPrimate").OriginalValue = "Bushbaby";

                Assert.Equal("Chimp", new PropertyEntry(entry, "Primate").OriginalValue);
                Assert.Null(entity.Primate);

                Assert.Equal("Bushbaby", new PropertyEntry(entry, "RequiredPrimate").OriginalValue);
                Assert.Null(entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();

                Assert.Equal("Chimp", new PropertyEntry(entry, "Primate").OriginalValue);
                Assert.Null(entity.Primate);

                Assert.Equal("Bushbaby", new PropertyEntry(entry, "RequiredPrimate").OriginalValue);
                Assert.Null(entity.RequiredPrimate);
            }
        }
Пример #3
0
        public void Can_set_original_value_to_null()
        {
            using (var context = new PrimateContext())
            {
                var entity = new Wotty
                {
                    Id              = 1,
                    Primate         = "Monkey",
                    RequiredPrimate = "Tarsier"
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Unchanged);

                new PropertyEntry(entry, "Primate").OriginalValue         = null;
                new PropertyEntry(entry, "RequiredPrimate").OriginalValue = null;

                Assert.Null(new PropertyEntry(entry, "Primate").OriginalValue);
                Assert.Null(new PropertyEntry(entry, "RequiredPrimate").OriginalValue);

                context.ChangeTracker.DetectChanges();

                Assert.Null(new PropertyEntry(entry, "Primate").OriginalValue);
                Assert.Null(new PropertyEntry(entry, "RequiredPrimate").OriginalValue);
            }
        }
Пример #4
0
        public void Can_set_current_value()
        {
            using (var context = new PrimateContext())
            {
                var entity = new Wotty
                {
                    Id              = 1,
                    Primate         = "Monkey",
                    RequiredPrimate = "Tarsier"
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Unchanged);

                new PropertyEntry(entry, "Primate").CurrentValue         = "Chimp";
                new PropertyEntry(entry, "RequiredPrimate").CurrentValue = "Bushbaby";

                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Bushbaby", entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();

                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Bushbaby", entity.RequiredPrimate);
            }
        }
Пример #5
0
        public void Can_set_current_value()
        {
            var entity = new Wotty { Id = 1, Primate = "Monkey" };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry(entry, "Primate").CurrentValue = "Chimp";

            Assert.Equal("Chimp", entity.Primate);
        }
        public void Can_set_current_value_to_null()
        {
            var entity = new Wotty { Id = 1, Primate = "Monkey" };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor<Wotty>(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry(entry, "Primate").CurrentValue = null;

            Assert.Null(entity.Primate);
        }
Пример #7
0
        public void Can_set_current_value_generic()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor <Wotty>(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry <Wotty, string>(entry, "Primate").CurrentValue = "Chimp";

            Assert.Equal("Chimp", entity.Primate);
        }
Пример #8
0
        public void Can_set_current_value()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = InMemoryTestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry(entry, "Primate").CurrentValue = "Chimp";

            Assert.Equal("Chimp", entity.Primate);
        }
Пример #9
0
        public void Can_set_current_value_to_null_generic()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = InMemoryTestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry <Wotty, string>(entry, "Primate").CurrentValue = null;

            Assert.Null(entity.Primate);
        }
Пример #10
0
        public void Can_set_current_value_to_null()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor <Wotty>(),
                EntityState.Unchanged,
                entity);

            new PropertyEntry(entry, "Primate").CurrentValue = null;

            Assert.Null(entity.Primate);
        }
Пример #11
0
        public void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(EntityState initialState)
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = InMemoryTestHelpers.Instance.CreateInternalEntry(BuildModel(), initialState, entity);

            Assert.False(new PropertyEntry(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = true;
            Assert.True(new PropertyEntry(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = false;
            Assert.False(new PropertyEntry(entry, "Primate").IsModified);
        }
Пример #12
0
        public void Can_set_and_get_original_value()
        {
            var entity = new Wotty { Id = 1, Primate = "Monkey" };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor<Wotty>(),
                EntityState.Unchanged,
                entity);

            Assert.Equal("Monkey", new PropertyEntry(entry, "Primate").OriginalValue);

            new PropertyEntry(entry, "Primate").OriginalValue = "Chimp";

            Assert.Equal("Chimp", new PropertyEntry(entry, "Primate").OriginalValue);
            Assert.Equal("Monkey", entity.Primate);
        }
Пример #13
0
        public void Can_set_and_get_original_value()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor <Wotty>(),
                EntityState.Unchanged,
                entity);

            Assert.Equal("Monkey", new PropertyEntry(entry, "Primate").OriginalValue);

            new PropertyEntry(entry, "Primate").OriginalValue = "Chimp";

            Assert.Equal("Chimp", new PropertyEntry(entry, "Primate").OriginalValue);
            Assert.Equal("Monkey", entity.Primate);
        }
Пример #14
0
        public void Can_set_and_clear_modified_generic()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor <Wotty>(),
                EntityState.Unchanged,
                entity);

            Assert.False(new PropertyEntry <Wotty, string>(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = true;

            Assert.True(new PropertyEntry <Wotty, string>(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = false;

            Assert.False(new PropertyEntry <Wotty, string>(entry, "Primate").IsModified);
        }
Пример #15
0
        public void Can_reject_changes_when_clearing_modified_flag()
        {
            var entity = new Wotty {
                Id = 1, Primate = "Monkey", Marmate = "Bovril"
            };

            var entry = InMemoryTestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                EntityState.Unchanged,
                entity);

            var primateEntry = new PropertyEntry(entry, "Primate");

            primateEntry.OriginalValue = "Chimp";
            primateEntry.IsModified    = true;

            var marmateEntry = new PropertyEntry(entry, "Marmate");

            marmateEntry.OriginalValue = "Marmite";
            marmateEntry.IsModified    = true;

            Assert.Equal(EntityState.Modified, entry.EntityState);
            Assert.Equal("Monkey", entity.Primate);
            Assert.Equal("Bovril", entity.Marmate);

            primateEntry.IsModified = false;

            Assert.Equal(EntityState.Modified, entry.EntityState);
            Assert.Equal("Chimp", entity.Primate);
            Assert.Equal("Bovril", entity.Marmate);

            marmateEntry.IsModified = false;

            Assert.Equal(EntityState.Unchanged, entry.EntityState);
            Assert.Equal("Chimp", entity.Primate);
            Assert.Equal("Marmite", entity.Marmate);
        }
Пример #16
0
        public void Can_reject_changes_when_clearing_modified_flag()
        {
            using (var context = new PrimateContext())
            {
                var entity = new Wotty {
                    Id = 1, Primate = "Monkey", Marmate = "Bovril", RequiredPrimate = "Tarsier"
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Unchanged);

                var primateEntry = new PropertyEntry(entry, "Primate");
                primateEntry.OriginalValue = "Chimp";
                primateEntry.IsModified    = true;

                var marmateEntry = new PropertyEntry(entry, "Marmate");
                marmateEntry.OriginalValue = "Marmite";
                marmateEntry.IsModified    = true;

                var requiredEntry = new PropertyEntry(entry, "RequiredPrimate");
                requiredEntry.OriginalValue = "Bushbaby";
                requiredEntry.IsModified    = true;

                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Monkey", entity.Primate);
                Assert.Equal("Bovril", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Monkey", entity.Primate);
                Assert.Equal("Bovril", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                primateEntry.IsModified = false;

                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Bovril", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Bovril", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                marmateEntry.IsModified = false;

                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Marmite", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();
                Assert.Equal(EntityState.Modified, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Marmite", entity.Marmate);
                Assert.Equal("Tarsier", entity.RequiredPrimate);

                requiredEntry.IsModified = false;

                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Marmite", entity.Marmate);
                Assert.Equal("Bushbaby", entity.RequiredPrimate);

                context.ChangeTracker.DetectChanges();
                Assert.Equal(EntityState.Unchanged, entry.EntityState);
                Assert.Equal("Chimp", entity.Primate);
                Assert.Equal("Marmite", entity.Marmate);
                Assert.Equal("Bushbaby", entity.RequiredPrimate);
            }
        }
Пример #17
0
        public void Can_set_and_clear_modified()
        {
            var entity = new Wotty { Id = 1, Primate = "Monkey" };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                TestHelpers.Instance.BuildModelFor<Wotty>(),
                EntityState.Unchanged,
                entity);

            Assert.False(new PropertyEntry(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = true;

            Assert.True(new PropertyEntry(entry, "Primate").IsModified);

            new PropertyEntry(entry, "Primate").IsModified = false;

            Assert.False(new PropertyEntry(entry, "Primate").IsModified);
        }
Пример #18
0
        public void Can_reject_changes_when_clearing_modified_flag()
        {
            var entity = new Wotty { Id = 1, Primate = "Monkey", Marmate = "Bovril" };

            var entry = TestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                EntityState.Unchanged,
                entity);

            var primateEntry = new PropertyEntry(entry, "Primate");
            primateEntry.OriginalValue = "Chimp";
            primateEntry.IsModified = true;

            var marmateEntry = new PropertyEntry(entry, "Marmate");
            marmateEntry.OriginalValue = "Marmite";
            marmateEntry.IsModified = true;

            Assert.Equal(EntityState.Modified, entry.EntityState);
            Assert.Equal("Monkey", entity.Primate);
            Assert.Equal("Bovril", entity.Marmate);

            primateEntry.IsModified = false;

            Assert.Equal(EntityState.Modified, entry.EntityState);
            Assert.Equal("Chimp", entity.Primate);
            Assert.Equal("Bovril", entity.Marmate);

            marmateEntry.IsModified = false;

            Assert.Equal(EntityState.Unchanged, entry.EntityState);
            Assert.Equal("Chimp", entity.Primate);
            Assert.Equal("Marmite", entity.Marmate);
        }