Пример #1
0
        public void SutDoesNotEqualAnonymousObject(object other)
        {
            var sut    = new PropertyInfoElement(TypeWithProperties.Property);
            var actual = sut.Equals(other);

            Assert.False(actual);
        }
        public void ToElementForPropertyInfoReturnsTheCorrectElement()
        {
            PropertyInfo        expected = typeof(TypeWithAllElements).GetProperty("TheProperty");
            PropertyInfoElement actual   = expected.ToElement();

            Assert.Equal(new PropertyInfoElement(expected), actual);
        }
 public override IReflectionVisitor <bool> Visit(
     PropertyInfoElement propertyInfoElement)
 {
     if (_searchedType == propertyInfoElement.PropertyInfo.PropertyType)
     {
         value = true;
     }
     return(this);
 }
Пример #4
0
 public void SutIsReflectionElement()
 {
     // Fixture setup
     // Exercise system
     var sut = new PropertyInfoElement(TypeWithProperties.Property);
     // Verify outcome
     Assert.IsAssignableFrom<IReflectionElement>(sut);
     // Teardown
 }
        public override IReflectionVisitor <IEnumerable> Visit(
            PropertyInfoElement propertyInfoElement)
        {
            var value =
                propertyInfoElement.PropertyInfo.GetValue(this.target, null);

            return(new ValueCollectingVisitor(
                       this.target,
                       this.values.Concat(new[] { value }).ToArray()));
        }
Пример #6
0
        public override IReflectionVisitor <IEnumerable> Visit(
            PropertyInfoElement propertyInfoElement)
        {
            var v = new SemanticComparisonValue(
                propertyInfoElement.PropertyInfo.Name,
                propertyInfoElement.PropertyInfo.PropertyType);

            return(new SemanticReflectionVisitor(
                       this.values.Concat(new[] { v }).ToArray()));
        }
Пример #7
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var pi    = TypeWithProperties.Property;
            var sut   = new PropertyInfoElement(pi);
            var other = new PropertyInfoElement(pi);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
 public void AcceptNullVisitorThrows()
 {
     // Fixture setup
     var sut = new PropertyInfoElement(TypeWithProperty.Property);
     // Exercise system
     // Verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Accept((IReflectionVisitor<object>)null));
     // Teardown
 }
        public void GetHashCodeReturnsCorrectResult()
        {
            var pi = TypeWithProperty.Property;
            var sut = new PropertyInfoElement(pi);

            var actual = sut.GetHashCode();

            var expected = pi.GetHashCode();
            Assert.Equal(expected, actual);
        }
Пример #10
0
        public void SutIsReflectionElement()
        {
            // Fixture setup
            // Exercise system
            var sut = new PropertyInfoElement(TypeWithProperties.Property);

            // Verify outcome
            Assert.IsAssignableFrom <IReflectionElement>(sut);
            // Teardown
        }
Пример #11
0
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut           = new PropertyInfoElement(TypeWithProperties.Property);
            var otherProperty = TypeWithProperties.OtherProperty;
            var other         = new PropertyInfoElement(otherProperty);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
Пример #12
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var pi = TypeWithProperties.Property;
            var sut = new PropertyInfoElement(pi);
            var other = new PropertyInfoElement(pi);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
Пример #13
0
        public void AcceptNullVisitorThrows()
        {
            // Fixture setup
            var sut = new PropertyInfoElement(TypeWithProperties.Property);

            // Exercise system
            // Verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Accept((IReflectionVisitor <object>)null));
            // Teardown
        }
Пример #14
0
        public void GetHashCodeReturnsCorrectResult()
        {
            var pi  = TypeWithProperties.Property;
            var sut = new PropertyInfoElement(pi);

            var actual = sut.GetHashCode();

            var expected = pi.GetHashCode();

            Assert.Equal(expected, actual);
        }
Пример #15
0
        public void ReadFromProperty()
        {
            PropertyInfo pi = from v in new Properties <Version>()
                              select v.Minor;
            var version = new Version(2, 7);
            var visitor = new ValueCollectingVisitor(version);

            var actual = new PropertyInfoElement(pi).Accept(visitor);

            Assert.Equal(version.Minor, actual.Value.OfType <int>().First());
        }
Пример #16
0
        public override IReflectionVisitor <bool> Visit(PropertyInfoElement propertyInfoElement)
        {
            if (object.ReferenceEquals(propertyInfoElement, null))
            {
                throw new ArgumentNullException(nameof(propertyInfoElement));
            }

            var pi = propertyInfoElement.PropertyInfo;

            return(this.Proceed(expected, this.value || this.IsMatch(pi.PropertyType, pi.Name)));
        }
Пример #17
0
        public void ReadFromProperty()
        {
            PropertyInfo pi = from v in new Properties<Version>()
                              select v.Minor;
            var version = new Version(2, 7);
            var visitor = new ValueCollectingVisitor(version);

            var actual = new PropertyInfoElement(pi).Accept(visitor);

            Assert.Equal(version.Minor, actual.Value.OfType<int>().First());
        }
 public void PropertyInfoIsCorrect()
 {
     // Fixture setup
     var expected = TypeWithProperty.Property;
     var sut = new PropertyInfoElement(expected);
     // Exercise system
     PropertyInfo actual = sut.PropertyInfo;
     // Verify outcome
     Assert.Equal(expected, actual);
     // Teardown
 }
Пример #19
0
        public void PropertyInfoIsCorrect()
        {
            // Fixture setup
            var expected = TypeWithProperties.Property;
            var sut      = new PropertyInfoElement(expected);
            // Exercise system
            PropertyInfo actual = sut.PropertyInfo;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Пример #20
0
        public void VisitPropertyInfoElementReturnsCorrectResult()
        {
            var sut = new ReflectionVisitor();
            var propertyInfoElement =
                new PropertyInfoElement(new Dummy().Property);

            var actual = sut.Visit(propertyInfoElement);

            var expected = sut;

            Assert.Same(expected, actual);
        }
Пример #21
0
        public override IReflectionVisitor <Action <object> > Visit(
            PropertyInfoElement propertyInfoElement)
        {
            Action <object> a =
                v => propertyInfoElement.PropertyInfo.SetValue(
                    this.target,
                    v,
                    null);

            return(new ValueWritingVisitor(
                       this.target,
                       this.actions.Concat(new[] { a }).ToArray()));
        }
Пример #22
0
            public override IReflectionVisitor <IEnumerable <NameAndType> > Visit(
                PropertyInfoElement propertyInfoElement)
            {
                if (propertyInfoElement == null)
                {
                    throw new ArgumentNullException("propertyInfoElement");
                }
                var v = new NameAndType(
                    propertyInfoElement.PropertyInfo.Name,
                    propertyInfoElement.PropertyInfo.PropertyType);

                return(new NameAndTypeCollectingVisitor(
                           this.values.Concat(new[] { v }).ToArray()));
            }
Пример #23
0
    public override IReflectionVisitor <object> Visit(PropertyInfoElement propertyInfoElement)
    {
        var pi = propertyInfoElement.PropertyInfo;

        if (pi.PropertyType.IsConstructedGenericType &&
            pi.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>) &&
            pi.CanWrite)
        {
            var elementType = pi.PropertyType.GetGenericArguments().Single();
            pi.SetValue(value, Array.CreateInstance(elementType, 0));
            return(this);
        }
        return(base.Visit(propertyInfoElement));
    }
        public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance()
        {
            // Fixture setup
            var expected = new DelegatingReflectionVisitor<int>();
            var sut = new PropertyInfoElement(TypeWithProperty.Property);
            var visitor = new DelegatingReflectionVisitor<int>
            {
                OnVisitPropertyInfoElement = e =>
                    e == sut ? expected : new DelegatingReflectionVisitor<int>()
            };

            // Exercise system
            var actual = sut.Accept(visitor);
            // Verify outcome
            Assert.Same(expected, actual);
            // Teardown
        }
Пример #25
0
        public void MatchConstructorArgumentAgainstReadOnlyProperty(
            string propertyName, string parameterName, bool expected)
        {
            var prop = new PropertyInfoElement(
                typeof(Version).GetProperty(propertyName));
            var param = new ParameterInfoElement(
                typeof(Version)
                .GetConstructor(new[] { typeof(int), typeof(int) })
                .GetParameters()
                .Where(p => p.Name == parameterName)
                .Single());

            var actual =
                new SemanticElementComparer(new SemanticReflectionVisitor())
                .Equals(prop, param);

            Assert.Equal(expected, actual);
        }
Пример #26
0
        public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance()
        {
            // Fixture setup
            var expected = new DelegatingReflectionVisitor <int>();
            var sut      = new PropertyInfoElement(TypeWithProperties.Property);
            var visitor  = new DelegatingReflectionVisitor <int>
            {
                OnVisitPropertyInfoElement = e =>
                                             e == sut ? expected : new DelegatingReflectionVisitor <int>()
            };

            // Exercise system
            var actual = sut.Accept(visitor);

            // Verify outcome
            Assert.Same(expected, actual);
            // Teardown
        }
Пример #27
0
        public void MatchContructorArgumentAgainstReadOnlyProperty(
            string propertyName, string parameterName, bool expected)
        {
            var prop = new PropertyInfoElement(
                typeof(Version).GetProperty(propertyName));
            var param = new ParameterInfoElement(
                typeof(Version)
                    .GetConstructor(new[] { typeof(int), typeof(int) })
                    .GetParameters()
                    .Where(p => p.Name == parameterName)
                    .Single());

            var actual =
                new SemanticElementComparer(new SemanticReflectionVisitor())
                    .Equals(prop, param);

            Assert.Equal(expected, actual);
        }
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut = new PropertyInfoElement(TypeWithProperty.Property);
            var otherProperty = TypeWithProperty.OtherProperty;
            var other = new PropertyInfoElement(otherProperty);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
 public void SutDoesNotEqualAnonymousObject(object other)
 {
     var sut = new PropertyInfoElement(TypeWithProperty.Property);
     var actual = sut.Equals(other);
     Assert.False(actual);
 }
Пример #30
0
 public virtual IReflectionVisitor <T> Visit(PropertyInfoElement propertyInfoElement)
 {
     return(OnVisitPropertyInfoElement(propertyInfoElement));
 }