Fix issue with tests and Authorize attribute

This commit is contained in:
DESKTOP-V1VLQ15\dsanz 2017-03-14 14:15:34 +01:00
parent 23fcfd0dc4
commit f6b2335518
4 changed files with 23 additions and 20 deletions

View File

@ -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 });
}
}
}
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);