public void Dispose_DisposesInnerContent()
        {
            // Arrange
            StringContent          innerContent    = new StringContent("HelloWorld!");
            HttpRequestMessage     request         = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();
            ProgressContent        progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Act
            progressContent.Dispose();

            // Assert
            Assert.ThrowsObjectDisposed(() => innerContent.LoadIntoBufferAsync(), typeof(StringContent).FullName);
        }
        public async Task SerializeToStreamAsync_InsertsProgressStream()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage();

            request.Content = new StringContent("HelloWorld!");

            MockProgressEventHandler progressEventHandler = new MockProgressEventHandler();
            ProgressMessageHandler   progressHandler      =
                MockProgressEventHandler.CreateProgressMessageHandler(
                    out progressEventHandler,
                    sendProgress: true
                    );
            ProgressContent progressContent = new ProgressContent(
                request.Content,
                progressHandler,
                request
                );
            MemoryStream memStream = new MemoryStream();

            // Act
            await progressContent.CopyToAsync(memStream);

            // Assert
            Assert.True(progressEventHandler.WasInvoked);
            Assert.Equal(request, progressEventHandler.Sender);
            Assert.Equal(
                request.Content.Headers.ContentLength,
                progressEventHandler.EventArgs.TotalBytes
                );
        }
 private void AddRequestProgress(HttpRequestMessage request)
 {
     if (HttpSendProgress != null && request != null && request.Content != null)
     {
         HttpContent progressContent = new ProgressContent(request.Content, this, request);
         request.Content = progressContent;
     }
 }
 private void AddRequestProgress(HttpRequestMessage request)
 {
     if (HttpSendProgress != null && request != null && request.Content != null)
     {
         HttpContent progressContent = new ProgressContent(request.Content, this, request);
         request.Content = progressContent;
     }
 }
        public void Dispose_DisposesInnerContent()
        {
            // Arrange
            StringContent innerContent = new StringContent("HelloWorld!");
            HttpRequestMessage request = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();
            ProgressContent progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Act
            progressContent.Dispose();

            // Assert
            Assert.ThrowsObjectDisposed(() => innerContent.LoadIntoBufferAsync(), typeof(StringContent).FullName);
        }
        public void Constructor_CopyHeadersFromInnerContent()
        {
            // Arrange
            StringContent innerContent = new StringContent("HelloWorld!");
            innerContent.Headers.Add(TestHeader, TestValue);
            HttpRequestMessage request = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();

            // Act
            ProgressContent progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Assert
            ValidateContentHeader(progressContent);
            Assert.Equal(innerContent.Headers.ContentType, progressContent.Headers.ContentType);
            Assert.Equal(innerContent.Headers.ContentLength, progressContent.Headers.ContentLength);
        }
        public void Constructor_CopyHeadersFromInnerContent()
        {
            // Arrange
            StringContent innerContent = new StringContent("HelloWorld!");

            innerContent.Headers.Add(TestHeader, TestValue);
            HttpRequestMessage     request         = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();

            // Act
            ProgressContent progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Assert
            ValidateContentHeader(progressContent);
            Assert.Equal(innerContent.Headers.ContentType, progressContent.Headers.ContentType);
            Assert.Equal(innerContent.Headers.ContentLength, progressContent.Headers.ContentLength);
        }
        public Task SerializeToStreamAsync_InsertsProgressStream()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage();
            request.Content = new StringContent("HelloWorld!");

            MockProgressEventHandler progressEventHandler = new MockProgressEventHandler();
            ProgressMessageHandler progressHandler = MockProgressEventHandler.CreateProgressMessageHandler(out progressEventHandler, sendProgress: true);
            ProgressContent progressContent = new ProgressContent(request.Content, progressHandler, request);
            MemoryStream memStream = new MemoryStream();

            // Act
            return progressContent.CopyToAsync(memStream).ContinueWith(
                task =>
                {
                    // Assert
                    Assert.Equal(TaskStatus.RanToCompletion, task.Status);
                    Assert.True(progressEventHandler.WasInvoked);
                    Assert.Equal(request, progressEventHandler.Sender);
                    Assert.Equal(request.Content.Headers.ContentLength, progressEventHandler.EventArgs.TotalBytes);
                });
        }