コード例 #1
0
        public override string ToString()
        {
            var result = new StringBuilder();

            if (MethodBase is MethodInfo info)
            {
                if (info.ReturnType != typeof(void))
                {
                    result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" ");
                }
                else
                {
                    result.Append("void ");
                }
            }

            result.Append(MethodBase.Name);
            if (MethodBase.IsGenericMethod)
            {
                var generic = ((MethodInfo)MethodBase).GetGenericMethodDefinition();
                result
                .Append("<")
                .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name)))
                .Append(">");
            }

            result
            .Append("(")
            .Append(Arguments.ToString())
            .Append(")");

            return(result.ToString());
        }
コード例 #2
0
        public void Ctor_ValueIsGuid_SetsValue()
        {
            var expected = Guid.NewGuid().ToString();

            var value = new Stringly <Guid>(expected).Value;

            Assert.That(value, Is.EqualTo(expected));
        }
コード例 #3
0
        public void ImplicitString_BooleanValue_ReturnsStringPassed()
        {
            var expected = "FALSE";

            string result = new Stringly <bool>(expected);

            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #4
0
        public void ToString_BooleanValue_ReturnsStringPassed()
        {
            var expected = "FALSE";

            var result = new Stringly <bool>(expected).ToString();

            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #5
0
        public void Ctor_ValueIsInt_SetsValue()
        {
            var expected = 42.ToString();

            var value = new Stringly <int>(expected).Value;

            Assert.That(value, Is.EqualTo(expected));
        }
コード例 #6
0
ファイル: MethodInvocation.cs プロジェクト: wmadzha/moq
        public override string ToString()
        {
            var result = new StringBuilder();

            if (MethodBase is MethodInfo info)
            {
                if (info.ReturnType != typeof(void))
                {
                    result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" ");
                }
                else
                {
                    result.Append("void ");
                }
            }

            if (MethodBase.IsSpecialName)
            {
                if (MethodBase.Name.StartsWith("get_", StringComparison.Ordinal) ||
                    MethodBase.Name.StartsWith("set_", StringComparison.Ordinal))
                {
                    result.Append(MethodBase.Name.Substring(4));
                }
                else if (MethodBase.Name.StartsWith("add_", StringComparison.Ordinal))
                {
                    result.Append(MethodBase.Name.Substring(4) + " += ");
                }
                else if (MethodBase.Name.StartsWith("remove_", StringComparison.Ordinal))
                {
                    result.Append(MethodBase.Name.Substring(7) + " -= ");
                }
            }
            else
            {
                result.Append(MethodBase.Name);
            }

            if (MethodBase.IsGenericMethod)
            {
                var generic = ((MethodInfo)MethodBase).GetGenericMethodDefinition();
                result
                .Append("<")
                .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name)))
                .Append(">");
            }

            // TODO: render indexer arguments?
            if (!MethodBase.IsSpecialName)
            {
                return(result
                       .Append("(")
                       .Append(Arguments.ToString())
                       .Append(")")
                       .ToString());
            }

            return(result.ToString());
        }
コード例 #7
0
ファイル: Samples.cs プロジェクト: rioka/Stringly.Typed
        public void StringlyComplexType_GivenAString_ValidatesAndCreatesTypeCorrectly()
        {
            Assert.That(_service.CalculateArea(new Stringly <Size>("10x10")), Is.EqualTo(100));

            Size size = new Stringly <Size>("42x1337");

            Assert.That(size.Width, Is.EqualTo(42));
            Assert.That(size.Height, Is.EqualTo(1337));

            Assert.Throws <ArgumentOutOfRangeException>(
                () => new Stringly <Size>("w:10 h:10"));
        }
コード例 #8
0
        public override string ToString()
        {
            var result = new StringBuilder();

            if (setup.MethodBase is MethodInfo info)
            {
                if (info.ReturnType != typeof(void))
                {
                    result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" ");
                }
                else
                {
                    result.Append("void ");
                }
            }

            result.Append(setup.MethodBase.Name);
            if (setup.MethodBase.IsGenericMethod)
            {
                var generic = ((MethodInfo)setup.MethodBase).GetGenericMethodDefinition();
                result
                .Append("<")
                .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name)))
                .Append(">");
            }

            var parameters = setup.MethodBase.GetParameters();

            return(result
                   .Append("(")
                   .Append(string.Join(", ", parameters.Select((p, i) =>
                                                               Stringly.ToTypeName(p.ParameterType) + " " +
                                                               p.Name + " = " +
                                                               matchers[i].ToString()
                                                               )))
                   .Append(")")
                   .ToString());
        }
コード例 #9
0
        public void Ctor_ValueMatchesRegex_CreatesComplexType()
        {
            DigitsOnly stringly = new Stringly <DigitsOnly>("0000");

            Assert.That(stringly.Digits.Count, Is.EqualTo(4));
        }
コード例 #10
0
 public void Ctor_TypedThatThrows_ThrowsArgumentOutOfRangeException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => { Stringly <TypeWithTypeParseThatThrows> value = "test"; });
 }
コード例 #11
0
 public override string ToString() => "Any<" + Stringly.ToTypeName(ArgumentType) + ">";
コード例 #12
0
 public static int Increment(Stringly <int> digits)
 {
     return(digits + 1);
 }
コード例 #13
0
ファイル: MockSetup.cs プロジェクト: wmadzha/moq
        public override string ToString()
        {
            var result = new StringBuilder();

            if (invocation.MethodBase is MethodInfo info)
            {
                if (info.ReturnType != typeof(void))
                {
                    result.Append(Stringly.ToTypeName(info.ReturnType)).Append(" ");
                }
                else
                {
                    result.Append("void ");
                }
            }

            if (invocation.MethodBase.IsSpecialName)
            {
                if (invocation.MethodBase.Name.StartsWith("get_", StringComparison.Ordinal) ||
                    invocation.MethodBase.Name.StartsWith("set_", StringComparison.Ordinal))
                {
                    result.Append(invocation.MethodBase.Name.Substring(4));
                }
                else if (invocation.MethodBase.Name.StartsWith("add_", StringComparison.Ordinal))
                {
                    result.Append(invocation.MethodBase.Name.Substring(4) + " += ");
                }
                else if (invocation.MethodBase.Name.StartsWith("remove_", StringComparison.Ordinal))
                {
                    result.Append(invocation.MethodBase.Name.Substring(7) + " -= ");
                }
            }
            else
            {
                result.Append(invocation.MethodBase.Name);
            }

            if (invocation.MethodBase.IsGenericMethod)
            {
                var generic = ((MethodInfo)invocation.MethodBase).GetGenericMethodDefinition();
                result
                .Append("<")
                .Append(string.Join(", ", generic.GetGenericArguments().Select(t => t.Name)))
                .Append(">");
            }

            var parameters = invocation.MethodBase.GetParameters();

            // TODO: render indexer arguments?
            if (!invocation.MethodBase.IsSpecialName)
            {
                return(result
                       .Append("(")
                       .Append(string.Join(", ", parameters.Select((p, i) =>
                                                                   (p.IsOut ? "out " : (p.ParameterType.IsByRef ? "ref " : "")) +
                                                                   Stringly.ToTypeName(p.ParameterType) + " " +
                                                                   p.Name +
                                                                   (p.IsOut ? "" : (" = " + matchers[i]))
                                                                   )))
                       .Append(")")
                       .ToString());
            }

            return(result.ToString());
        }
コード例 #14
0
 public void Ctor_GivenAString_ThrowsArgumentOutOfRangeException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => { Stringly <TypeWithoutTryParseMethod> cat = "nyan"; });
 }
コード例 #15
0
ファイル: Samples.cs プロジェクト: rioka/Stringly.Typed
 internal void DontWantToNewStringly(Stringly <RecordId> recordId)
 {
     RecordId id = recordId;
 }