コード例 #1
0
        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);
                    }
                });
            });
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string          buffer = getStdin();
            FunctionHandler f      = new FunctionHandler();

            f.Handle(buffer);
        }
コード例 #3
0
ファイル: startup.cs プロジェクト: CodeIsPoetri/templates
        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
ファイル: Program.cs プロジェクト: kostkams/csharp-mongo
        // 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
ファイル: Startup.cs プロジェクト: PLoecker/csharp-kestrel
        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);
                }
            });
        }
コード例 #12
0
        public void Handle_GetsUpperCaseString_ReturnsTheSameString()
        {
            const string input = "FOOBAR";

            Assert.Equal(input, FunctionHandler.Handle(input));
        }
コード例 #13
0
        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);
        }