public void Can_deserialize_TestRequest_QueryStringSerializer_output() { // Setup var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly); var restPath = new RestPath(typeof(TestRequest), "/service", "GET"); var restHandler = new RestHandler { RestPath = restPath }; var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"; NameValueCollection queryString = HttpUtility.ParseQueryString(requestString); var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection()); var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service"); Assert.That(request2.ListOfA.Count, Is.EqualTo(1)); Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2)); }
public void Can_use_fileStream() { byte[] fileBytes = uploadedTextFile.ReadFully(); string fileText = Encoding.ASCII.GetString(fileBytes); "File content size {0}".Print(fileBytes.Length); "File content is {0}".Print(fileText); var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); mockRequest.Headers.Add("Range", "bytes=6-8"); var httpResult = new HttpResult(uploadedTextFile, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(fileText.Substring(6, 3))); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 6-8/33")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_seek_from_middle_to_middle() { var mockRequest = new HttpRequestMock(); mockRequest.Headers.Add("Range", "bytes=3-5"); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo("456")); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 3-5/10")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_respond_to_non_range_requests_with_200_OK_response() { var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(customText)); Assert.That(mockResponse.Headers["Content-Range"], Is.Null); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(200)); }