Exemplo n.º 1
0
        public async Task Upload()
        {
            var content = new MultipartFormDataContent();
            var files   = Directory.GetFiles("./files")
                          .Select(path => new FileStream(path, FileMode.Open))
                          .ForEach(s =>
            {
                var fileName = Path.GetFileName(s.Name);
                content.Add(new StreamContent(s), Path.GetFileNameWithoutExtension(s.Name), fileName
                            );
            });


            var httpResponse = await this._client.PostAsync($"/upload", content);

            httpResponse.EnsureSuccessStatusCode();
            var json = await httpResponse.Content.ReadAsStringAsync();

            var result = _jsonConvertor.Deserialize <StandardResult <List <Code.FileResult> > >(json);

            foreach (var file in result.Body)
            {
                var response = await this._client.GetAsync(file.Url);

                response.EnsureSuccessStatusCode();
                var stream = await response.Content.ReadAsStreamAsync();

                Assert.True(stream.Length > 0);
                this.Show(new { Descript = file, stream.Length });
            }
        }
Exemplo n.º 2
0
 private T Deserialize <T>(string input)
 {
     return(string.IsNullOrWhiteSpace(input) ?
            default(T) :
            _jsonConvertor.Deserialize <T>(input));
 }