Esempio n. 1
0
        public void Can_POST_upload_stream_using_JsonHttpClient()
        {
            try
            {
                var client = new JsonHttpClient(ListeningOn);

                using (var fileStream = new FileInfo("~/TestExistingDir/upload.html".MapProjectPlatformPath()).OpenRead())
                {
                    var fileName = "upload.html";

                    bool isFilterCalled = false;
                    JsonHttpClient.GlobalRequestFilter = request =>
                    {
                        isFilterCalled = true;
                    };
                    var response = client.PostFile <FileUploadResponse>(
                        "/fileuploads", fileStream, fileName, MimeTypes.GetMimeType(fileName));

                    fileStream.Position = 0;
                    var expectedContents = new StreamReader(fileStream).ReadToEnd();

                    Assert.That(isFilterCalled);
                    Assert.That(response.Name, Is.EqualTo("file"));
                    Assert.That(response.FileName, Is.EqualTo(fileName));
                    Assert.That(response.ContentLength, Is.EqualTo(fileStream.Length));
                    Assert.That(response.ContentType, Is.EqualTo(MimeTypes.GetMimeType(fileName)));
                    Assert.That(response.Contents, Is.EqualTo(expectedContents));
                }
            }
            finally
            {
                JsonHttpClient.GlobalRequestFilter = null;  //reset this to not cause side-effects
            }
        }