Fix issue with tests and Authorize attribute
This commit is contained in:
parent
23fcfd0dc4
commit
f6b2335518
@ -15,7 +15,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
{
|
||||
public class EventBusRabbitMQ : IEventBus
|
||||
{
|
||||
private readonly string _brokerName = "event_bus";
|
||||
private readonly string _brokerName = "eshop_event_bus";
|
||||
private readonly string _connectionString;
|
||||
private readonly Dictionary<string, List<IIntegrationEventHandler>> _handlers;
|
||||
private readonly List<Type> _eventTypes;
|
||||
@ -120,24 +120,11 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
|
||||
var consumer = new EventingBasicConsumer(channel);
|
||||
consumer.Received += async (model, ea) =>
|
||||
{
|
||||
{
|
||||
var eventName = ea.RoutingKey;
|
||||
if (_handlers.ContainsKey(eventName))
|
||||
{
|
||||
var message = Encoding.UTF8.GetString(ea.Body);
|
||||
Type eventType = _eventTypes.Single(t => t.Name == eventName);
|
||||
|
||||
var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
|
||||
var handlers = _handlers[eventName];
|
||||
var message = Encoding.UTF8.GetString(ea.Body);
|
||||
|
||||
|
||||
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
|
||||
}
|
||||
}
|
||||
await ProcessEvent(eventName, message);
|
||||
};
|
||||
channel.BasicConsume(queue: _queueName,
|
||||
noAck: true,
|
||||
@ -147,5 +134,21 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
return _connection.Item1;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProcessEvent(string eventName, string message)
|
||||
{
|
||||
if (_handlers.ContainsKey(eventName))
|
||||
{
|
||||
Type eventType = _eventTypes.Single(t => t.Name == eventName);
|
||||
var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
|
||||
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
|
||||
var handlers = _handlers[eventName];
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
//[Authorize]
|
||||
[Authorize]
|
||||
public class OrdersController : Controller
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
@ -17,7 +17,7 @@ namespace FunctionalTests.Middleware
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
var identity = new ClaimsIdentity();
|
||||
var identity = new ClaimsIdentity("cookies");
|
||||
identity.AddClaim(new Claim("sub", "1234"));
|
||||
httpContext.User.AddIdentity(identity);
|
||||
await _next.Invoke(httpContext);
|
||||
|
@ -17,7 +17,7 @@ namespace IntegrationTests.Middleware
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
var identity = new ClaimsIdentity();
|
||||
var identity = new ClaimsIdentity("cookies");
|
||||
identity.AddClaim(new Claim("sub", "1234"));
|
||||
httpContext.User.AddIdentity(identity);
|
||||
await _next.Invoke(httpContext);
|
||||
|
Loading…
x
Reference in New Issue
Block a user