Ejemplo n.º 1
0
        [Fact] // CodePlex 137
        public void Entities_with_unmapped_base_class_with_private_property_setters_can_be_manipulated()
        {
            using (var context = new PrivacyContext())
            {
                var one = context.Ones.Single();
                var two = context.Twos.Single();

                var nameProperty = context.Entry(one).Property(e => e.Name);
                nameProperty.CurrentValue  = "Praise You";
                nameProperty.OriginalValue = "Right Now, Right Here";

                Assert.Equal("Praise You", one.Name);
                Assert.Equal("Praise You", nameProperty.CurrentValue);
                Assert.Equal("Right Now, Right Here", nameProperty.OriginalValue);

                var enumProperty = context.Entry(one).Property(e => e.AnEnum);
                enumProperty.CurrentValue  = AnEnum.Big;
                enumProperty.OriginalValue = AnEnum.Big;

                Assert.Equal(AnEnum.Big, one.AnEnum);
                Assert.Equal(AnEnum.Big, enumProperty.CurrentValue);
                Assert.Equal(AnEnum.Big, enumProperty.OriginalValue);

                var imageProperty = context.Entry(one).ComplexProperty(e => e.Info).Property(c => c.Image);
                imageProperty.CurrentValue  = new byte[8];
                imageProperty.OriginalValue = new byte[24];

                Assert.Equal(8, one.Info.Image.Length);
                Assert.Equal(8, imageProperty.CurrentValue.Length);
                Assert.Equal(24, imageProperty.OriginalValue.Length);

                var colRel = context.Entry(one).Collection(e => e.ColRel);
                var newCol = new List <ActualEntity2>
                {
                    new ActualEntity2(748, "Slash Dot Dash", AnEnum.Beat, 0, null)
                };
                colRel.CurrentValue = newCol;

                Assert.Same(newCol, one.ColRel);
                Assert.Same(newCol, colRel.CurrentValue);

                var refRel = context.Entry(two).Reference(e => e.RefRel);
                var newRef = new ActualEntity1(0, "Slash Dot Dash", AnEnum.Beat, new ActualComplex(new byte[10]), null);
                refRel.CurrentValue = newRef;

                Assert.Same(newRef, two.RefRel);
                Assert.Same(newRef, refRel.CurrentValue);

                var fkProperty = context.Entry(two).Property(e => e.RefRelId);
                fkProperty.CurrentValue  = 678;
                fkProperty.OriginalValue = 789;

                Assert.Equal(678, two.RefRelId);
                Assert.Equal(678, fkProperty.CurrentValue);
                Assert.Equal(789, fkProperty.OriginalValue);
            }
        }
Ejemplo n.º 2
0
        [Fact] // CodePlex 137
        public void Entities_with_unmapped_base_class_with_private_property_setters_can_be_explicitly_loaded_by_reference()
        {
            using (var context = new PrivacyContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var two = context.Twos.Single();
                context.Entry(two).Reference(e => e.RefRel).Load();
                var one = two.RefRel;

                Assert.NotEqual(0, one.Id);
                Assert.Equal("Right Here, Right Now", one.Name);
                Assert.Equal(AnEnum.Beat, one.AnEnum);
                Assert.Same(one, two.RefRel);
                Assert.Equal(one.Id, two.RefRelId);
            }
        }
Ejemplo n.º 3
0
        [Fact] // CodePlex 137
        public void Entities_with_unmapped_base_class_with_private_property_setters_can_be_explicitly_loaded_by_collection()
        {
            using (var context = new PrivacyContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var one = context.Ones.Single();
                context.Entry(one).Collection(e => e.ColRel).Load();
                var two = one.ColRel.Single();

                Assert.Equal(747, two.Id);
                Assert.Equal("Sunset", two.Name);
                Assert.Equal(AnEnum.Beat, two.AnEnum);
                Assert.Same(one, two.RefRel);
                Assert.Equal(one.Id, two.RefRelId);
            }
        }