public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapPost("/", async context =>
                {
                    try
                    {
                        using var reader = new StreamReader(context.Request.Body);

                        var data    = await reader.ReadToEndAsync();
                        var handler = new FunctionHandler();
                        var result  = await handler.Handle(data);
                        await context.Response.WriteAsync(result);
                    }
                    catch (Exception ex)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        await context.Response.WriteAsync(ex.Message);
                    }
                });
            });
        }
        static void Main(string[] args)
        {
            string          buffer = getStdin();
            FunctionHandler f      = new FunctionHandler();

            f.Handle(buffer);
        }
示例#3
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                var functionHandler = new FunctionHandler();
                try
                {
                    var response = functionHandler.Handle(context.Request);
                    context.Response.StatusCode = response.statusCode;
                    foreach (KeyValuePair <string, string> entry in response.headers)
                    {
                        HeaderDictionaryExtensions.Append(context.Response.Headers, entry.Key, entry.Value);
                    }
                    await context.Response.WriteAsync(response.body);
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    await context.Response.WriteAsync(ex.Message);
                }
            });
        }
示例#4
0
        static void Main(string[] args)
        {
            string          buffer  = getStdin();
            var             context = new DefaultFunctionContext();
            FunctionHandler f       = new FunctionHandler(context);

            f.Handle(buffer);
        }
示例#5
0
        public void ExtractHtml()
        {
            var             message = File.OpenText("encoded.txt").ReadToEnd();
            FunctionHandler handler = new FunctionHandler();
            var             result  = handler.Handle(message);

            Assert.Contains("Purchase Order 16487645-2", result);
        }
示例#6
0
        public void Test1()
        {
            var fh  = new FunctionHandler();
            var res = fh.Handle("This is my input");

            var expected = "Hi there - your input was: This is my input\n";

            Assert.Equal(res, expected);
        }
示例#7
0
文件: Program.cs 项目: TapiQQ/testapi
        static void Main(string[] args)
        {
            string          buffer = Console.In.ReadToEnd();
            FunctionHandler f      = new FunctionHandler();

            string responseValue = f.Handle(buffer);

            if (responseValue != null)
            {
                Console.Write(responseValue);
            }
        }
示例#8
0
        static async Task MainAsync()
        {
            string buffer = await Console.In.ReadToEndAsync();

            FunctionHandler f = new FunctionHandler();

            string responseValue = await f.Handle(buffer);

            if (responseValue != null)
            {
                Console.Write(responseValue);
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            string buffer = Console.In.ReadToEnd();

            var             serviceProvider = DependencyRegistrations.ConfigureServices();
            FunctionHandler f = (FunctionHandler)serviceProvider.GetService(typeof(FunctionHandler));

            string responseValue = f.Handle(buffer);

            if (responseValue != null)
            {
                Console.Write(responseValue);
            }
        }
示例#10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.Run(async(context) =>
            {
                var functionHandler = new FunctionHandler();

                // Set up the MongoDB connection before calling the function handler.
                functionHandler.SetupConnection();

                try
                {
                    var requestBody = getRequest(context.Request.Body);
                    var result      = functionHandler.Handle(requestBody).Result;

                    await context.Response.WriteAsync(result);
                }
                catch (Exception ex)
                {
                    await context.Response.WriteAsync(ex.Message);
                }
            });
        }
示例#11
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                var functionHandler = new FunctionHandler();
                try
                {
                    var requestBody = getRequest(context.Request.Body);
                    var result      = functionHandler.Handle(requestBody).Result;
                    await context.Response.WriteAsync(result);
                }
                catch (Exception ex)
                {
                    await context.Response.WriteAsync(ex.Message);
                }
            });
        }
        public void Handle_GetsUpperCaseString_ReturnsTheSameString()
        {
            const string input = "FOOBAR";

            Assert.Equal(input, FunctionHandler.Handle(input));
        }
        public void Handle_GetsNotFullyUpperCaseStrings_ReturnsUpperCaseStrings(string input)
        {
            const string expected = "FOOBAR";

            Assert.Equal(expected, FunctionHandler.Handle(input));
        }
示例#14
0
        public async Task HandleTest()
        {
            var result = await _handler.Handle(_mockRequest.Object);

            Assert.Equal(System.Net.HttpStatusCode.OK, result.Status);
        }