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