Example #1
0
        public void ToString_GenericInstanceType_receiver_should_contain_generic_parameters()
        {
            var method = typeof(Comparison <int>).GetTypeInfo().GetMethod("Invoke");

            Assert.Equal("System.Comparison<System.Int32>.Invoke(System.Int32 x, System.Int32 y)",
                         MethodName.FromMethodInfo(method).ToString());
        }
Example #2
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);
        }
Example #3
0
        public void FromMethod_out_parameter_nominal()
        {
            MethodName m = MethodName.FromMethodInfo(typeof(char).GetTypeInfo().GetMethod("TryParse"));

            Assert.Equal("System.Char.TryParse(System.String s, System.Char& result)", m.FullName);
            Assert.True(m.Parameters[1].ParameterType.IsByReference);
        }
Example #4
0
        public void FromMethod_ref_parameter_nominal()
        {
            MethodName m = MethodName.FromMethodInfo(typeof(Array).GetTypeInfo().GetMethod("Resize"));

            Assert.Equal("System.Array.Resize<T>(T[]& array, System.Int32 newSize)", m.FullName);
            Assert.True(m.Parameters[0].ParameterType.IsByReference);
        }
Example #5
0
        private void InvokeHttpPost(object[] parameters)
        {
            string CompleteUrl;

            if (MethodName.EndsWith("/"))
            {
                CompleteUrl = Url + MethodName;
            }
            else
            {
                CompleteUrl = Url + "/" + MethodName;
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(CompleteUrl);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            using (Stream s = request.GetRequestStream())
                using (StreamWriter sw = new StreamWriter(s))
                {
                    for (int i = 0; i < Parameters.Count; ++i)
                    {
                        sw.Write(Parameters[i].Name + "=" + System.Web.HttpUtility.UrlEncodeUnicode(Convert.ToString(parameters[i])) + ((i < (Parameters.Count - 1)) ? "&" : ""));
                    }
                    sw.Flush();
                }

            WebResponse response = request.GetResponse();

            response.Close();
        }
Example #6
0
 public JObject RequestServer(MethodName methodName, object parameter)
 {
     return(RequestServer(methodName, new List <object>()
     {
         parameter
     }));
 }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WeakAction"/> class.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="action">The action.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="action"/> is <c>null</c>.</exception>
        /// <exception cref="NotSupportedException">The <paramref name="action"/> is an anonymous delegate.</exception>
        public WeakAction(object target, Action action)
            : base(target)
        {
            Argument.IsNotNull("action", action);

#if NETFX_CORE || PCL
            Log.Warning("Since WinRT won't allow specific reflection, the WeakAction is implemented as regular action");

            _action = action;
#else
            MethodName = action.Method.ToString();

            if (MethodName.Contains("_AnonymousDelegate>"))
            {
                const string error = "Anonymous delegates are not supported because they are located in a private class";
                Log.Error(error);
                throw new NotSupportedException(error);
            }

            var targetType   = (target != null) ? target.GetType() : typeof(object);
            var delegateType = typeof(OpenInstanceAction <>).MakeGenericType(targetType);

            _action = DelegateHelper.CreateDelegate(delegateType, action.Method);
#endif
        }
Example #8
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);
        }
        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);
        }
Example #10
0
        public void Create_should_create_method_name_from_name()
        {
            var a = MethodName.Create("Hello");
            var b = MethodName.Parse("Hello");

            Assert.Equal(a, b);
        }
 /// <summary>
 /// 
 /// </summary>
 public CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime)
 {
     this.MethodName = methodName;
     this.ConnectionString = connectionString;
     this.StartTime = startTime;
     this.EndTime = endTime;
 }
Example #12
0
                public Signature(string signature)
                {
                    Regex regex = new Regex(@"^(?<static>!?)(?<type>.+)\.(?<method>.+)\((?<paras>.*)\)$");
                    Match match = regex.Match(signature);

                    if (!match.Success)
                    {
                        throw new FaultInjectionException();
                    }

                    declaringType = new TypeName(match.Groups["type"].Value);
                    method        = new MethodName(match.Groups["method"].Value);
                    if (match.Groups["paras"].Value != string.Empty)
                    {
                        parameters = new ParaList(match.Groups["paras"].Value);
                    }

                    // Is static method?
                    isStatic = (match.Groups["static"].Value != string.Empty);
                    // Is constructor?
                    if (declaringType.arraySuffix == null)
                    {
                        string methodName = method.name.identifier;
                        string className  = declaringType.plainTypeName.className;
                        if (className == methodName)
                        {
                            isConstructor = true;
                        }
                    }
                }
Example #13
0
        protected override void EndProcessing()
        {
            var outList = new List <PoshMethod>();

            for (int i = 0; i < list.Count; i++)
            {
                Type t = list[i];
                IEnumerable <MethodInfo> allMethods = t.GetMethods(realFlags);
                if (this.MyInvocation.BoundParameters.ContainsKey("MethodName"))
                {
                    allMethods = allMethods.Where(x => MethodName.Any(n => n.Equals(x.Name, StringComparison.CurrentCultureIgnoreCase)));
                }
                else if (!this.MyInvocation.BoundParameters.ContainsKey("Force"))
                {
                    allMethods = allMethods.Where(x => !x.Name.Contains("_"));
                }
                foreach (MethodInfo mi in allMethods)
                {
                    outList.Add(mi);
                }
            }
            outList.Sort(new PoshMethodSorter());

            WriteObject(outList, true);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="exception"></param>
 protected CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception)
 {
     this.MethodName = methodName;
     this.ConnectionString = connectionString;
     this.Exception = exception;
     this.ThrowException = true;
 }
Example #15
0
        private void ProcessCallbackBinding()
        {
            // Trying to roughly follow http://msdn.microsoft.com/en-us/library/ms228974(v=vs.110).aspx
            // "Event-based async pattern"

            if (InputObject == null)
            {
                throw new PSArgumentNullException("InputObject", "InputObject may not be null.");
            }

            bool isStatic = false;
            Type targetType;

            if ((_baseObject as Type) != null)
            {
                targetType = (Type)_baseObject;
                isStatic   = true;
                this.WriteVerbose("InputObject is a Type: " + targetType.Name);
            }
            else
            {
                targetType = _baseObject.GetType();
                this.WriteVerbose("InputObject is an instance of " + targetType.Name);
            }

            // Func<T1, Tn..., AsyncCallback, object, IAsyncResult> begin,
            // Func<IAsyncResult, dynamic> end)
            // begin/end?
            if (MethodName.StartsWith("Begin",
                                      StringComparison.OrdinalIgnoreCase))
            {
                WriteVerbose("Method is AsyncCallback Begin/End pairing style.");

                string     verb          = MethodName.Substring(5);
                string     endMethodName = "End" + verb;
                MethodInfo endMethod     = targetType.GetMethod(endMethodName, new[] { typeof(IAsyncResult) });

                if (endMethod == null)
                {
                    throw new PSArgumentException(String.Format(
                                                      "No matching '{0}(IAsyncResult)' method found for APM call '{1}'.",
                                                      endMethodName, MethodName));

                    // TODO: throw proper terminating error
                    //this.ThrowTerminatingError(new ErrorRecord());
                }
                //BindBeginEndStyleMethod(targetType, isStatic);
            }
            else if (MethodName.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
            {
                // determine if EAP or TAP mode call
                string verb = MethodName.Substring(0, MethodName.Length - 5); // e.g. "[Read]Async"

                this.WriteWarning("*Async method handling not implemented, yet.");
            }
            // winrt / task?

            //
        }
Example #16
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));
        }
Example #17
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));
        }
Example #18
0
        internal override string DebugView()
        {
            var arguments = String.Join(", ", Arguments.Select(t => t.ToString()));

            return(Context != null
                ? String.Format("{0}.{1}({2})", Context, MethodName.Capitalize(), arguments)
                : String.Format("{0}({1})", MethodName.Capitalize(), arguments));
        }
Example #19
0
        public void MethodName()
        {
            var diagnostic = new MethodName {
                Convention = "^[A-Z][a-zA-Z0-9]+$"
            };

            Verifier.Verify(@"TestCases\MethodName.cs", diagnostic);
        }
Example #20
0
 public Guid ToGuid()
 {
     return(new Guid(ServiceHash.GetBytes()
                     .Concat(InterfaceHash.GetBytes())
                     .Concat(MethodName.GetBytes())
                     .Concat(MethodSignature.GetBytes())
                     .ToArray()));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="exception"></param>
 protected CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, Object executionContext)
 {
     this.MethodName       = methodName;
     this.ConnectionString = connectionString;
     this.Exception        = exception;
     this.ThrowException   = true;
     this.ExecutionContext = executionContext;
 }
Example #22
0
        /// <summary>
        /// Send a get request
        /// </summary>
        /// <param name="apiName">Name of the api Method</param>
        /// <param name="queryStr">query string with parameters</param>
        /// <returns>The HTTP response message if the call is successful</returns>
        public HttpResponseMessage Request(MethodName apiName, string queryStr = "")
        {
            var apiMethod = GetAPI(apiName, queryStr);

            var response = _httpClient.GetAsync(apiMethod.Url).Result;

            return(response);
        }
Example #23
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);
        }
Example #24
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);
        }
Example #25
0
 /// <summary>
 ///
 /// </summary>
 protected CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime, Object executionContext)
 {
     this.MethodName       = methodName;
     this.ConnectionString = connectionString;
     this.StartTime        = startTime;
     this.EndTime          = endTime;
     this.ExecutionContext = executionContext;
 }
Example #26
0
        internal override string DebugView()
        {
            var arguments = string.Join(", ", Arguments.Select(t => t.ToString()));

            return(Context != null
                ? $"{Context}.{MethodName.Capitalize()}({arguments})"
                : $"{MethodName.Capitalize()}({arguments})");
        }
        public void TypeParameterParsingIsCached()
        {
            var sut = new MethodName();
            var a   = sut.TypeParameters;
            var b   = sut.TypeParameters;

            Assert.AreSame(a, b);
        }
Example #28
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);
        }
Example #29
0
 private bool MatchMethodName(string filter)
 {
     if (string.IsNullOrEmpty(filter))
     {
         return(true);
     }
     return(MethodName.ToLower().Equals(filter.ToLower()));
 }
 public static GenericNameContext Create(MethodName m)
 {
     if (m == null)
     {
         return(Empty);
     }
     return(new GenericNameContext(m, m.DeclaringType));
 }
Example #31
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);
        }
Example #32
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());
        }
Example #33
0
        public JObject RequestServer(MethodName methodName, List<object> parameters)
        {
            HttpWebRequest rawRequest = GetRawRequest();

            //  basic info required by qt
            JObject jObject = new JObject
                {
                    new JProperty("jsonrpc", "1.0"),
                    new JProperty("id", "1"),
                    new JProperty("method", methodName.ToString())
                };

            //  adds provided parameters
            JArray props = new JArray();

            if (parameters != null && parameters.Any())
            {
                foreach (object parameter in parameters)
                {
                    props.Add(parameter);

                }
            }

            StreamReader streamReader = null;
            jObject.Add(new JProperty("params", props));

            // serialize json for the request
            try
            {
                String s = JsonConvert.SerializeObject(jObject);
                byte[] byteArray = Encoding.UTF8.GetBytes(s);
                rawRequest.ContentLength = byteArray.Length;
                Stream dataStream = rawRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse webResponse = rawRequest.GetResponse();
                streamReader = new StreamReader(webResponse.GetResponseStream(), true);
                return (JObject)JsonConvert.DeserializeObject(streamReader.ReadToEnd());
            }
            catch (WebException webException)
            {
                if (webException.Status == WebExceptionStatus.ConnectFailure)
                {
                    throw new Exception("Could not connect to Gamerscoind, please check that Gamerscoind is up and running and that you configuration (" + _secondaryserverIp + ", " + _secondaryusername + ", " + _secondarypassword +") is correct");
                }
                return null;
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
        }
        static XunitTestFrameworkMetadata()
        {
            Assembly_XunitAssert = ShortAssemblyName.FromName("xunit.assert");
            Assembly_XunitCore = ShortAssemblyName.FromName("xunit.core");

            Type_Assert = MakeTypeName("Assert");
            Type_AssertException = MakeTypeName("XunitException", Namespace_XunitSdk, Assembly_XunitAssert);
            Type_FactAttribute = MakeTypeName("FactAttribute");
            Type_TheoryAttribute = MakeTypeName("TheoryAttribute");
            Type_TraitAttribute = MakeTypeName("TraitAttribute");

            Ctor_FactAttribute = MetadataBuilderHelper.Attributes.ConstructorName(Type_FactAttribute.Definition);
            Ctor_TraitAttribute = MetadataBuilderHelper.Attributes.ConstructorName(Type_TraitAttribute.Definition);

            Method_PexAssertInconclusive = new Lazy<Method>(() => MakePexAssertInconclusive());

            MethodDefinition_AssertEqual = MakeAssertEqual();
            MethodDefinition_AssertNotEqual = MakeAssertNotEqual();
            MethodDefinition_AssertNotNull = MakeAssertNotNull();
            MethodDefinition_AssertNull = MakeAssertNull();
            MethodDefinition_AssertTrue = MakeAssertTrue();

            Property_Skip = new PropertyDefinitionName(Assembly_XunitCore, -1, Type_FactAttribute.Definition, "Skip", SystemTypes.String.SerializableName).SelfInstantiation;
        }
Example #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ex"></param>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 public DatabaseException(Exception ex, MethodName methodName, String connectionString)
     : base(ex.Message, ex)
 {
     this.MethodName = methodName;
     this.ConnectionString = connectionString;
 }
Example #36
0
 public JObject RequestServer(MethodName methodName, object parameter, object parameter2)
 {
     return RequestServer(methodName, new List<object> { parameter, parameter2 });
 }
Example #37
0
 public JObject RequestServer(MethodName methodName)
 {
     return RequestServer(methodName, parameters: null);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="command"></param>
 public CommandExecutingEventArgs(MethodName methodName, String connectionString, DbCommand command)
     : this(methodName, connectionString)
 {
     Cancel = false;
     Command = command;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="dataAdapter"></param>
 public CommandExecutingEventArgs(MethodName methodName, String connectionString, DbDataAdapter dataAdapter)
     : this(methodName, connectionString)
 {
     Cancel = false;
     DataAdapter = dataAdapter;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 public CommandExecutingEventArgs(MethodName methodName, String connectionString, SqlBulkCopyContext context)
     : this(methodName, connectionString)
 {
     Cancel = false;
     Context = context;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 protected CommandExecutingEventArgs(MethodName methodName, String connectionString)
 {
     MethodName = methodName;
     ConnectionString = connectionString;
 }
 private ViewTestParametersCollection GetParamsCollection(MethodName methodName)
 {
     return new ViewTestParametersCollection(GetViewTest(methodName));
 }
 private ViewTest GetViewTest(MethodName methodName)
 {
     var method = GetType().GetMethod(methodName.ToString());
     return new ViewTest(method);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="dataAdapter"></param>
 /// <param name="exception"></param>
 public CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, DbDataAdapter dataAdapter)
     : this(methodName, connectionString, exception)
 {
     this.DataAdapter = dataAdapter;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 /// <param name="exception"></param>
 public CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, SqlBulkCopyContext context)
     : this(methodName, connectionString, exception)
 {
     this.Context = context;
 }
Example #46
0
 private void CatchException(MethodName methodName, String connectionString, SqlBulkCopyContext context, Exception exception)
 {
     var e = new CommandErrorEventArgs(methodName, connectionString, exception, context);
     SqlServerDatabase.OnCommandError(e);
     if (e.ThrowException == true)
     {
         var ex = CreateException(e);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="command"></param>
 public CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime, DbCommand command)
     : this(methodName, connectionString, startTime, endTime)
 {
     this.Command = command;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="context"></param>
 public CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime, SqlBulkCopyContext context)
     : this(methodName, connectionString, startTime, endTime)
 {
     this.Context = context;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="dataAdapter"></param>
 public CommandExecutedEventArgs(MethodName methodName, String connectionString, DateTimeOffset startTime, DateTimeOffset endTime, DbDataAdapter dataAdapter)
     : this(methodName, connectionString, startTime, endTime)
 {
     this.DataAdapter = dataAdapter;
 }
 public ResultTracer(IPexPathComponent component, MethodName trackMethod,StringBuilder log)
 {
     host = component;
     _trackMethod = trackMethod;
     _log = log;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="connectionString"></param>
 /// <param name="command"></param>
 /// <param name="exception"></param>
 public CommandErrorEventArgs(MethodName methodName, String connectionString, Exception exception, DbCommand command)
     : this(methodName, connectionString, exception)
 {
     this.Command = command;
 }