Ejemplo n.º 1
0
        public void SutDoesNotEqualAnonymousObject(object other)
        {
            var sut    = new ParameterInfoElement(TypeWithParameters.Parameter);
            var actual = sut.Equals(other);

            Assert.False(actual);
        }
        public void ToElementForParameterInfoReturnsTheCorrectElement()
        {
            ParameterInfo        expected = TypeWithAllElements.ParameterInfo;
            ParameterInfoElement actual   = expected.ToElement();

            Assert.Equal(new ParameterInfoElement(expected), actual);
        }
Ejemplo n.º 3
0
 public void SutIsReflectionElement()
 {
     // Fixture setup
     // Exercise system
     var sut = new ParameterInfoElement(TypeWithParameters.Parameter);
     // Verify outcome
     Assert.IsAssignableFrom<IReflectionElement>(sut);
     // Teardown
 }
Ejemplo n.º 4
0
 public void AcceptNullVisitorThrows()
 {
     // Fixture setup
     var sut = new ParameterInfoElement(TypeWithParameters.Parameter);
     // Exercise system
     // Verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Accept((IReflectionVisitor<object>)null));
     // Teardown
 }
Ejemplo n.º 5
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var par   = TypeWithParameters.Parameter;
            var sut   = new ParameterInfoElement(par);
            var other = new ParameterInfoElement(par);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
        public void GetHashCodeReturnsCorrectResult()
        {
            var par = TypeWithParameter.Parameter;
            var sut = new ParameterInfoElement(par);

            var actual = sut.GetHashCode();

            var expected = par.GetHashCode();
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void SutIsReflectionElement()
        {
            // Fixture setup
            // Exercise system
            var sut = new ParameterInfoElement(TypeWithParameters.Parameter);

            // Verify outcome
            Assert.IsAssignableFrom <IReflectionElement>(sut);
            // Teardown
        }
Ejemplo n.º 8
0
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut            = new ParameterInfoElement(TypeWithParameters.Parameter);
            var otherParameter = TypeWithParameters.OtherParameter;
            var other          = new ParameterInfoElement(otherParameter);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
Ejemplo n.º 9
0
        public override IReflectionVisitor <IEnumerable> Visit(
            ParameterInfoElement parameterInfoElement)
        {
            var v = new SemanticComparisonValue(
                parameterInfoElement.ParameterInfo.Name,
                parameterInfoElement.ParameterInfo.ParameterType);

            return(new SemanticReflectionVisitor(
                       this.values.Concat(new[] { v }).ToArray()));
        }
Ejemplo n.º 10
0
        public void SutEqualsOtherIdenticalInstance()
        {
            var par = TypeWithParameters.Parameter;
            var sut = new ParameterInfoElement(par);
            var other = new ParameterInfoElement(par);

            var actual = sut.Equals(other);

            Assert.True(actual);
        }
Ejemplo n.º 11
0
        public void AcceptNullVisitorThrows()
        {
            // Fixture setup
            var sut = new ParameterInfoElement(TypeWithParameters.Parameter);

            // Exercise system
            // Verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Accept((IReflectionVisitor <object>)null));
            // Teardown
        }
Ejemplo n.º 12
0
        public void GetHashCodeReturnsCorrectResult()
        {
            var par = TypeWithParameters.Parameter;
            var sut = new ParameterInfoElement(par);

            var actual = sut.GetHashCode();

            var expected = par.GetHashCode();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 13
0
        public override IReflectionVisitor <bool> Visit(ParameterInfoElement parameterInfoElement)
        {
            if (object.ReferenceEquals(parameterInfoElement, null))
            {
                throw new ArgumentNullException(nameof(parameterInfoElement));
            }

            var pi = parameterInfoElement.ParameterInfo;

            return(this.Proceed(expected, this.value || this.IsMatch(pi.ParameterType, pi.Name)));
        }
Ejemplo n.º 14
0
 public void ParameterInfoIsCorrect()
 {
     // Fixture setup
     var expected = TypeWithParameters.Parameter;
     var sut = new ParameterInfoElement(expected);
     // Exercise system
     ParameterInfo actual = sut.ParameterInfo;
     // Verify outcome
     Assert.Equal(expected, actual);
     // Teardown
 }
Ejemplo n.º 15
0
        public void VisitParameterInfoElementReturnsCorrectResult()
        {
            var sut = new ReflectionVisitor();
            var parameterInfoElement =
                new ParameterInfoElement(new Dummy().Parameter);

            var actual = sut.Visit(parameterInfoElement);

            var expected = sut;

            Assert.Same(expected, actual);
        }
Ejemplo n.º 16
0
        public void ParameterInfoIsCorrect()
        {
            // Fixture setup
            var expected = TypeWithParameters.Parameter;
            var sut      = new ParameterInfoElement(expected);
            // Exercise system
            ParameterInfo actual = sut.ParameterInfo;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Ejemplo n.º 17
0
            public override IReflectionVisitor <IEnumerable <NameAndType> > Visit(
                ParameterInfoElement parameterInfoElement)
            {
                if (parameterInfoElement == null)
                {
                    throw new ArgumentNullException("parameterInfoElement");
                }
                var v = new NameAndType(
                    parameterInfoElement.ParameterInfo.Name,
                    parameterInfoElement.ParameterInfo.ParameterType);

                return(new NameAndTypeCollectingVisitor(
                           this.values.Concat(new[] { v }).ToArray()));
            }
Ejemplo n.º 18
0
        public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance()
        {
            // Fixture setup
            var expected = new DelegatingReflectionVisitor<int>();
            var sut = new ParameterInfoElement(TypeWithParameters.Parameter);
            var visitor = new DelegatingReflectionVisitor<int>
            {
                OnVisitParameterInfoElement = e =>
                    e == sut ? expected : new DelegatingReflectionVisitor<int>()
            };

            // Exercise system
            var actual = sut.Accept(visitor);
            // Verify outcome
            Assert.Same(expected, actual);
            // Teardown
        }
Ejemplo n.º 19
0
        public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance()
        {
            // Fixture setup
            var expected = new DelegatingReflectionVisitor <int>();
            var sut      = new ParameterInfoElement(TypeWithParameters.Parameter);
            var visitor  = new DelegatingReflectionVisitor <int>
            {
                OnVisitParameterInfoElement = e =>
                                              e == sut ? expected : new DelegatingReflectionVisitor <int>()
            };

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

            // Verify outcome
            Assert.Same(expected, actual);
            // Teardown
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
 public virtual IReflectionVisitor <T> Visit(ParameterInfoElement parameterInfoElement)
 {
     return(OnVisitParameterInfoElement(parameterInfoElement));
 }
Ejemplo n.º 23
0
        private string ParametersFilename(ParameterInfoElement[] parameters)
        {
            string result = string.Join(",", parameters.Select(p => FilenamePartForParameter(p.ParameterType)));
            if (result.Length > 100) {
                // prevent too long filenames
                result = GetMD5Hash(result);
            }

            return result;
        }
Ejemplo n.º 24
0
        public void SutDoesNotEqualDifferentInstanceOfSameType()
        {
            var sut = new ParameterInfoElement(TypeWithParameters.Parameter);
            var otherParameter = TypeWithParameters.OtherParameter;
            var other = new ParameterInfoElement(otherParameter);

            var actual = sut.Equals(other);

            Assert.False(actual);
        }
Ejemplo n.º 25
0
 public void SutDoesNotEqualAnonymousObject(object other)
 {
     var sut = new ParameterInfoElement(TypeWithParameters.Parameter);
     var actual = sut.Equals(other);
     Assert.False(actual);
 }