Beispiel #1
0
        /// <summary>
        /// Send request to some servers parallel
        /// </summary>
        /// <param name="requestCase"></param>
        /// <param name="servers"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task SendRequestsParallelAsync(RequestCase requestCase, string[] servers, CancellationToken cancellationToken)
        {
            requestCase._status = CaseStatus.Running;
            requestCase.Responses.Clear();

            var tasks = new Task <Response> [servers.Length];

            for (int i = 0; i < servers.Length; i++)
            {
                tasks[i] = RequestManager.SendRequestAsync(requestCase.request, servers[i], cancellationToken);
            }
            ;

            try
            {
                var results = await Task.WhenAll(tasks);

                for (int i = 0; i < servers.Length; i++)
                {
                    requestCase.Responses.Add(servers[i], results[i]);
                }

                requestCase.CompareResults(cancellationToken);
            }
            catch (TaskCanceledException)
            {
                //cancellationToken in cancelled state
            }
        }
Beispiel #2
0
        internal static void ShowDiff(RequestCase requestCase)
        {
            string filePath = Path.GetTempPath();

            string winMergeString = "";
            int    i = 0;

            foreach (var result in requestCase.Responses.Values)
            {
                File.WriteAllText($"{filePath}{i}.txt", result.body);
                winMergeString += $"{filePath}{i++}.txt ";
            }

            Process.Start("WinMergeU.exe", winMergeString);
        }
        public async Task TestMethod1Async()
        {
            var testCase = new RequestCase(
                new Request
            {
                requestType = RequestType.GET,
                path        = @"/search",
                parameters  = new Dictionary <string, string>()
                {
                    { "q", "42" }
                }
            }
                );

            await RequestParallelManager.SendRequestsParallelAsync(
                testCase,
                new string[] { "https://www.google.com", "http://www.google.com" },
                CancellationToken.None);

            Assert.AreEqual(testCase._status, CaseStatus.Equals);
        }