public void WebApplicationCreate_RegistersRouting()
        {
            var app           = WebApplication.Create();
            var linkGenerator = app.Services.GetService(typeof(LinkGenerator));

            Assert.NotNull(linkGenerator);
        }
        public void WebApplicationCreate_RegistersApiExplorerForEndpoints()
        {
            var app = WebApplication.Create();
            var apiDescriptionProvider = app.Services.GetService(typeof(IApiDescriptionProvider));

            Assert.NotNull(apiDescriptionProvider);
        }
示例#3
0
        public static async Task Main(string[] args)
        {
            await using var webApp = WebApplication.Create(args);

            webApp.MapGet("/", (Func <string>)(() => "Hello, World!"));

            await webApp.RunAsync();
        }
示例#4
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.Map("/api", subapp => new TodoApi().MapRoutes(subapp));

            await app.RunAsync();
        }
示例#5
0
        public async static Task Run()
        {
            var app = WebApplication.Create();
            Func <MakeTransfer, ActionResult> handleSaveTransfer = ConfigureSaveTransferHandler(app.Configuration);

            app.MapPost("/Transfer/Future", handleSaveTransfer);

            await app.RunAsync();
        }
示例#6
0
    public static void Main(string[] args)
    {
        var app = WebApplication.Create(args);

        app.UseStaticFiles();
        app.MapGet("/", (Func <string>)(() => "Hello, World!"));

        app.Run();
    }
示例#7
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            var todos = new TodoApi();

            todos.MapRoutes(app);

            await app.RunAsync();
        }
示例#8
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/api/todos", async context =>
            {
                await JsonSerializer.SerializeAsync(context.Response.Body, new { name = "Sirwan" }, _options);
            });
            await app.RunAsync();
        }
示例#9
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/", async context =>
            {
                await context.Response.WriteAsync("Hello World!");
            });

            await app.RunAsync();
        }
示例#10
0
    static async Task Main(string[] args)
    {
        var app = WebApplication.Create(args);

        app.MapGet("/", async http =>
        {
            await http.Response.WriteJsonAsync(new { message = "Hello World" });
        });

        await app.RunAsync();
    }
示例#11
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/api/todos", GetAll);
            app.MapGet("/api/todos/{id}", Get);
            app.MapPost("/api/todos", Post);
            app.MapDelete("/api/todos/{id}", Delete);

            await app.RunAsync();
        }
示例#12
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/api/todos", GetTodos);
            app.MapPost("/api/todos", CreateTodo);
            app.MapPost("/api/todos/{id}", UpdateCompleted);
            app.MapDelete("/api/todos/{id}", DeleteTodo);

            await app.RunAsync();
        }
示例#13
0
文件: Program.cs 项目: leicam/Fenix
        public static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapPost("/fenix/v1/clientes", IncluirCliente);
            app.MapGet("/fenix/v1/clientes", BuscarClientes);
            app.MapGet("/fenix/v1/clientes/{id}", BuscarCliente);
            app.MapPut("/fenix/v1/clientes/{id}", AtualizarCliente);
            app.MapDelete("/fenix/v1/clientes", ApagarClientes);
            app.MapDelete("/fenix/v1/clientes/{id}", ApagarCliente);

            await app.RunAsync();
        }
示例#14
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/{name?}", async http =>
            {
                http.Request.RouteValues.TryGet("name", out string name);
                name ??= "World";

                await http.Response.WriteAsync($"Hello {name}!");
            });

            await app.RunAsync();
        }
        public void WebApplicationCreate_RegistersEventSourceLogger()
        {
            var listener = new TestEventListener();
            var app      = WebApplication.Create();

            var logger = app.Services.GetRequiredService <ILogger <WebApplicationTests> >();
            var guid   = Guid.NewGuid().ToString();

            logger.LogInformation(guid);

            var events = listener.EventData.ToArray();

            Assert.Contains(events, args =>
                            args.EventSource.Name == "Microsoft-Extensions-Logging" &&
                            args.Payload.OfType <string>().Any(p => p.Contains(guid)));
        }
        public async Task EnvironmentSpecificLoggingConfigurationSectionPassedToLoggerByDefault()
        {
            try
            {
                await File.WriteAllTextAsync("appsettings.Development.json", @"
{
    ""Logging"": {
        ""LogLevel"": {
            ""Default"": ""Warning""
        }
    }
}");

                var app = WebApplication.Create(new[] { "--environment", "Development" });

                // TODO: Make this work! I think it should be possible if we register our Configuration
                // as a ChainedConfigurationSource instead of copying over the bootstrapped IConfigurationSources.
                //var builder = WebApplication.CreateBuilder();
                //builder.Environment.EnvironmentName = "Development";
                //await using var app = builder.Build();

                var factory = (ILoggerFactory)app.Services.GetService(typeof(ILoggerFactory));
                var logger  = factory.CreateLogger("Test");

                logger.Log(LogLevel.Information, 0, "Message", null, (s, e) =>
                {
                    Assert.True(false);
                    return(string.Empty);
                });

                var logWritten = false;
                logger.Log(LogLevel.Warning, 0, "Message", null, (s, e) =>
                {
                    logWritten = true;
                    return(string.Empty);
                });

                Assert.True(logWritten);
            }
            finally
            {
                File.Delete("appsettings.json");
            }
        }
        async void ExecuteSubirServidorCommand()
        {
            if (_appState.Applications.Select(x => x.Item1).Any(x => x == Selected.Id))
            {
                return;
            }

            //
            var app = WebApplication.Create();

            app.Listen($"https://localhost:{Selected.PortaPadrao}");

            foreach (var endpoint in Selected.Items)
            {
                if (endpoint.Metodo == Core.MetodoHttp.MhGet)
                {
                    app.MapGet(endpoint.Endpoint, async(context) =>
                    {
                        await ProcessarRequisicao(context, endpoint);
                    });
                }

                if (endpoint.Metodo == Core.MetodoHttp.MhPost)
                {
                    app.MapPost(endpoint.Endpoint, async(context) =>
                    {
                        //using (var reader = new StreamReader(context.Request.Body))
                        //{
                        //    var body = await reader.ReadToEndAsync();

                        //    var json = JsonConvert.DeserializeObject(body);
                        //}

                        await ProcessarRequisicao(context, endpoint);
                    });
                }
            }

            _appState.Applications.Add((Selected.Id, app));
            RaisePropertyChanged(nameof(IsActive));
            //await app.RunAsync(_cancellationToken);
        }
    public async Task EnvironmentSpecificLoggingConfigurationSectionPassedToLoggerByDefault()
    {
        var contentRootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

        Directory.CreateDirectory(contentRootPath);

        try
        {
            await File.WriteAllTextAsync(Path.Combine(contentRootPath, "appsettings.Development.json"), @"
{
    ""Logging"": {
        ""LogLevel"": {
            ""Default"": ""Warning""
        }
    }
}");

            var app = WebApplication.Create(new[] { "--environment", "Development", "--contentRoot", contentRootPath });

            var factory = (ILoggerFactory)app.Services.GetService(typeof(ILoggerFactory));
            var logger  = factory.CreateLogger("Test");

            logger.Log(LogLevel.Information, 0, "Message", null, (s, e) =>
            {
                Assert.True(false);
                return(string.Empty);
            });

            var logWritten = false;
            logger.Log(LogLevel.Warning, 0, "Message", null, (s, e) =>
            {
                logWritten = true;
                return(string.Empty);
            });

            Assert.True(logWritten);
        }
        finally
        {
            Directory.Delete(contentRootPath, recursive: true);
        }
    }
        public async Task LoggingConfigurationSectionPassedToLoggerByDefault()
        {
            try
            {
                await File.WriteAllTextAsync("appsettings.json", @"
{
    ""Logging"": {
        ""LogLevel"": {
            ""Default"": ""Warning""
        }
    }
}");

                await using var app = WebApplication.Create();

                var factory = (ILoggerFactory)app.Services.GetService(typeof(ILoggerFactory));
                var logger  = factory.CreateLogger("Test");

                logger.Log(LogLevel.Information, 0, "Message", null, (s, e) =>
                {
                    Assert.True(false);
                    return(string.Empty);
                });

                var logWritten = false;
                logger.Log(LogLevel.Warning, 0, "Message", null, (s, e) =>
                {
                    logWritten = true;
                    return(string.Empty);
                });

                Assert.True(logWritten);
            }
            finally
            {
                File.Delete("appsettings.json");
            }
        }
示例#20
0
        /// <summary>
        /// Entry Point for initialization and route registering
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            ServiceDependency.Init();
            var receiver   = ServiceDependency.InternalServiceProvider.GetService <IReceiver>();
            var observable = ServiceDependency.InternalServiceProvider.GetService <IEventObserver>();
            var subscriber = ServiceDependency.InternalServiceProvider.GetService <ISendMessage>();

            subscriber.Subscribe(observable);

            await receiver.StartReader();

            app.MapPost("/receiver", async http =>
            {
                var request = await http.Request.ReadJsonAsync <SNSRequest>();
                await receiver.Accept(request);
                http.Response.StatusCode = StatusCodes.Status200OK;
            });


            await app.RunAsync();
        }
示例#21
0
        static async Task Main(string[] args)
        {
            var ledService = new LEDService();
            var app        = WebApplication.Create(args);

            app.MapGet("/green", async http =>
            {
                ledService.ToggleGreen();
                await http.Response.WriteJsonAsync(new { success = true });
            });
            app.MapGet("/amber", async http =>
            {
                ledService.ToggleGold();
                await http.Response.WriteJsonAsync(new { success = true });
            });
            app.MapGet("/red", async http =>
            {
                ledService.ToggleRed();
                await http.Response.WriteJsonAsync(new { success = true });
            });

            await app.RunAsync();
        }
示例#22
0
        static async Task Main(string[] args)
        {
            var app = WebApplication.Create(args);

            app.MapGet("/api/repositories", async(context) => {
                await context.Response.WriteJsonAsync(Repositories);
            });

            app.MapPost("/api/repositories", async(context) => {
                var repo = await JsonSerializer.DeserializeAsync <Repository>(context.Request.Body, _options);

                repo.Id = Guid.NewGuid();

                Repositories.Add(repo);

                await context.Response.WriteJsonAsync(repo);
            });

            app.MapPut("/api/repositories/{id}", async(context) => {
                var id = Guid.Parse((string)context.Request.RouteValues["id"]);

                var repoIndex = Repositories.FindIndex(repo => repo.Id == id);

                if (repoIndex < 0)
                {
                    context.Response.StatusCode = StatusCodes.Status400BadRequest;
                    await context.Response.WriteJsonAsync(new { Error = "Repository not found." });
                    return;
                }

                var repo = await JsonSerializer.DeserializeAsync <Repository>(context.Request.Body, _options);

                var repoUpdated = new Repository {
                    Id    = id,
                    Url   = repo.Url,
                    Title = repo.Title,
                    Techs = repo.Techs,
                    Likes = 0
                };

                Repositories[repoIndex] = repoUpdated;

                await context.Response.WriteJsonAsync(repoUpdated);
            });

            app.MapDelete("/api/repositories/{id}", async(context) => {
                var id = Guid.Parse((string)context.Request.RouteValues["id"]);

                var repoIndex = Repositories.FindIndex(repo => repo.Id == id);

                if (repoIndex < 0)
                {
                    context.Response.StatusCode = StatusCodes.Status400BadRequest;
                    await context.Response.WriteJsonAsync(new { Error = "Repository not found." });
                    return;
                }

                Repositories.RemoveAt(repoIndex);

                context.Response.StatusCode = StatusCodes.Status204NoContent;
            });

            app.MapPost("/api/repositories/{id}/like", async(context) => {
                var id = Guid.Parse((string)context.Request.RouteValues["id"]);
                Console.WriteLine($"Repo ID: {id}");
                var repoIndex = Repositories.FindIndex(repo => repo.Id == id);

                if (repoIndex < 0)
                {
                    context.Response.StatusCode = StatusCodes.Status400BadRequest;
                    await context.Response.WriteJsonAsync(new { Error = "Repository not found." });
                    return;
                }

                var likes = Repositories[repoIndex].Likes;

                Repositories[repoIndex].Likes = ++likes;

                await context.Response.WriteJsonAsync(new { Likes = likes });
            });

            await app.RunAsync();
        }