Esempio n. 1
0
        public async Task VerifyTimeoutOnReadAsync(Func <Stream, Task <string> > readAsync)
        {
            // Arrange
            var expectedDownload     = "download";
            var expectedMilliseconds = 25;
            var memoryStream         = GetStream("foobar");
            var slowStream           = new SlowStream(memoryStream)
            {
                DelayPerByte = TimeSpan.FromMilliseconds(expectedMilliseconds * 2)
            };
            var timeoutStream = new DownloadTimeoutStream(
                expectedDownload,
                slowStream,
                TimeSpan.FromMilliseconds(expectedMilliseconds));

            // Act & Assert
            var exception = await Assert.ThrowsAsync <IOException>(() =>
                                                                   readAsync(timeoutStream));

            Assert.Equal(
                $"The download of '{expectedDownload}' timed out because " +
                $"no data was received for {expectedMilliseconds}ms.",
                exception.Message);
            Assert.IsType <TimeoutException>(exception.InnerException);
        }
Esempio n. 2
0
        public async Task VerifyFailureOnReadAsync(Func <Stream, Task <string> > readAsync)
        {
            // Arrange
            var expected     = new IOException();
            var memoryStream = GetStream("foobar");
            var slowStream   = new SlowStream(memoryStream)
            {
                OnRead = (buffer, offset, count) => { throw expected; }
            };
            var timeoutStream = new DownloadTimeoutStream(
                "download",
                slowStream,
                TimeSpan.FromSeconds(1));

            // Act & Assert
            var actual = await Assert.ThrowsAsync <IOException>(() =>
                                                                readAsync(timeoutStream));

            Assert.Same(expected, actual);
        }