Exemple #1
0
        private void Can_set_and_get_original_value_starting_null_helper <TWotty>()
            where TWotty : IWotty, new()
        {
            using (var context = new PrimateContext())
            {
                var entity = new TWotty {
                    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);
            }
        }
Exemple #2
0
        private void Can_set_original_value_to_null_helper <TWotty>()
            where TWotty : IWotty, new()
        {
            using var context = new PrimateContext();
            var entity = new TWotty
            {
                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);
        }
Exemple #3
0
        private void Can_set_current_value_helper <TWotty>()
            where TWotty : IWotty, new()
        {
            using var context = new PrimateContext();
            var entity = new TWotty
            {
                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);
        }
Exemple #4
0
        private void Can_set_current_value_to_null_generic_helper <TWotty>()
            where TWotty : class, IWotty, new()
        {
            var entity = new TWotty {
                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);
        }
Exemple #5
0
        private void Can_set_and_get_original_value_generic_helper <TWotty>()
            where TWotty : class, IWotty, new()
        {
            var entity = new TWotty {
                Id = 1, Primate = "Monkey"
            };

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

            Assert.Equal("Monkey", new PropertyEntry <Wotty, string>(entry, "Primate").OriginalValue);

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

            Assert.Equal("Chimp", new PropertyEntry <Wotty, string>(entry, "Primate").OriginalValue);
            Assert.Equal("Monkey", entity.Primate);
        }
Exemple #6
0
        private void Can_set_and_clear_modified_on_Modified_entity_helper <TWotty>()
            where TWotty : IWotty, new()
        {
            using (var context = new PrimateContext())
            {
                var entity = new TWotty {
                    Id = 1
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Modified);

                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);

                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);
            }
        }
Exemple #7
0
        private void Can_set_and_clear_modified_generic_helper <TWotty>()
            where TWotty : class, IWotty, new()
        {
            var entity = new TWotty {
                Id = 1, Primate = "Monkey"
            };

            var entry = InMemoryTestHelpers.Instance.CreateInternalEntry(
                BuildModel(),
                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);
        }
Exemple #8
0
        private void Can_reject_changes_when_clearing_modified_flag_helper <TWotty>()
            where TWotty : IWotty, new()
        {
            using (var context = new PrimateContext())
            {
                var entity = new TWotty {
                    Id = 1, Primate = "Monkey", Marmate = "Bovril", RequiredPrimate = "Tarsier"
                };
                var entry = context.Entry(entity).GetInfrastructure();
                entry.SetEntityState(EntityState.Unchanged);

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

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

                var requiredEntry = new PropertyEntry(entry, "RequiredPrimate")
                {
                    OriginalValue = "Bushbaby", 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);
            }
        }