diff --git a/fundamentals/minimal-apis/samples/MinApiTestsSample/IntegrationTests/Helpers/TestWebApplicationFactory.cs b/fundamentals/minimal-apis/samples/MinApiTestsSample/IntegrationTests/Helpers/TestWebApplicationFactory.cs index d8853e9..577fd91 100644 --- a/fundamentals/minimal-apis/samples/MinApiTestsSample/IntegrationTests/Helpers/TestWebApplicationFactory.cs +++ b/fundamentals/minimal-apis/samples/MinApiTestsSample/IntegrationTests/Helpers/TestWebApplicationFactory.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using WebMinRouteGroup.Data; @@ -11,6 +12,11 @@ public class TestWebApplicationFactory { protected override IHost CreateHost(IHostBuilder builder) { + builder.ConfigureHostConfiguration(config => + { + config.AddInMemoryCollection(new Dictionary { { "EmailAddress", "test1@Contoso.com" } }); + }); + builder.ConfigureServices(services => { var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions)); diff --git a/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/Services/TodoService.cs b/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/Services/TodoService.cs index 54689cd..f7a4f65 100644 --- a/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/Services/TodoService.cs +++ b/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/Services/TodoService.cs @@ -7,11 +7,13 @@ public class TodoService : ITodoService { private readonly TodoGroupDbContext _dbContext; private readonly IEmailService _emailService; + private readonly IConfiguration _configuration; - public TodoService(TodoGroupDbContext dbContext, IEmailService emailService) + public TodoService(TodoGroupDbContext dbContext, IEmailService emailService, IConfiguration configuration) { _dbContext = dbContext; _emailService = emailService; + _configuration = configuration; } public async ValueTask Find(int id) @@ -29,7 +31,7 @@ public class TodoService : ITodoService await _dbContext.Todos.AddAsync(todo); if (await _dbContext.SaveChangesAsync() > 0) - await _emailService.Send("hello@microsoft.com", $"New todo has been added: {todo.Title}"); + await _emailService.Send(_configuration["EmailAddress"]!, $"New todo has been added: {todo.Title}"); } public async Task Update(Todo todo) diff --git a/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/appsettings.json b/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/appsettings.json index 10f68b8..9d91f8b 100644 --- a/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/appsettings.json +++ b/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "EmailAddress": "test1@Contoso.com" }