Exemplo n.º 1
0
        public async Task TestPostText()
        {
            var text = "Hello world, thanks postman-echo !";

            using var fileStore = _fileStoreFactory.GetFileStoreFromName("test");

            string token = await fileStore.CreateFileToken("sample.txt");

            using (StreamWriter writer = new StreamWriter(await fileStore.OpenWrite(token)))
            {
                writer.Write(text);
            }
            HttpWorker worker   = Host.Services.GetService <HttpWorker>();
            var        response = await worker.DoJsonWork <HttpWorkerInput, HttpWorkerOutput>(new HttpWorkerInput
            {
                Method                = "POST",
                Uri                   = new Uri("https://postman-echo.com/post"),
                ContentFileToken      = token,
                OutputFileStoreName   = "test",
                OutputContentFileName = "test.json"
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.Length > 0);
            Assert.NotNull(response.ContentFileToken);
        }
Exemplo n.º 2
0
        public async Task TestErrorManagement()
        {
            HttpWorker worker   = Host.Services.GetService <HttpWorker>();
            var        response = await worker.DoJsonWork <HttpWorkerInput, HttpWorkerOutput>(new HttpWorkerInput
            {
                Method      = "GET",
                Uri         = new Uri("https://postman-echo.com/status/404"),
                FailIfError = false
            });

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            Assert.Null(response.ContentFileToken);
        }
Exemplo n.º 3
0
        public async Task TestGetJson()
        {
            HttpWorker worker   = Host.Services.GetService <HttpWorker>();
            var        response = await worker.DoJsonWork <HttpWorkerInput, HttpWorkerOutput>(new HttpWorkerInput
            {
                Method = "GET",
                Uri    = new Uri("https://postman-echo.com/get?foor=bar"),
                OutputContentFileName = "test.json",
                OutputFileStoreName   = "test"
            });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.Length > 0);

            var json = GetFileTokenContent(response.ContentFileToken);

            using (var doc = JsonDocument.Parse(json))
            {
                Assert.Equal("https://postman-echo.com/get?foor=bar", doc.RootElement.EnumerateObject().First(x => x.Name == "url").Value.GetString());
            }
        }