Example #1
0
		public void Download_should_return_empty_result_for_null_uri()
		{
			//arrange
			var target = new Downloader();
			//act
			var actual = target.Download(null);
			//assert
			Assert.AreEqual(0, actual.Length);
		}
Example #2
0
		public void Download_should_return_stream_from_target_url()
		{
			//arrange
			const string expected = "some string";
			string actual;
			using (var listener = new HttpListener())
			{
				var url = string.Format("http://localhost:{0}/", FreePort);
				listener.Prefixes.Add(url);
				listener.Start();
				listener.BeginGetContext(AsynGetContext, new AsyncArguments(listener, expected));
				var target = new Downloader();
				//act
				var actualStream = target.Download(new Uri(url));
				//assert
				listener.Stop();
				var result = new byte[Encoding.Default.GetBytes(expected).Length];
				actualStream.Read(result, 0, result.Length);
				actual = Encoding.Default.GetString(result);
			}

			Assert.AreEqual(expected, actual);
		}