Пример #1
0
        public void CreateNotSupportActionTest()
        {
            var factory = new HttpFactory();

            Assert.Throws(typeof(ArgumentOutOfRangeException), () =>
            {
                factory.CreateHttp(HttpRequestActionType.None)
                .Setup()
                .SetUrl("http://localhost")
                .SetContent("");
            });
        }
Пример #2
0
        /// <summary>
        /// 执行方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        public T Execute <T>(IWeiXinRequest <T> request) where T : WeiXinResponse
        {
            //获得httpMethodAttribute数据.
            Type info = request.GetType();
            var  HttpAttributeInfo = (HttpMethodAttribute)System.Attribute.GetCustomAttribute(info, typeof(HttpMethodAttribute));
            ///根据不同的请求方式
            Http <T> http = HttpFactory <T> .CreateHttp(HttpAttributeInfo.Method);

            //延签消息
            http.Token = Token;
            http.HttpMethodAttribute = HttpAttributeInfo;
            http.Request             = request;
            return(http.GetResponse());
        }
Пример #3
0
        public async System.Threading.Tasks.Task CreateHttpActionTestAsync()
        {
            var options = new HttpOptions();

            options.AddFileExtAsContentType(".txt", "is txt file");

            var factory = new HttpFactory(options);
            var httpGet = factory.CreateHttp(HttpRequestActionType.Get)
                          .Setup()
                          .SetUrl("http://www.baidu.com");

            var response = await httpGet.GetResponseAsync();

            Assert.NotEmpty(response);
        }