public void RequestWithWrongProtocol() { var uri = new Uri("http://www.silkveil.net"); var fileContentSource = new FileContentSource(); var called = 0; fileContentSource.ContentAvailable += stream => called++; fileContentSource.Request(uri); Assert.That(called, Is.EqualTo(0)); }
public void RequestNonExistentFileThrowsContentNotFoundException() { string nonExistentFile; do { nonExistentFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); } while (System.IO.File.Exists(nonExistentFile)); var fileContentSource = new FileContentSource(); Assert.That( () => fileContentSource.Request(new Uri(nonExistentFile)), Throws.Exception.TypeOf(typeof(ContentNotFoundException))); }
public void RequestFile() { int size = 1024; string content = new string('\u0000', size); var uri = CreateRandomTempFile(content); var fileContentSource = new FileContentSource(); fileContentSource.ContentAvailable += stream => { Assert.That(stream.Length, Is.EqualTo(size)); using (var streamReader = new StreamReader(stream)) { Assert.That(streamReader.ReadToEnd(), Is.EqualTo(content)); } }; fileContentSource.Request(uri); }