public void Decode_WithNull_ReturnsNull() { var encoding = new ContentEncoder("gzip"); var nullBytes = encoding.Decode(null); Assert.IsNull(nullBytes); }
public void Constructor_WithValue_MethodUpdated() { const string Expected = "gzip"; var encoding = new ContentEncoder(Expected); Assert.AreEqual(Expected, encoding.Method); }
public void Decode_UsingGzip_ReturnsDecompressed() { var encoding = new ContentEncoder("gzip"); var actual = encoding.Decode(_helloWorldGZip); CollectionAssert.AreEqual(_helloWorldUtf8, actual); }
public void Decode_UsingUnknownMethod_ReturnsSame() { var encoding = new ContentEncoder("badmethod"); var actual = encoding.Decode(_helloWorldGZip); CollectionAssert.AreEqual(_helloWorldGZip, actual); }
public void Decode_UsingDeflate_ReturnsDecompressed() { var encoding = new ContentEncoder("deflate"); var actual = encoding.Decode(_helloWorldDeflate); CollectionAssert.AreEqual(_helloWorldUtf8, actual); }
public void Encode_UsingDeflate_ReturnsCompressed() { var encoding = new ContentEncoder("deflate"); var actual = encoding.Encode(_helloWorldUtf8); // assert that we got back something different CollectionAssert.AreNotEqual(_helloWorldUtf8, actual); var roundTrip = encoding.Decode(actual); CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip); }
public void Encode_UsingGzip_ReturnsCompressed() { var encoding = new ContentEncoder("gzip"); var actual = encoding.Encode(_helloWorldUtf8); CollectionAssert.AreNotEqual(_helloWorldUtf8, actual); // assert that the gzip header is present Assert.AreEqual(actual[0], 31); Assert.AreEqual(actual[1], 139); var roundTrip = encoding.Decode(actual); CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip); }
public void Constructor_WithNullMethod_MethodIsStringEmpty() { var encoding = new ContentEncoder(null); Assert.AreEqual(string.Empty, encoding.Method); }
public void Encode_UsingGzipUppercase_ReturnsCompressed() { var encoding = new ContentEncoder("GZIP"); var actual = encoding.Encode(_helloWorldUtf8); // assert that we got back something different CollectionAssert.AreNotEqual(_helloWorldUtf8, actual); // assert that the gzip header is present Assert.AreEqual(actual[0], 31); Assert.AreEqual(actual[1], 139); var roundTrip = encoding.Decode(actual); CollectionAssert.AreEqual(_helloWorldUtf8, roundTrip); }
/// <summary> /// Populates the response of the HTTP context from the Stump. /// </summary> /// <param name="incommingHttpContext">The incomming HTTP context.</param> /// <param name="stump">The <see cref="T:Stumps.Stump"/> used to populate the response.</param> private void PopulateResponse(IStumpsHttpContext incommingHttpContext, Stump stump) { // Write the status code information incommingHttpContext.Response.StatusCode = stump.Response.StatusCode; incommingHttpContext.Response.StatusDescription = stump.Response.StatusDescription; // Write the headers incommingHttpContext.Response.Headers.Clear(); stump.Response.Headers.CopyTo(incommingHttpContext.Response.Headers); // Write the body incommingHttpContext.Response.ClearBody(); if (stump.Response.BodyLength > 0) { var buffer = stump.Response.GetBody(); if (stump.Response.Headers["Content-Encoding"] != null) { var encoder = new ContentEncoder(stump.Response.Headers["Content-Encoding"]); buffer = encoder.Encode(buffer); } incommingHttpContext.Response.AppendToBody(buffer); } }