public void CreateRequest_WithNullParameters_ThrowsArgumentNullException(HttpMethod httpMethod, string url)
 {
     var requestBuilder = new DocumentConversionRequestBuilder();
     var exception = Record.Exception(() => requestBuilder.CreateRequest(null, null));
     Assert.NotNull(exception);
     Assert.IsType<ArgumentNullException>(exception);
 }
        public void CreateRequest_Equal()
        {
            var requestBuilder = new DocumentConversionRequestBuilder();

            var request = requestBuilder.CreateRequest(HttpMethod.Get, ServiceUrl);

            Assert.NotNull(request);
            Assert.Equal(ServiceUrl, request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Get, request.Method);
        }
        public void BuildRequestMessage_WithNullArguments_ThrowsArgumentNullException(string url, Stream file,
            FileType fileType, ConversionTarget conversionTarget, JObject config)
        {
            var requestBuilder = new DocumentConversionRequestBuilder();

            var exception =
                Record.Exception(() => requestBuilder.BuildRequestMessage(url, file, fileType, conversionTarget, config));
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
        public async Task BuildRequestMessage_Equal(int fileLength, FileType fileType, ConversionTarget conversionTarget,
            string mockConfig, string expectedConfig, string expectedMediaType)
        {
            dynamic config = null;
            if (!string.IsNullOrWhiteSpace(mockConfig))
                config = JObject.Parse(mockConfig);

            var requestBuilder = new DocumentConversionRequestBuilder();

            using (var ms = new MemoryStream(new byte[fileLength]))
            {
                var request = requestBuilder.BuildRequestMessage(ServiceUrl, ms, fileType, conversionTarget, config);

                Assert.NotNull(request);
                Assert.Equal(ServiceUrl, request.RequestUri.ToString());
                Assert.Equal(HttpMethod.Post, request.Method);

                var content = (MultipartFormDataContent) request.Content;
                var fileContent =
                    (StreamContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "file");
                var configContent =
                    (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "config");

                Assert.NotNull(fileContent);
                Assert.NotNull(configContent);

                var file = await fileContent.ReadAsByteArrayAsync().ConfigureAwait(false);

                Assert.Equal(ms.Length, file.Length);
                Assert.Equal(expectedConfig, await configContent.ReadAsStringAsync().ConfigureAwait(false));
                Assert.Equal(expectedMediaType, fileContent.Headers.ContentType.MediaType);
            }
        }