Example #1
0
        public void CheckValue(DbContext ctx, object actual)
        {
            var propertyType = Accessor.MemberType;

            var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
            var entitySet = objectContext.GetEntitySet(propertyType);
            var keyMembers = entitySet.ElementType.KeyMembers;

            ctx.Entry(actual).Reference(Accessor.Name).Load();

            var actualEntity = Accessor.GetValue(actual);
            if (actualEntity == null)
            {
                throw new AssertionException(ExpectedEntity.Dump(), "NULL");
            }
            foreach (var keyMember in keyMembers)
            {
                var accessor = new PropertyAccessor(propertyType.GetProperty(keyMember.Name));

                var actualKeyValue = accessor.GetValue(actualEntity);
                var expectedKeyValue = accessor.GetValue(ExpectedEntity);

                if (!expectedKeyValue.Equals(actualKeyValue))
                {
                    throw new AssertionException(ExpectedEntity.Dump(), actualEntity.Dump());
                }
            }
        }
Example #2
0
 public Property(PropertyAccessor accessor, object expectedValue)
 {
     _accessor = accessor;
     _expectedValue = expectedValue;
 }
Example #3
0
 public Reference(PropertyAccessor propertyAccessor, object expectedEntity)
 {
     Accessor = propertyAccessor;
     ExpectedEntity = expectedEntity;
 }