public void CreateEmptyContentHeadersReturnsEmptyHeaders() { HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); Assert.NotNull(headers); Assert.Equal(0, headers.Count()); }
public void GetStream_ThrowsOnNullParent() { TProvider provider = new TProvider(); HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); Assert.ThrowsArgumentNull(() => provider.GetStream(null, headers), "parent"); }
public void GetStream_ThrowsOnNoContentDisposition() { MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(ValidPath); HttpContent content = new StringContent(String.Empty); HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); Assert.Throws <InvalidOperationException>(() => { provider.GetStream(content, headers); }); }
/// <summary> /// Initializes a new instance of the <see cref="MimeBodyPart"/> class. /// </summary> /// <param name="streamProvider">The stream provider.</param> /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param> public MimeBodyPart(MultipartStreamProvider streamProvider, int maxBodyPartHeaderSize) { Contract.Assert(streamProvider != null); _streamProvider = streamProvider; Segments = new List <ArraySegment <byte> >(2); _headers = FormattingUtilities.CreateEmptyContentHeaders(); HeaderParser = new InternetMessageFormatHeaderParser(_headers, maxBodyPartHeaderSize); }
public void Constructor_ThrowsOnNullLocation() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act and Assert Assert.ThrowsArgumentNull(() => new MultipartRemoteFileData(headers, null, "Name"), "location"); }
public void Constructor_ThrowsOnNullLocation() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act & Assert Assert.ThrowsArgumentNull(() => new RemoteStreamInfo(new MemoryStream(), null, "Name"), "location"); }
/// <summary> /// Initializes a new instance of the <see cref="MimeBodyPart"/> class. /// </summary> /// <param name="streamProvider">The stream provider.</param> /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param> public MimeBodyPart(IMultipartStreamProvider streamProvider, int maxBodyPartHeaderSize) { Contract.Assert(streamProvider != null, "Stream provider cannot be null."); _streamProvider = streamProvider; Segments = new ArrayList(2); _headers = FormattingUtilities.CreateEmptyContentHeaders(); HeaderParser = new InternetMessageFormatHeaderParser(_headers, maxBodyPartHeaderSize); }
public void Constructor_ThrowsOnNullFileName() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act and Assert Assert.ThrowsArgumentNull(() => new MultipartRemoteFileData(headers, "http://some/path/to", null), "fileName"); }
public void Constructor_ThrowsOnNullFileName() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act & Assert Assert.ThrowsArgumentNull(() => new RemoteStreamInfo(new MemoryStream(), "http://some/path/to", null), "fileName"); }
public void GetStream_ThrowsOnNoContentDisposition() { // Arrange CustomMultipartFormDataRemoteStreamProvider provider = new CustomMultipartFormDataRemoteStreamProvider(); HttpContent content = new StringContent(String.Empty); HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act & Assert Assert.Throws <InvalidOperationException>(() => { provider.GetStream(content, headers); }); }
public void Constructor_InitializesCorrectly() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); string fileName = "filename"; // Act MultipartFileData fileData = new MultipartFileData(headers, fileName); Assert.Same(headers, fileData.Headers); Assert.Same(fileName, fileData.LocalFileName); }
/// <summary> /// Initializes a new instance of the <see cref="MimeBodyPart"/> class. /// </summary> /// <param name="streamProvider">The stream provider.</param> /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param> /// <param name="parentContent">The part's parent content</param> public MimeBodyPart(MultipartStreamProvider streamProvider, int maxBodyPartHeaderSize, HttpContent parentContent) { Contract.Assert(streamProvider != null); Contract.Assert(parentContent != null); _streamProvider = streamProvider; _parentContent = parentContent; Segments = new List <ArraySegment <byte> >(2); _headers = FormattingUtilities.CreateEmptyContentHeaders(); HeaderParser = new InternetMessageFormatHeaderParser( _headers, maxBodyPartHeaderSize, ignoreHeaderValidation: true); }
public void Constructor_InitializesCorrectly() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); string remoteFileURL = "http://some/path/to"; string fileName = "Name"; // Act MultipartRemoteFileData fileData = new MultipartRemoteFileData(headers, remoteFileURL, fileName); // Assert Assert.Same(headers, fileData.Headers); Assert.Same(remoteFileURL, fileData.Location); Assert.Same(fileName, fileData.FileName); }
/// <summary> /// Copies the unsorted header fields to a sorted collection. /// </summary> /// <param name="source">The unsorted source headers</param> /// <param name="destination">The destination <see cref="HttpRequestHeaders"/> or <see cref="HttpResponseHeaders"/>.</param> /// <param name="contentStream">The input <see cref="Stream"/> used to form any <see cref="HttpContent"/> being part of this HTTP request.</param> /// <param name="rewind">Start location of any request entity within the <paramref name="contentStream"/>.</param> /// <returns>An <see cref="HttpContent"/> instance if header fields contained and <see cref="HttpContentHeaders"/>.</returns> private static HttpContent CreateHeaderFields( HttpHeaders source, HttpHeaders destination, Stream contentStream, int rewind ) { Contract.Assert(source != null, "source headers cannot be null"); Contract.Assert(destination != null, "destination headers cannot be null"); Contract.Assert(contentStream != null, "contentStream must be non null"); HttpContentHeaders contentHeaders = null; HttpContent content = null; // Set the header fields foreach (KeyValuePair <string, IEnumerable <string> > header in source) { if (!destination.TryAddWithoutValidation(header.Key, header.Value)) { if (contentHeaders == null) { contentHeaders = FormattingUtilities.CreateEmptyContentHeaders(); } contentHeaders.TryAddWithoutValidation(header.Key, header.Value); } } // If we have content headers then create an HttpContent for this Response if (contentHeaders != null) { // Need to rewind the input stream to be at the position right after the HTTP header // which we may already have parsed as we read the content stream. if (!contentStream.CanSeek) { throw Error.InvalidOperation( Properties.Resources.HttpMessageContentStreamMustBeSeekable, "ContentReadStream", FormattingUtilities.HttpResponseMessageType.Name ); } contentStream.Seek(0 - rewind, SeekOrigin.Current); content = new StreamContent(contentStream); contentHeaders.CopyTo(content.Headers); } return(content); }
public void Constructor_InitializesCorrectly() { // Arrange HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); string remoteFileURL = "http://some/path/to"; string fileName = "Name"; Stream stream = new MemoryStream(); // Act RemoteStreamInfo fileData = new RemoteStreamInfo(stream, remoteFileURL, fileName); // Assert Assert.Same(stream, fileData.RemoteStream); Assert.Same(remoteFileURL, fileData.Location); Assert.Same(fileName, fileData.FileName); }
public void CopyTo_CopiesContentHeaders() { // Arrange HttpContentHeaders source = FormattingUtilities.CreateEmptyContentHeaders(); source.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf8; parameter=value"); source.ContentLength = 1234; source.ContentLocation = new Uri("http://some.host"); source.Add("test-name1", "test-value1"); source.Add("test-name2", "test-value2"); HttpContentHeaders destination = FormattingUtilities.CreateEmptyContentHeaders(); // Act source.CopyTo(destination); // Assert Assert.Equal(source.ToString(), destination.ToString()); }
public void GetStream_ReturnsNewMemoryStream() { // Arrange MultipartMemoryStreamProvider instance = new MultipartMemoryStreamProvider(); HttpContent parent = new StringContent(String.Empty); HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); // Act Stream stream1 = instance.GetStream(parent, headers); Stream stream2 = instance.GetStream(parent, headers); // Assert Assert.IsType <MemoryStream>(stream1); Assert.Equal(0, stream1.Length); Assert.Equal(0, stream1.Position); Assert.IsType <MemoryStream>(stream2); Assert.Equal(0, stream2.Length); Assert.Equal(0, stream2.Position); Assert.NotSame(stream1, stream2); }
public void Constructor_ThrowsOnNullLocalFileName() { HttpContentHeaders headers = FormattingUtilities.CreateEmptyContentHeaders(); Assert.ThrowsArgumentNull(() => new MultipartFileData(headers, null), "localFileName"); }