예제 #1
0
		public async Task MakeRequestAsync()
		{
			var service = new SupperHttpService(EventHandler, settings);

			await service.ActivateAsync(cancellationToken);

#pragma warning disable 4014

			Task.Run(() => service.RunAsync(cancellationToken), cancellationToken);

#pragma warning restore 4014

			foreach (var item in testSamples)
			{
				var webRequest = WebRequest.Create(mainPrefix + item.Item2);

				webRequest.Credentials = CredentialCache.DefaultCredentials;

				webRequest.Method = item.Item1;

				webRequest.ContentLength = 0;

				try
				{
					using (var response = (HttpWebResponse) await webRequest.GetResponseAsync())
					{
						Assert.AreEqual(item.Item3, (HttpStatusCode) (Int32) response.StatusCode);

						if (response.StatusCode == System.Net.HttpStatusCode.OK)
						{
							var s = await (new StreamReader(response.GetResponseStream()).ReadToEndAsync());

							Assert.AreEqual(item.Item4, s);
						}
					}
				}
				catch (WebException)
				{
					if (item.Item3 != HttpStatusCode.BadRequest)
					{
						throw;
					}
				}
				catch (Exception e)
				{
					Trace.TraceError(e.Message);
				}
			}

			await service.DeactivateAsync(cancellationToken);
		}
예제 #2
0
		public async Task ExternalTestAsync()
		{
			var service = new SupperHttpService(EventHandler, settings);

			await service.ActivateAsync(cancellationToken);

			var runTask = Task.Run(() => service.RunAsync(cancellationToken), cancellationToken);

			await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken);

			await service.DeactivateAsync(cancellationToken);

			await runTask;
		}