public void TestThatLongNameThrowsOnEmptyString()
        {
            var attrib = new ArgumentValueAttribute();

            attrib.Invoking(a => a.LongName = string.Empty)
            .Should().Throw <InvalidArgumentSetException>();
        }
        public void TestThatLongNameAcceptsNull()
        {
            var attrib = new ArgumentValueAttribute();

            attrib.Invoking(a => a.LongName = null)
            .Should().NotThrow <InvalidArgumentSetException>();
        }
Exemplo n.º 3
0
 private static bool TryGetArgumentValueAttribute(FieldInfo fieldInfo, out ArgumentValueAttribute attribute)
 {
     // Look for an <see cref="ArgumentValueAttribute" /> attribute,
     // which might further customize how we can parse strings into
     // this value.
     attribute = fieldInfo.GetSingleAttribute <ArgumentValueAttribute>(inherit: false);
     return(attribute != null);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Basic constructor.
        /// </summary>
        /// <param name="fieldInfo">Information for the value.</param>
        public EnumArgumentValue(FieldInfo fieldInfo)
        {
            _fieldInfo = fieldInfo;

            try
            {
                Value = _fieldInfo.GetValue(null);
            }
            catch (InvalidOperationException)
            {
                Value = _fieldInfo.GetRawConstantValue();
            }

            if (Value == null)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldInfo));
            }

            _attribute =
                GetAttributes <ArgumentValueAttribute>().SingleOrDefault() ??
                new ArgumentValueAttribute();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Basic constructor.
        /// </summary>
        /// <param name="fieldInfo">Information for the value.</param>
        public EnumArgumentValue(FieldInfo fieldInfo)
        {
            _fieldInfo = fieldInfo;

            try
            {
                Value = _fieldInfo.GetValue(null);
            }
            catch (InvalidOperationException)
            {
                Value = _fieldInfo.GetRawConstantValue();
            }

            if (Value == null)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldInfo));
            }

            if (!TryGetArgumentValueAttribute(fieldInfo, out _attribute))
            {
                _attribute = new ArgumentValueAttribute();
            }
        }