Exemple #1
0
        public void Parse_should_create_class_generic_parameters_dereference()
        {
            var method = MethodName.Parse("System.Class`2..ctor(`0,`1)");

            Assert.Same(method.DeclaringType.GenericParameters[0], method.Parameters[0].ParameterType);
            Assert.Same(method.DeclaringType.GenericParameters[1], method.Parameters[1].ParameterType);
        }
Exemple #2
0
        public void Parse_should_create_method_generic_parameters_dereference()
        {
            var method = MethodName.Parse("System.Class.Invoke``2(``0,``1)");

            Assert.Same(method.GenericParameters[0], method.Parameters[0].ParameterType);
            Assert.Same(method.GenericParameters[1], method.Parameters[1].ParameterType);
        }
Exemple #3
0
        public void Parse_should_parse_byref_type()
        {
            var method = MethodName.Parse("TryParse(String,Int32&)");

            Assert.Null(method.DeclaringType);
            Assert.Equal("TryParse(String, Int32&)", method.ToString());
        }
        public void SetMethod_should_generate_from_property_or_indexer(string name, string expected)
        {
            var pn     = PropertyName.Parse(name);
            var setter = MethodName.Parse(expected);

            Assert.Equal(setter, pn.SetMethod);
        }
Exemple #5
0
        public void Parse_should_throw_on_errors(string text)
        {
            var ex = Record.Exception(() => MethodName.Parse(text));

            Assert.IsInstanceOf(typeof(ArgumentException), ex);
            Assert.Contains("instance of type `Carbonfrost.Commons.DotNet.MethodName'", ex.Message);
        }
Exemple #6
0
        public void get_operator_name_semantics()
        {
            var type  = TypeName.Parse("System.Int32");
            var adder = type.GetOperator(OperatorType.Addition);

            Assert.Equal(MethodName.Parse("System.Int32.op_Addition(System.Int32, System.Int32) : System.Int32"), adder);
        }
Exemple #7
0
        public void RemoveParameters_should_apply_to_names(string name)
        {
            var method    = MethodName.Parse(name);;
            var newMethod = method.RemoveParameters();

            Assert.Equal("TryParse()", newMethod.ToString());
        }
Exemple #8
0
        public void Matches_should_apply_to_all_less_specific_names(string text)
        {
            var method1 = MethodName.Parse(text);
            var name    = MethodName.Parse("System.UInt32.TryParse(String, UInt32&)");

            Assert.True(method1.Matches(name));
        }
Exemple #9
0
        public void RemoveParameterAt_should_remove_specified_index(int index, string expected)
        {
            var method    = MethodName.Parse("TryParse(A,B)");
            var newMethod = method.RemoveParameterAt(index);

            Assert.Equal(expected, newMethod.ToString());
        }
Exemple #10
0
        public void Parse_should_parse_pointer_type_arg()
        {
            var method = MethodName.Parse(".ctor(Char*)");

            Assert.Null(method.DeclaringType);
            Assert.Equal("Char*", method.Parameters[0].ToString());
        }
Exemple #11
0
        public void Parse_implied_nested_generic_type()
        {
            MethodName id = MethodName.Parse("System.Collections.Generic.Dictionary`2.ValueCollection.CopyTo()");

            Assert.Equal("CopyTo", id.Name);
            Assert.Equal("System.Collections.Generic.Dictionary`2+ValueCollection", id.DeclaringType.FullName);
        }
Exemple #12
0
        public void SetParameter_should_apply_new_parameter_names_and_types()
        {
            var method    = MethodName.Parse("TryParse(text:)");
            var newMethod = method.SetParameter(0, "text", TypeName.FromType(typeof(string)));

            Assert.Equal("TryParse(System.String text)", newMethod.ToString());
        }
Exemple #13
0
        public void Create_should_create_method_name_from_name()
        {
            var a = MethodName.Create("Hello");
            var b = MethodName.Parse("Hello");

            Assert.Equal(a, b);
        }
Exemple #14
0
        public void Equals_should_apply_to_parsed_elements(string text)
        {
            var a = MethodName.Parse(text);
            var b = MethodName.Parse(text);

            Assert.Equal(b, a);
        }
Exemple #15
0
        public void SetParameter_should_apply_modifiers()
        {
            var method    = MethodName.Parse("TryParse(text:)");
            var newMethod = method.SetParameter(0, "text", TypeName.FromType(typeof(string)),
                                                new [] { TypeName.Parse("Const") }, new [] { TypeName.Parse("Volatile") });

            Assert.Equal("TryParse(modreq(Const) modopt(Volatile) System.String text)", newMethod.ToString());
        }
Exemple #16
0
        public void Matches_method_generic_parameter_count()
        {
            var subject = MethodName.Parse("System.Array.ConvertAll<TInput,TOutput>(TInput[], Converter<TInput, TOutput>)");

            Assert.True(MethodName.Parse("System.Array.ConvertAll<TInput,TOutput>(TInput[], Converter<TInput, TOutput>)").Matches(subject));
            Assert.True(MethodName.Parse("ConvertAll<TInput,TOutput>(TInput[], Converter<TInput, TOutput>)").Matches(subject));
            Assert.False(MethodName.Parse("ConvertAll(TInput[], Converter<TInput, TOutput>)").Matches(subject));
        }
Exemple #17
0
        public void Matches_should_apply_to_byref_parameters()
        {
            var method1 = MethodName.Parse("System.UInt32.TryParse(String, UInt32&)");
            var method2 = MethodName.Parse("System.UInt32.TryParse(String, UInt32&)");

            Assert.True(method1.Equals(method2));
            Assert.True(method1.Matches(method2));
        }
Exemple #18
0
        public void AddParameter_should_apply_new_parameter_names_and_types()
        {
            var method    = MethodName.Parse("TryParse");
            var newMethod = method.AddParameter("text", TypeName.FromType(typeof(string)))
                            .AddParameter("value", TypeName.Parse("Byte&"));

            Assert.Equal("TryParse(System.String text, Byte& value)", newMethod.ToString());
        }
Exemple #19
0
        public void AssociatedMember_creates_event_name_unspecified_parameters(string methodName)
        {
            var accessor = MethodName.Parse(methodName);
            var evt      = EventName.Parse("INotifyPropertyChanged.PropertyChanged");

            Assert.Equal(evt, accessor.AssociatedEvent);
            Assert.Equal(evt, accessor.AssociatedMember);
        }
Exemple #20
0
        public void Parse_should_apply_to_ctor_with_declaring_type()
        {
            var method = MethodName.Parse("System.Exception..ctor(String, Exception)");

            Assert.True(method.HasParametersSpecified);
            Assert.Equal("System.Exception..ctor(String, Exception)", method.ToString());
            Assert.Equal(".ctor", method.Name);
        }
Exemple #21
0
        public void Parse_method_generic_parameter_array_argument(string text)
        {
            var m = MethodName.Parse(text);

            var first = (ArrayTypeName)m.Parameters[0].ParameterType;

            Assert.Equal(0, ((GenericParameterName)first.ElementType).Position);
        }
Exemple #22
0
        public void Parse_method_named_generic_parameters(string text)
        {
            var m = MethodName.Parse(text);

            Assert.IsInstanceOf(typeof(DefaultMethodName), m);
            Assert.Equal("System.Array.ConvertAll<TInput, TOutput>()", m.FullName);
            Assert.Equal(2, m.GenericParameterCount);
        }
Exemple #23
0
        public void Parse_method_generic_parameter_count(string text)
        {
            var m = MethodName.Parse(text);

            Assert.IsInstanceOf(typeof(DefaultMethodName), m);
            Assert.Equal(2, m.GenericParameterCount);
            Assert.Equal("ConvertAll", m.Name);
        }
Exemple #24
0
        public void Matches_explicit_interface_name()
        {
            var subject = MethodName.Parse("System.Tuple`2::System.ITuple.ToString()");

            Assert.True(MethodName.Parse("Tuple`2::System.ITuple.ToString()").Matches(subject));

            // Doesn't match because it is considered "ToString()"
            Assert.False(MethodName.Parse("System.ITuple.ToString()").Matches(subject));
        }
Exemple #25
0
        public void Parse_should_apply_to_methods_without_parameters_or_declaring_types()
        {
            var method = MethodName.Parse("ToString");

            Assert.Null(method.DeclaringType);
            Assert.NotNull(method.Parameters);
            Assert.False(method.HasParametersSpecified);
            Assert.Equal("ToString", method.Name);
        }
Exemple #26
0
        public void WithParametersUnspecified_should_apply_to_names(string name)
        {
            var method    = MethodName.Parse(name);;
            var newMethod = method.WithParametersUnspecified();

            Assert.False(newMethod.HasParametersSpecified);
            Assert.Equal("TryParse", newMethod.ToString());
            Assert.NotNull(newMethod.Parameters);
        }
Exemple #27
0
        public void AssociatedMember_creates_event_name_semantics(string methodName)
        {
            // We know the event's type based on the signature of the associated accessor
            var accessor = MethodName.Parse(methodName);
            var evt      = EventName.Parse("INotifyPropertyChanged.PropertyChanged:EventHandler");

            Assert.Equal(evt, accessor.AssociatedEvent);
            Assert.Equal(evt, accessor.AssociatedMember);
        }
Exemple #28
0
        public void Parse_method_name_unqualified_parameters()
        {
            MethodName id = MethodName.Parse("System.IComparer.CompareTo");

            Assert.Equal("CompareTo", id.Name);
            Assert.Equal("System.IComparer", id.DeclaringType.FullName);
            Assert.NotNull(id.Parameters);
            Assert.Equal(-1, id.ParameterCount);
        }
Exemple #29
0
        public void SetParameter_should_apply_on_generics()
        {
            var method = MethodName.Parse("Create``2(``0,``1)");

            Assert.Equal("Create", method.Name);
            var newMethod = method.SetParameter(0, "text", TypeName.FromType(typeof(string)));

            Assert.Equal("Create", newMethod.Name);
            Assert.Equal("Create``2(System.String text, ``1)", newMethod.ToString());
        }
Exemple #30
0
        public void Parse_should_apply_to_ctor_without_declaring_type()
        {
            var method = MethodName.Parse(".ctor(Char*,Int32,Int32)");

            Assert.Null(method.DeclaringType);
            Assert.NotNull(method.Parameters);
            Assert.True(method.HasParametersSpecified);
            Assert.Equal(".ctor", method.Name);
            Assert.Equal(".ctor(Char*, Int32, Int32)", method.ToString());
        }