コード例 #1
0
ファイル: BatchWorkApiTest.cs プロジェクト: pranavd/BatchWork
        private SubmitBatchResponse Test_SubmitBatch()
        {
            try
            {
                var urlList = Enumerable.Repeat(_testDownloadUrl, _urlCount).ToArray();

                //trick to work with HttpRequestMessage class in controller
                var controller = new DownloadController
                {
                    Request = new HttpRequestMessage()
                };
                controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey,
                                                  new HttpConfiguration());

                //calling target action
                var response = controller.SubmitBatch(urlList);

                if (response != null)
                {
                    var responseReadTask = Task.Factory.StartNew(() =>
                    {
                        return(response.Content.ReadAsStringAsync());
                    });
                    responseReadTask.Wait();

                    var result = responseReadTask.Result.Result;

                    if (string.IsNullOrEmpty(result))
                    {
                        throw new Exception("empty response from batch submit request");
                    }
                    else
                    {
                        //deserailize object
                        var submitBatchResponse = JsonConvert.DeserializeObject <SubmitBatchResponse>(result);
                        return(submitBatchResponse);
                    }
                }
                else
                {
                    throw new Exception("null response for batch submit request");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }