示例#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);
            }
        }
示例#2
0
 public ActualEntity2(int id, string name, AnEnum anEnum, int refRelId, ActualEntity1 refRel)
     : base(id, name, anEnum, refRelId, refRel)
 {
 }
示例#3
0
 public void SetRefRel(ActualEntity1 refRel)
 {
     RefRel = refRel;
 }
示例#4
0
 public EntityBase2(int id, string name, AnEnum anEnum, int refRelId, ActualEntity1 refRel)
     : base(id, name, anEnum)
 {
     RefRelId = refRelId;
     RefRel   = refRel;
 }