Browse Source

Remove Program

davidfowl/common-services
David Fowler 1 year ago
committed by Reuben Bond
parent
commit
d96e4db08c
7 changed files with 38 additions and 34 deletions
  1. +4
    -0
      src/Services/Basket/Basket.API/Basket.API.csproj
  2. +1
    -1
      src/Services/Basket/Basket.API/Controllers/BasketController.cs
  3. +2
    -2
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs
  4. +2
    -2
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs
  5. +1
    -7
      src/Services/Basket/Basket.API/Program.cs
  6. +24
    -20
      src/Services/Basket/Basket.FunctionalTests/Base/BasketScenarioBase.cs
  7. +4
    -2
      src/Services/Basket/Basket.FunctionalTests/RedisBasketRepositoryTests.cs

+ 4
- 0
src/Services/Basket/Basket.API/Basket.API.csproj View File

@ -18,4 +18,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Services.Common\Services.Common.csproj" /> <ProjectReference Include="..\..\Services.Common\Services.Common.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Basket.FunctionalTests" />
</ItemGroup>
</Project> </Project>

+ 1
- 1
src/Services/Basket/Basket.API/Controllers/BasketController.cs View File

@ -71,7 +71,7 @@ public class BasketController : ControllerBase
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.Id, Program.AppName);
_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId}", eventMessage.Id);
throw; throw;
} }


+ 2
- 2
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs View File

@ -15,9 +15,9 @@ public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<Orde
public async Task Handle(OrderStartedIntegrationEvent @event) public async Task Handle(OrderStartedIntegrationEvent @event)
{ {
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}"))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _repository.DeleteBasketAsync(@event.UserId.ToString()); await _repository.DeleteBasketAsync(@event.UserId.ToString());
} }


+ 2
- 2
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs View File

@ -15,9 +15,9 @@ public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandl
public async Task Handle(ProductPriceChangedIntegrationEvent @event) public async Task Handle(ProductPriceChangedIntegrationEvent @event)
{ {
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}"))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, @event);
var userIds = _repository.GetUsers(); var userIds = _repository.GetUsers();


+ 1
- 7
src/Services/Basket/Basket.API/Program.cs View File

@ -63,12 +63,6 @@ try
} }
catch (Exception ex) catch (Exception ex)
{ {
app.Logger.LogCritical(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName);
app.Logger.LogCritical(ex, "Program terminated unexpectedly");
return 1; return 1;
} }
public partial class Program
{
private static string Namespace = typeof(Program).Assembly.GetName().Name;
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
}

+ 24
- 20
src/Services/Basket/Basket.FunctionalTests/Base/BasketScenarioBase.cs View File

@ -3,13 +3,14 @@ using Microsoft.Extensions.Hosting;
namespace Basket.FunctionalTests.Base; namespace Basket.FunctionalTests.Base;
public class BasketScenarioBase : WebApplicationFactory<Program>
public class BasketScenarioBase
{ {
private const string ApiUrlBase = "api/v1/basket"; private const string ApiUrlBase = "api/v1/basket";
public TestServer CreateServer() public TestServer CreateServer()
{ {
return Server;
var factory = new BasketApplicaton();
return factory.Server;
} }
public static class Get public static class Get
@ -26,33 +27,36 @@ public class BasketScenarioBase : WebApplicationFactory<Program>
public static string CheckoutOrder = $"{ApiUrlBase}/checkout"; public static string CheckoutOrder = $"{ApiUrlBase}/checkout";
} }
protected override IHost CreateHost(IHostBuilder builder)
private class BasketApplicaton : WebApplicationFactory<Program>
{ {
builder.ConfigureServices(services =>
protected override IHost CreateHost(IHostBuilder builder)
{ {
services.AddSingleton<IStartupFilter, AuthStartupFilter>();
});
builder.ConfigureServices(services =>
{
services.AddSingleton<IStartupFilter, AuthStartupFilter>();
});
builder.ConfigureAppConfiguration(c =>
{
var directory = Path.GetDirectoryName(typeof(BasketScenarioBase).Assembly.Location)!;
builder.ConfigureAppConfiguration(c =>
{
var directory = Path.GetDirectoryName(typeof(BasketScenarioBase).Assembly.Location)!;
c.AddJsonFile(Path.Combine(directory, "appsettings.json"), optional: false);
});
c.AddJsonFile(Path.Combine(directory, "appsettings.json"), optional: false);
});
return base.CreateHost(builder);
}
return base.CreateHost(builder);
}
private class AuthStartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
private class AuthStartupFilter : IStartupFilter
{ {
return app =>
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{ {
app.UseMiddleware<AutoAuthorizeMiddleware>();
return app =>
{
app.UseMiddleware<AutoAuthorizeMiddleware>();
next(app);
};
next(app);
};
}
} }
} }
} }

+ 4
- 2
src/Services/Basket/Basket.FunctionalTests/RedisBasketRepositoryTests.cs View File

@ -9,7 +9,8 @@ namespace Basket.FunctionalTests
[Fact] [Fact]
public async Task UpdateBasket_return_and_add_basket() public async Task UpdateBasket_return_and_add_basket()
{ {
var redis = Services.GetRequiredService<ConnectionMultiplexer>();
var server = CreateServer();
var redis = server.Services.GetRequiredService<ConnectionMultiplexer>();
var redisBasketRepository = BuildBasketRepository(redis); var redisBasketRepository = BuildBasketRepository(redis);
@ -26,7 +27,8 @@ namespace Basket.FunctionalTests
[Fact] [Fact]
public async Task Delete_Basket_return_null() public async Task Delete_Basket_return_null()
{ {
var redis = Services.GetRequiredService<ConnectionMultiplexer>();
var server = CreateServer();
var redis = server.Services.GetRequiredService<ConnectionMultiplexer>();
var redisBasketRepository = BuildBasketRepository(redis); var redisBasketRepository = BuildBasketRepository(redis);


Loading…
Cancel
Save