public Mock <IServiceProvider> GetServiceProvider(IUnitOfWork _unitOfWork, IAzureServiceBusSender <ProductSKUInventoryMovementModel> _queueService) { var spMock = new Mock <IServiceProvider>(); spMock.Setup(s => s.GetService(typeof(IUnitOfWork))) .Returns(_unitOfWork); spMock.Setup(s => s.GetService(typeof(IAzureServiceBusSender <ProductSKUInventoryMovementModel>))) .Returns(_queueService); return(spMock); }
public async Task InvokeAsync(HttpContext httpContext, IAzureServiceBusSender sender, IOptions <Configuration.PortfolioQueueNames> portfolioConfig) { string targetQueueName = null; if (httpContext.Request.Method == System.Net.Http.HttpMethod.Post.Method) { targetQueueName = portfolioConfig.Value.PortfolioCreated; } else if (httpContext.Request.Method == System.Net.Http.HttpMethod.Put.Method) { targetQueueName = portfolioConfig.Value.PortfolioUpdated; } else if (httpContext.Request.Method == System.Net.Http.HttpMethod.Delete.Method) { targetQueueName = portfolioConfig.Value.PortfolioDeleted; } if (!String.IsNullOrWhiteSpace(targetQueueName)) { httpContext.Request.EnableBuffering(); var originalPosition = httpContext.Request.Body.Position; using (var reader = new StreamReader( httpContext.Request.Body, encoding: Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: true)) { var body = await reader.ReadToEndAsync(); await sender.SendMessageAsync(body, targetQueueName); httpContext.Request.Body.Position = originalPosition; } } await _next(httpContext); }