private static object CreateSubstituteRequest(ICustomAttributeProvider request, SubstituteAttribute attribute)
        {
            var parameter = request as ParameterInfo;
            if (parameter != null)
            {
                return new SubstituteRequest(parameter.ParameterType);
            }

            var property = request as PropertyInfo;
            if (property != null)
            {
                return new SubstituteRequest(property.PropertyType);
            }

            var field = request as FieldInfo;
            if (field != null)
            {
                return new SubstituteRequest(field.FieldType);
            }

            throw new NotSupportedException(
                string.Format(
                    CultureInfo.CurrentCulture,
                    "{0} is applied to an unsupported code element {1}",
                    attribute, request));
        }
Ejemplo n.º 2
0
            internal DBUPGRADES(string Name, IRecord Owner, FieldAttributeCollection attributes)
            {
                this.name       = Name;
                this.owner      = Owner;
                this.attributes = attributes;

                substituteName = this.attributes.Get(typeof(SubstituteAttribute)) as SubstituteAttribute;
                if (substituteName == null)
                {
                    substituteName = new SubstituteAttribute(name);
                    this.attributes.Add(substituteName);
                }
            }
        public void CreateRelayedRequestThrowsNotSupportedExceptionWhenAttributeIsAppliedToUnexpectedCodeElement()
        {
            // Arrange
            var sut       = new SubstituteAttributeRelay();
            var request   = Substitute.For <ICustomAttributeProvider>();
            var attribute = new SubstituteAttribute();

            request.GetCustomAttributes(Arg.Any <Type>(), Arg.Any <bool>()).Returns(new object[] { attribute });
            var context = Substitute.For <ISpecimenContext>();
            // Act
            var e = Assert.Throws <NotSupportedException>(() => sut.Create(request, context));

            // Assert
            Assert.Contains(attribute.ToString(), e.Message);
            Assert.Contains(request.ToString(), e.Message);
        }
        public void CreateRelayedRequestThrowsNotSupportedExceptionWhenAttributeIsAppliedToUnexpectedCodeElement()
        {
            // Fixture setup
            var sut       = new SubstituteAttributeRelay();
            var request   = Substitute.For <EventInfo>();
            var attribute = new SubstituteAttribute();

            request.GetCustomAttributes(Arg.Any <Type>(), Arg.Any <bool>()).Returns(new[] { attribute });
            var context = Substitute.For <ISpecimenContext>();
            // Exercise system
            var e = Assert.Throws <NotSupportedException>(() => sut.Create(request, context));

            // Verify outcome
            Assert.Contains(attribute.ToString(), e.Message);
            Assert.Contains(request.ToString(), e.Message);
            // Teardown
        }
 public void CreateRelayedRequestThrowsNotSupportedExceptionWhenAttributeIsAppliedToUnexpectedCodeElement()
 {
     // Fixture setup
     var sut = new SubstituteAttributeRelay();
     var request = Substitute.For<EventInfo>();
     var attribute = new SubstituteAttribute();
     request.GetCustomAttributes(Arg.Any<Type>(), Arg.Any<bool>()).Returns(new[] { attribute });
     var context = Substitute.For<ISpecimenContext>();
     // Exercise system
     var e = Assert.Throws<NotSupportedException>(() => sut.Create(request, context));
     // Verify outcome
     Assert.Contains(attribute.ToString(), e.Message);
     Assert.Contains(request.ToString(), e.Message);
     // Teardown
 }
Ejemplo n.º 6
0
        private static object CreateSubstituteRequest(ICustomAttributeProvider request, SubstituteAttribute attribute)
        {
            switch (request)
            {
            case ParameterInfo parameter:
                return(new SubstituteRequest(parameter.ParameterType));

            case PropertyInfo property:
                return(new SubstituteRequest(property.PropertyType));

            case FieldInfo field:
                return(new SubstituteRequest(field.FieldType));

            default:
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "{0} is applied to an unsupported code element {1}",
                              attribute,
                              request));
            }
        }
        private static object CreateSubstituteRequest(ICustomAttributeProvider request, SubstituteAttribute attribute)
        {
            var parameter = request as ParameterInfo;

            if (parameter != null)
            {
                return(new SubstituteRequest(parameter.ParameterType));
            }

            var property = request as PropertyInfo;

            if (property != null)
            {
                return(new SubstituteRequest(property.PropertyType));
            }

            var field = request as FieldInfo;

            if (field != null)
            {
                return(new SubstituteRequest(field.FieldType));
            }

            throw new NotSupportedException(
                      string.Format(
                          CultureInfo.CurrentCulture,
                          "{0} is applied to an unsupported code element {1}",
                          attribute, request));
        }