Updates all the services to .NET 6.0 (#1770)
* Created global using file for catalog.api * Moved individual usings statements to globalusing * Updated catalog.api project * Fixed local run bug for catalog.api * Included globalusing for payment.api * Refactored namespace statement for payment.api * Moved namespaces to ordering.domain project * Included globalusing for ordering.domain project * Included globalusings for ordering.infrastructure project * Refactored namespaces for ordering.infrastructure project * Updated relevant packages in ordering.infrastructure project * Included globalusings for ordering.signalrHub project * Moved all the namespace to globalusings * Updated packages in ordering.signalrHub csproj file * Refactored namespace statements in catalog.api project * Fixed namespace name in ordering.domain * Included global usings for ordering.api project * Moved all usings to globalusing file * Updated ordering.api csproj project * Fixed bug in statup.cs * Updated ordering.unittests.csproj file * Included globalusings in webhooks.api project * Moved using statements to globalusing file in webhooks.api * Included globalusing for web.bff.shoppping aggregator project * Moved namespaces to globalusing shopping aggregator * Included globalusing mobile.bff.shoppping project * Moved namespaces to globalusing file * Included globalusing for eventbus project * Moved namespaces to global usings for eventbus * Included globalusing for EventBusRabbitMQ project * Moved using statements to EventBusRabbitMQ project * Included global using in EventBusServiceBus project * Moved using statements to globalusing for EventBusServiceBus * Included globalusing file for IntegrationEventLogEF project * Move using statements to globalusing file * Updated packages of IntegrationEventLogEF project * Included globalusing to Devspaces.Support project * Moved using statements to globalusing Devspaces * Updated dependent packages for Devspaces.Support.csproj * Fixed bug in Basket API * Fixed bug in catalog.api * Fixed bug Identity.API * Included globalusing to Basket.UnitTest project * Moved namespaces to Basket.UnitTest project * Updated packages of Basket.UnitTest csproj * Included globalusing for Basket.FunctionalTests project * Included file-scoped namespaces Basket.FunctionalTests * Updated packages of Basket.FunctionalTests.csproj file * Updated catalog unit test project to Net 6.0 * Included global usings for Catalog.FunctionalTests * Included file-scope namespace catalog.functionaltests * Updated packages of catalog.functionaltest csproj * Included MigrateDbContext method in HostExtensions * Included globalusing for ordering.UnitTests project * Included file-scope statement for Ordering.UnitTest project * Included globalusing for Ordering.FunctionalTests * Included file-scope namespace statement for using * Updated packages in Ordering.FunctionalTests.csproj * Apply suggestions from code review Co-authored-by: David Pine <david.pine@microsoft.com> * Apply suggestions from code review Co-authored-by: David Pine <david.pine@microsoft.com> * Update src/Services/Ordering/Ordering.API/Startup.cs Co-authored-by: David Pine <david.pine@microsoft.com> * Update src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToPaidDomainEvent.cs Co-authored-by: David Pine <david.pine@microsoft.com> * Update src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs Co-authored-by: David Pine <david.pine@microsoft.com> * Update src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs Co-authored-by: David Pine <david.pine@microsoft.com> * Apply suggestions from code review Co-authored-by: David Pine <david.pine@microsoft.com> * Apply suggestions from code review Co-authored-by: David Pine <david.pine@microsoft.com> Co-authored-by: David Pine <david.pine@microsoft.com>
This commit is contained in:
parent
ab1d9cc897
commit
c37320b3e5
@ -1,9 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config
|
||||
public class UrlsConfig
|
||||
{
|
||||
public class UrlsConfig
|
||||
{
|
||||
public class CatalogOperations
|
||||
{
|
||||
public static string GetItemById(int id) => $"/api/v1/catalog/items/{id}";
|
||||
@ -34,5 +32,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config
|
||||
public string GrpcCatalog { get; set; }
|
||||
|
||||
public string GrpcOrdering { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class BasketController : ControllerBase
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class BasketController : ControllerBase
|
||||
{
|
||||
private readonly ICatalogService _catalog;
|
||||
private readonly IBasketService _basket;
|
||||
|
||||
@ -152,5 +143,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
[Route("")]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[Route("")]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[HttpGet()]
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return new RedirectResult("~/swagger");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class OrderController : ControllerBase
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class OrderController : ControllerBase
|
||||
{
|
||||
private readonly IBasketService _basketService;
|
||||
private readonly IOrderingService _orderingService;
|
||||
|
||||
@ -41,5 +34,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
|
||||
return await _orderingService.GetOrderDraftAsync(basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters
|
||||
{
|
||||
|
||||
namespace Basket.API.Infrastructure.Filters
|
||||
{
|
||||
public class AuthorizeCheckOperationFilter : IOperationFilter
|
||||
|
@ -0,0 +1,41 @@
|
||||
global using CatalogApi;
|
||||
global using Devspaces.Support;
|
||||
global using Grpc.Core.Interceptors;
|
||||
global using Grpc.Core;
|
||||
global using GrpcBasket;
|
||||
global using GrpcOrdering;
|
||||
global using HealthChecks.UI.Client;
|
||||
global using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
global using Microsoft.AspNetCore.Authentication;
|
||||
global using Microsoft.AspNetCore.Authorization;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.AspNetCore;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
global using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Microsoft.OpenApi.Models;
|
||||
global using Serilog;
|
||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IdentityModel.Tokens.Jwt;
|
||||
global using System.Linq;
|
||||
global using System.Net.Http.Headers;
|
||||
global using System.Net.Http;
|
||||
global using System.Net;
|
||||
global using System.Text.Json;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Threading;
|
||||
global using System;
|
@ -1,12 +1,7 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure
|
||||
public class GrpcExceptionInterceptor : Interceptor
|
||||
{
|
||||
public class GrpcExceptionInterceptor : Interceptor
|
||||
{
|
||||
private readonly ILogger<GrpcExceptionInterceptor> _logger;
|
||||
|
||||
public GrpcExceptionInterceptor(ILogger<GrpcExceptionInterceptor> logger)
|
||||
@ -37,5 +32,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,7 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure
|
||||
public class HttpClientAuthorizationDelegatingHandler : DelegatingHandler
|
||||
{
|
||||
public class HttpClientAuthorizationDelegatingHandler : DelegatingHandler
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ILogger<HttpClientAuthorizationDelegatingHandler> _logger;
|
||||
|
||||
@ -50,5 +41,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct
|
||||
return await _httpContextAccessor.HttpContext
|
||||
.GetTokenAsync(ACCESS_TOKEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class AddBasketItemRequest
|
||||
{
|
||||
public class AddBasketItemRequest
|
||||
{
|
||||
public int CatalogItemId { get; set; }
|
||||
|
||||
public string BasketId { get; set; }
|
||||
@ -12,5 +12,4 @@
|
||||
{
|
||||
Quantity = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
public class BasketData
|
||||
{
|
||||
|
||||
public class BasketData
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
public List<BasketDataItem> Items { get; set; } = new List<BasketDataItem>();
|
||||
public List<BasketDataItem> Items { get; set; } = new();
|
||||
|
||||
public BasketData()
|
||||
{
|
||||
@ -17,6 +14,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
BuyerId = buyerId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class BasketDataItem
|
||||
{
|
||||
public class BasketDataItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
@ -16,6 +15,4 @@
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public string PictureUrl { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class CatalogItem
|
||||
{
|
||||
public class CatalogItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
@ -9,5 +9,4 @@
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public string PictureUri { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
public class OrderData
|
||||
{
|
||||
|
||||
public class OrderData
|
||||
{
|
||||
public string OrderNumber { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
@ -42,7 +38,5 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
|
||||
public string Buyer { get; set; }
|
||||
|
||||
public List<OrderItemData> OrderItems { get; } = new List<OrderItemData>();
|
||||
}
|
||||
|
||||
public List<OrderItemData> OrderItems { get; } = new();
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class OrderItemData
|
||||
{
|
||||
public class OrderItemData
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
@ -14,6 +13,4 @@
|
||||
public int Units { get; set; }
|
||||
|
||||
public string PictureUrl { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class UpdateBasketItemData
|
||||
{
|
||||
public class UpdateBasketItemData
|
||||
{
|
||||
public string BasketItemId { get; set; }
|
||||
|
||||
public int NewQty { get; set; }
|
||||
@ -11,6 +10,4 @@
|
||||
{
|
||||
NewQty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
public class UpdateBasketItemsRequest
|
||||
{
|
||||
|
||||
public class UpdateBasketItemsRequest
|
||||
{
|
||||
|
||||
public string BasketId { get; set; }
|
||||
|
||||
public ICollection<UpdateBasketItemData> Updates { get; set; }
|
||||
@ -14,6 +11,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
Updates = new List<UpdateBasketItemData>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
public class UpdateBasketRequest
|
||||
{
|
||||
|
||||
public class UpdateBasketRequest
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
public IEnumerable<UpdateBasketRequestItemData> Items { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class UpdateBasketRequestItemData
|
||||
{
|
||||
public class UpdateBasketRequestItemData
|
||||
{
|
||||
public string Id { get; set; } // Basket id
|
||||
|
||||
public int ProductId { get; set; } // Catalog item id
|
||||
|
||||
public int Quantity { get; set; } // Quantity
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator;
|
||||
using Serilog;
|
||||
|
||||
|
||||
BuildWebHost(args).Run();
|
||||
await BuildWebHost(args).RunAsync();
|
||||
IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost
|
||||
.CreateDefaultBuilder(args)
|
||||
|
@ -1,13 +1,7 @@
|
||||
using GrpcBasket;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
private readonly Basket.BasketClient _basketClient;
|
||||
private readonly ILogger<BasketService> _logger;
|
||||
|
||||
@ -86,5 +80,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
using CatalogApi;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly Catalog.CatalogClient _client;
|
||||
|
||||
public CatalogService(Catalog.CatalogClient client)
|
||||
@ -39,5 +33,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
Price = (decimal)catalogItemResponse.Price
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,9 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public interface IBasketService
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketData> GetById(string id);
|
||||
Task<BasketData> GetByIdAsync(string id);
|
||||
|
||||
Task UpdateAsync(BasketData currentBasket);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public interface ICatalogService
|
||||
{
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<CatalogItem> GetCatalogItemAsync(int id);
|
||||
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public interface IOrderingService
|
||||
{
|
||||
public interface IOrderingService
|
||||
{
|
||||
Task<OrderData> GetOrderDraftAsync(BasketData basketData);
|
||||
}
|
||||
}
|
@ -1,15 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
private readonly HttpClient _apiClient;
|
||||
private readonly ILogger<OrderApiClient> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
@ -36,5 +28,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
using GrpcOrdering;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
public class OrderingService : IOrderingService
|
||||
{
|
||||
public class OrderingService : IOrderingService
|
||||
{
|
||||
private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
|
||||
private readonly ILogger<OrderingService> _logger;
|
||||
|
||||
@ -75,5 +69,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
return command;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,7 @@
|
||||
using CatalogApi;
|
||||
using Devspaces.Support;
|
||||
using GrpcBasket;
|
||||
using GrpcOrdering;
|
||||
using HealthChecks.UI.Client;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
public class Startup
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
@ -97,10 +72,10 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddCustomMvc(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddOptions();
|
||||
@ -218,5 +193,4 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
return services;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config
|
||||
public class UrlsConfig
|
||||
{
|
||||
|
||||
public class UrlsConfig
|
||||
{
|
||||
|
||||
public class CatalogOperations
|
||||
{
|
||||
// grpc call under REST must go trough port 80
|
||||
@ -40,6 +37,5 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config
|
||||
public string GrpcCatalog { get; set; }
|
||||
|
||||
public string GrpcOrdering { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class BasketController : ControllerBase
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class BasketController : ControllerBase
|
||||
{
|
||||
private readonly ICatalogService _catalog;
|
||||
private readonly IBasketService _basket;
|
||||
|
||||
@ -35,7 +26,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var basket = await _basket.GetById(data.BuyerId) ?? new BasketData(data.BuyerId);
|
||||
var basket = await _basket.GetByIdAsync(data.BuyerId) ?? new BasketData(data.BuyerId);
|
||||
var catalogItems = await _catalog.GetCatalogItemsAsync(data.Items.Select(x => x.ProductId));
|
||||
|
||||
// group by product id to avoid duplicates
|
||||
@ -93,7 +84,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var currentBasket = await _basket.GetById(data.BasketId);
|
||||
var currentBasket = await _basket.GetByIdAsync(data.BasketId);
|
||||
if (currentBasket == null)
|
||||
{
|
||||
return BadRequest($"Basket with id {data.BasketId} not found.");
|
||||
@ -160,5 +151,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
[Route("")]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[Route("")]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[HttpGet()]
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return new RedirectResult("~/swagger");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,13 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class OrderController : ControllerBase
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class OrderController : ControllerBase
|
||||
{
|
||||
private readonly IBasketService _basketService;
|
||||
private readonly IOrderingService _orderingService;
|
||||
|
||||
public OrderController(IBasketService basketService, IOrderingService orderingService)
|
||||
{
|
||||
_basketService = basketService;
|
||||
@ -26,12 +20,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
[ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(basketId))
|
||||
if (string.IsNullOrWhitespace(basketId))
|
||||
{
|
||||
return BadRequest("Need a valid basketid");
|
||||
}
|
||||
// Get the basket data and build a order draft based on it
|
||||
var basket = await _basketService.GetById(basketId);
|
||||
var basket = await _basketService.GetByIdAsync(basketId);
|
||||
|
||||
if (basket == null)
|
||||
{
|
||||
@ -40,5 +34,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
|
||||
return await _orderingService.GetOrderDraftAsync(basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters
|
||||
{
|
||||
namespace Basket.API.Infrastructure.Filters
|
||||
{
|
||||
@ -30,10 +24,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters
|
||||
{
|
||||
new OpenApiSecurityRequirement
|
||||
{
|
||||
[ oAuthScheme ] = new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" }
|
||||
[ oAuthScheme ] = new[] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" }
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
41
src/ApiGateways/Web.Bff.Shopping/aggregator/GlobalUsings.cs
Normal file
41
src/ApiGateways/Web.Bff.Shopping/aggregator/GlobalUsings.cs
Normal file
@ -0,0 +1,41 @@
|
||||
global using CatalogApi;
|
||||
global using Devspaces.Support;
|
||||
global using Grpc.Core.Interceptors;
|
||||
global using Grpc.Core;
|
||||
global using GrpcBasket;
|
||||
global using GrpcOrdering;
|
||||
global using HealthChecks.UI.Client;
|
||||
global using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
global using Microsoft.AspNetCore.Authentication;
|
||||
global using Microsoft.AspNetCore.Authorization;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.AspNetCore;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
global using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Microsoft.OpenApi.Models;
|
||||
global using Serilog;
|
||||
global using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IdentityModel.Tokens.Jwt;
|
||||
global using System.Linq;
|
||||
global using System.Net.Http.Headers;
|
||||
global using System.Net.Http;
|
||||
global using System.Net;
|
||||
global using System.Text.Json;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Threading;
|
||||
global using System;
|
@ -1,12 +1,7 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
public class GrpcExceptionInterceptor : Interceptor
|
||||
{
|
||||
public class GrpcExceptionInterceptor : Interceptor
|
||||
{
|
||||
private readonly ILogger<GrpcExceptionInterceptor> _logger;
|
||||
|
||||
public GrpcExceptionInterceptor(ILogger<GrpcExceptionInterceptor> logger)
|
||||
@ -24,11 +19,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
return new AsyncUnaryCall<TResponse>(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose);
|
||||
}
|
||||
|
||||
private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t)
|
||||
private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> task)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await t;
|
||||
var response = await task;
|
||||
return response;
|
||||
}
|
||||
catch (RpcException e)
|
||||
@ -37,5 +32,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,8 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
{
|
||||
public class HttpClientAuthorizationDelegatingHandler
|
||||
public class HttpClientAuthorizationDelegatingHandler
|
||||
: DelegatingHandler
|
||||
{
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public HttpClientAuthorizationDelegatingHandler(IHttpContextAccessor httpContextAccessor)
|
||||
@ -23,12 +15,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
var authorizationHeader = _httpContextAccessor.HttpContext
|
||||
.Request.Headers["Authorization"];
|
||||
|
||||
if (!string.IsNullOrEmpty(authorizationHeader))
|
||||
if (!string.IsNullOrWhitespace(authorizationHeader))
|
||||
{
|
||||
request.Headers.Add("Authorization", new List<string>() { authorizationHeader });
|
||||
}
|
||||
|
||||
var token = await GetToken();
|
||||
var token = await GetTokenAsync();
|
||||
|
||||
if (token != null)
|
||||
{
|
||||
@ -38,12 +30,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
return await base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
|
||||
async Task<string> GetToken()
|
||||
Task<string> GetTokenAsync()
|
||||
{
|
||||
const string ACCESS_TOKEN = "access_token";
|
||||
|
||||
return await _httpContextAccessor.HttpContext
|
||||
return _httpContextAccessor.HttpContext
|
||||
.GetTokenAsync(ACCESS_TOKEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class AddBasketItemRequest
|
||||
{
|
||||
public class AddBasketItemRequest
|
||||
{
|
||||
public int CatalogItemId { get; set; }
|
||||
|
||||
public string BasketId { get; set; }
|
||||
@ -13,6 +12,5 @@
|
||||
{
|
||||
Quantity = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
public class BasketData
|
||||
{
|
||||
|
||||
public class BasketData
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
public List<BasketDataItem> Items { get; set; } = new List<BasketDataItem>();
|
||||
public List<BasketDataItem> Items { get; set; } = new();
|
||||
|
||||
public BasketData()
|
||||
{
|
||||
@ -17,6 +14,5 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
BuyerId = buyerId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class BasketDataItem
|
||||
{
|
||||
public class BasketDataItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
@ -16,6 +15,4 @@
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public string PictureUrl { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class CatalogItem
|
||||
{
|
||||
public class CatalogItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
@ -10,6 +9,6 @@
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public string PictureUri { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
public class OrderData
|
||||
{
|
||||
|
||||
public class OrderData
|
||||
{
|
||||
public string OrderNumber { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
@ -42,7 +38,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
|
||||
public string Buyer { get; set; }
|
||||
|
||||
public List<OrderItemData> OrderItems { get; } = new List<OrderItemData>();
|
||||
}
|
||||
|
||||
public List<OrderItemData> OrderItems { get; } = new();
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class OrderItemData
|
||||
{
|
||||
public class OrderItemData
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
@ -14,6 +13,4 @@
|
||||
public int Units { get; set; }
|
||||
|
||||
public string PictureUrl { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,9 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class UpdateBasketItemData
|
||||
{
|
||||
public class UpdateBasketItemData
|
||||
{
|
||||
public string BasketItemId { get; set; }
|
||||
|
||||
public int NewQty { get; set; }
|
||||
|
||||
public UpdateBasketItemData()
|
||||
{
|
||||
NewQty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
public class UpdateBasketItemsRequest
|
||||
{
|
||||
|
||||
public class UpdateBasketItemsRequest
|
||||
{
|
||||
public string BasketId { get; set; }
|
||||
|
||||
public ICollection<UpdateBasketItemData> Updates { get; set; }
|
||||
@ -13,6 +10,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
Updates = new List<UpdateBasketItemData>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
public class UpdateBasketRequest
|
||||
{
|
||||
|
||||
public class UpdateBasketRequest
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
public IEnumerable<UpdateBasketRequestItemData> Items { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
|
||||
public class UpdateBasketRequestItemData
|
||||
{
|
||||
public class UpdateBasketRequestItemData
|
||||
{
|
||||
public string Id { get; set; } // Basket id
|
||||
|
||||
public int ProductId { get; set; } // Catalog item id
|
||||
|
||||
public int Quantity { get; set; } // Quantity
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator;
|
||||
using Serilog;
|
||||
|
||||
BuildWebHost(args).Run();
|
||||
await BuildWebHost(args).RunAsync();
|
||||
|
||||
IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost
|
||||
|
@ -1,13 +1,7 @@
|
||||
using GrpcBasket;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
private readonly Basket.BasketClient _basketClient;
|
||||
private readonly ILogger<BasketService> _logger;
|
||||
|
||||
@ -99,5 +93,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,7 @@
|
||||
using CatalogApi;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly Catalog.CatalogClient _client;
|
||||
private readonly ILogger<CatalogService> _logger;
|
||||
|
||||
@ -48,5 +41,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
Price = (decimal)catalogItemResponse.Price
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,8 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public interface IBasketService
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketData> GetById(string id);
|
||||
Task<BasketData> GetByIdAsync(string id);
|
||||
|
||||
Task UpdateAsync(BasketData currentBasket);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public interface ICatalogService
|
||||
{
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<CatalogItem> GetCatalogItemAsync(int id);
|
||||
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public interface IOrderingService
|
||||
{
|
||||
public interface IOrderingService
|
||||
{
|
||||
Task<OrderData> GetOrderDraftAsync(BasketData basketData);
|
||||
}
|
||||
}
|
@ -1,15 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
private readonly HttpClient _apiClient;
|
||||
private readonly ILogger<OrderApiClient> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
@ -23,7 +15,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket)
|
||||
{
|
||||
var url = _urls.Orders + UrlsConfig.OrdersOperations.GetOrderDraft();
|
||||
var url = $"{_urls.Orders}{UrlsConfig.OrdersOperations.GetOrderDraft()}";
|
||||
var content = new StringContent(JsonSerializer.Serialize(basket), System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await _apiClient.PostAsync(url, content);
|
||||
|
||||
@ -36,5 +28,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
using GrpcOrdering;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
public class OrderingService : IOrderingService
|
||||
{
|
||||
public class OrderingService : IOrderingService
|
||||
{
|
||||
private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
|
||||
private readonly ILogger<OrderingService> _logger;
|
||||
|
||||
@ -75,5 +69,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
return command;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,7 @@
|
||||
using CatalogApi;
|
||||
using Devspaces.Support;
|
||||
using GrpcBasket;
|
||||
using GrpcOrdering;
|
||||
using HealthChecks.UI.Client;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Filters.Basket.API.Infrastructure.Filters;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
public class Startup
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
@ -99,10 +74,10 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
||||
@ -221,5 +196,4 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0-preview.7.21377.19" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0-preview.7.21377.19" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,13 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
namespace Devspaces.Support;
|
||||
|
||||
namespace Devspaces.Support
|
||||
public class DevspacesMessageHandler : DelegatingHandler
|
||||
{
|
||||
public class DevspacesMessageHandler : DelegatingHandler
|
||||
{
|
||||
private const string DevspacesHeaderName = "azds-route-as";
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
public DevspacesMessageHandler(IHttpContextAccessor httpContextAccessor)
|
||||
@ -25,5 +19,4 @@ namespace Devspaces.Support
|
||||
}
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
src/BuildingBlocks/Devspaces.Support/GlobalUsings.cs
Normal file
6
src/BuildingBlocks/Devspaces.Support/GlobalUsings.cs
Normal file
@ -0,0 +1,6 @@
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Net.Http;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Threading;
|
@ -1,13 +1,10 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Devspaces.Support;
|
||||
|
||||
namespace Devspaces.Support
|
||||
public static class HttpClientBuilderDevspacesExtensions
|
||||
{
|
||||
public static class HttpClientBuilderDevspacesExtensions
|
||||
{
|
||||
public static IHttpClientBuilder AddDevspacesSupport(this IHttpClientBuilder builder)
|
||||
{
|
||||
builder.AddHttpMessageHandler<DevspacesMessageHandler>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Devspaces.Support;
|
||||
|
||||
namespace Devspaces.Support
|
||||
public static class ServiceCollectionDevspacesExtensions
|
||||
{
|
||||
public static class ServiceCollectionDevspacesExtensions
|
||||
{
|
||||
public static IServiceCollection AddDevspaces(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<DevspacesMessageHandler>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||
public interface IDynamicIntegrationEventHandler
|
||||
{
|
||||
public interface IDynamicIntegrationEventHandler
|
||||
{
|
||||
Task Handle(dynamic eventData);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||
public interface IEventBus
|
||||
{
|
||||
public interface IEventBus
|
||||
{
|
||||
void Publish(IntegrationEvent @event);
|
||||
|
||||
void Subscribe<T, TH>()
|
||||
@ -19,5 +17,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||
void Unsubscribe<T, TH>()
|
||||
where TH : IIntegrationEventHandler<T>
|
||||
where T : IntegrationEvent;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||
{
|
||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||
where TIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
{
|
||||
Task Handle(TIntegrationEvent @event);
|
||||
}
|
||||
|
||||
public interface IIntegrationEventHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public interface IIntegrationEventHandler
|
||||
{
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
|
||||
public record IntegrationEvent
|
||||
{
|
||||
public record IntegrationEvent
|
||||
{
|
||||
public IntegrationEvent()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
@ -23,5 +20,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
|
||||
|
||||
[JsonInclude]
|
||||
public DateTime CreationDate { get; private init; }
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions
|
||||
public static class GenericTypeExtensions
|
||||
{
|
||||
public static class GenericTypeExtensions
|
||||
{
|
||||
public static string GetGenericTypeName(this Type type)
|
||||
{
|
||||
var typeName = string.Empty;
|
||||
@ -26,5 +23,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions
|
||||
{
|
||||
return @object.GetType().GetGenericTypeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
src/BuildingBlocks/EventBus/EventBus/GlobalUsings.cs
Normal file
8
src/BuildingBlocks/EventBus/EventBus/GlobalUsings.cs
Normal file
@ -0,0 +1,8 @@
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
global using static Microsoft.eShopOnContainers.BuildingBlocks.EventBus.InMemoryEventBusSubscriptionsManager;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Text.Json.Serialization;
|
||||
global using System.Threading.Tasks;
|
||||
global using System;
|
@ -1,13 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Microsoft.eShopOnContainers.BuildingBlocks.EventBus.InMemoryEventBusSubscriptionsManager;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
public interface IEventBusSubscriptionsManager
|
||||
{
|
||||
public interface IEventBusSubscriptionsManager
|
||||
{
|
||||
bool IsEmpty { get; }
|
||||
event EventHandler<string> OnEventRemoved;
|
||||
void AddDynamicSubscription<TH>(string eventName)
|
||||
@ -30,5 +24,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
IEnumerable<SubscriptionInfo> GetHandlersForEvent<T>() where T : IntegrationEvent;
|
||||
IEnumerable<SubscriptionInfo> GetHandlersForEvent(string eventName);
|
||||
string GetEventKey<T>();
|
||||
}
|
||||
}
|
@ -1,13 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
public partial class InMemoryEventBusSubscriptionsManager : IEventBusSubscriptionsManager
|
||||
{
|
||||
public partial class InMemoryEventBusSubscriptionsManager : IEventBusSubscriptionsManager
|
||||
{
|
||||
|
||||
|
||||
private readonly Dictionary<string, List<SubscriptionInfo>> _handlers;
|
||||
@ -21,7 +15,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
_eventTypes = new List<Type>();
|
||||
}
|
||||
|
||||
public bool IsEmpty => !_handlers.Keys.Any();
|
||||
public bool IsEmpty => _handlers is { Count: 0 };
|
||||
public void Clear() => _handlers.Clear();
|
||||
|
||||
public void AddDynamicSubscription<TH>(string eventName)
|
||||
@ -158,5 +152,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
{
|
||||
return typeof(T).Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
using System;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
public partial class InMemoryEventBusSubscriptionsManager : IEventBusSubscriptionsManager
|
||||
{
|
||||
public partial class InMemoryEventBusSubscriptionsManager : IEventBusSubscriptionsManager
|
||||
{
|
||||
public class SubscriptionInfo
|
||||
{
|
||||
public bool IsDynamic { get; }
|
||||
@ -15,14 +13,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
HandlerType = handlerType;
|
||||
}
|
||||
|
||||
public static SubscriptionInfo Dynamic(Type handlerType)
|
||||
{
|
||||
return new SubscriptionInfo(true, handlerType);
|
||||
}
|
||||
public static SubscriptionInfo Typed(Type handlerType)
|
||||
{
|
||||
return new SubscriptionInfo(false, handlerType);
|
||||
}
|
||||
}
|
||||
public static SubscriptionInfo Dynamic(Type handlerType) =>
|
||||
new SubscriptionInfo(true, handlerType);
|
||||
|
||||
public static SubscriptionInfo Typed(Type handlerType) =>
|
||||
new SubscriptionInfo(false, handlerType);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Polly;
|
||||
using Polly.Retry;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using RabbitMQ.Client.Exceptions;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
{
|
||||
public class DefaultRabbitMQPersistentConnection
|
||||
public class DefaultRabbitMQPersistentConnection
|
||||
: IRabbitMQPersistentConnection
|
||||
{
|
||||
{
|
||||
private readonly IConnectionFactory _connectionFactory;
|
||||
private readonly ILogger<DefaultRabbitMQPersistentConnection> _logger;
|
||||
private readonly int _retryCount;
|
||||
@ -54,6 +44,9 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
|
||||
try
|
||||
{
|
||||
_connection.ConnectionShutdown -= OnConnectionShutdown;
|
||||
_connection.CallbackException -= OnCallbackException;
|
||||
_connection.ConnectionBlocked -= OnConnectionBlocked;
|
||||
_connection.Dispose();
|
||||
}
|
||||
catch (IOException ex)
|
||||
@ -127,5 +120,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
|
||||
TryConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,7 @@
|
||||
using Autofac;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Polly;
|
||||
using Polly.Retry;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using RabbitMQ.Client.Exceptions;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
public class EventBusRabbitMQ : IEventBus, IDisposable
|
||||
{
|
||||
public class EventBusRabbitMQ : IEventBus, IDisposable
|
||||
{
|
||||
const string BROKER_NAME = "eshop_event_bus";
|
||||
const string AUTOFAC_SCOPE_NAME = "eshop_event_bus";
|
||||
|
||||
@ -293,5 +276,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
_logger.LogWarning("No subscription for RabbitMQ event: {EventName}", eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
src/BuildingBlocks/EventBus/EventBusRabbitMQ/GlobalUsings.cs
Normal file
17
src/BuildingBlocks/EventBus/EventBusRabbitMQ/GlobalUsings.cs
Normal file
@ -0,0 +1,17 @@
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Polly;
|
||||
global using Polly.Retry;
|
||||
global using RabbitMQ.Client;
|
||||
global using RabbitMQ.Client.Events;
|
||||
global using RabbitMQ.Client.Exceptions;
|
||||
global using System;
|
||||
global using System.IO;
|
||||
global using System.Net.Sockets;
|
||||
global using Autofac;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
|
||||
global using System.Text;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Text.Json;
|
@ -1,15 +1,11 @@
|
||||
using RabbitMQ.Client;
|
||||
using System;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
|
||||
{
|
||||
public interface IRabbitMQPersistentConnection
|
||||
public interface IRabbitMQPersistentConnection
|
||||
: IDisposable
|
||||
{
|
||||
{
|
||||
bool IsConnected { get; }
|
||||
|
||||
bool TryConnect();
|
||||
|
||||
IModel CreateModel();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
using Microsoft.Azure.ServiceBus;
|
||||
using System;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
|
||||
public class DefaultServiceBusPersisterConnection : IServiceBusPersisterConnection
|
||||
{
|
||||
public class DefaultServiceBusPersisterConnection : IServiceBusPersisterConnection
|
||||
{
|
||||
private readonly ServiceBusConnectionStringBuilder _serviceBusConnectionStringBuilder;
|
||||
private readonly string _subscriptionClientName;
|
||||
private SubscriptionClient _subscriptionClient;
|
||||
@ -64,5 +61,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
|
||||
{
|
||||
using Autofac;
|
||||
using Microsoft.Azure.ServiceBus;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||
|
||||
public class EventBusServiceBus : IEventBus
|
||||
{
|
||||
public class EventBusServiceBus : IEventBus
|
||||
{
|
||||
private readonly IServiceBusPersisterConnection _serviceBusPersisterConnection;
|
||||
private readonly ILogger<EventBusServiceBus> _logger;
|
||||
private readonly IEventBusSubscriptionsManager _subsManager;
|
||||
@ -132,15 +121,15 @@
|
||||
var messageData = Encoding.UTF8.GetString(message.Body);
|
||||
|
||||
// Complete the message so that it is not received again.
|
||||
if (await ProcessEvent(eventName, messageData))
|
||||
if (await ProcessEventAsync(eventName, messageData))
|
||||
{
|
||||
await _serviceBusPersisterConnection.SubscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
|
||||
}
|
||||
},
|
||||
new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 10, AutoComplete = false });
|
||||
new MessageHandlerOptions(ExceptionReceivedHandlerAsync) { MaxConcurrentCalls = 10, AutoComplete = false });
|
||||
}
|
||||
|
||||
private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
|
||||
private Task ExceptionReceivedHandlerAsync(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
|
||||
{
|
||||
var ex = exceptionReceivedEventArgs.Exception;
|
||||
var context = exceptionReceivedEventArgs.ExceptionReceivedContext;
|
||||
@ -150,7 +139,7 @@
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task<bool> ProcessEvent(string eventName, string message)
|
||||
private async Task<bool> ProcessEventAsync(string eventName, string message)
|
||||
{
|
||||
var processed = false;
|
||||
if (_subsManager.HasSubscriptionsForEvent(eventName))
|
||||
@ -199,5 +188,4 @@
|
||||
_logger.LogWarning("The messaging entity {DefaultRuleName} Could not be found.", RuleDescription.DefaultRuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
global using static Microsoft.eShopOnContainers.BuildingBlocks.EventBus.InMemoryEventBusSubscriptionsManager;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Text.Json.Serialization;
|
||||
global using System.Threading.Tasks;
|
||||
global using System;
|
||||
global using Microsoft.Azure.ServiceBus;
|
||||
global using Autofac;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using System.Text;
|
||||
global using System.Text.Json;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
|
||||
{
|
||||
using Microsoft.Azure.ServiceBus;
|
||||
using System;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||
|
||||
public interface IServiceBusPersisterConnection : IDisposable
|
||||
{
|
||||
public interface IServiceBusPersisterConnection : IDisposable
|
||||
{
|
||||
ITopicClient TopicClient { get; }
|
||||
ISubscriptionClient SubscriptionClient { get; }
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
|
||||
|
||||
public enum EventStateEnum
|
||||
{
|
||||
public enum EventStateEnum
|
||||
{
|
||||
NotPublished = 0,
|
||||
InProgress = 1,
|
||||
Published = 2,
|
||||
PublishedFailed = 3
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
global using Microsoft.EntityFrameworkCore;
|
||||
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
global using System;
|
||||
global using System.Text.Json;
|
||||
global using System.ComponentModel.DataAnnotations.Schema;
|
||||
global using System.Linq;
|
||||
global using System.Threading.Tasks;
|
||||
global using Microsoft.EntityFrameworkCore.Storage;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Data.Common;
|
||||
global using System.Reflection;
|
@ -1,10 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
||||
public class IntegrationEventLogContext : DbContext
|
||||
{
|
||||
public class IntegrationEventLogContext : DbContext
|
||||
{
|
||||
public IntegrationEventLogContext(DbContextOptions<IntegrationEventLogContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
@ -41,5 +38,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
||||
.IsRequired();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-preview.7.21378.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-preview.7.21378.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.7.21378.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.7.21378.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,13 +1,7 @@
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
||||
public class IntegrationEventLogEntry
|
||||
{
|
||||
public class IntegrationEventLogEntry
|
||||
{
|
||||
private IntegrationEventLogEntry() { }
|
||||
public IntegrationEventLogEntry(IntegrationEvent @event, Guid transactionId)
|
||||
{
|
||||
@ -39,5 +33,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
||||
IntegrationEvent = JsonSerializer.Deserialize(Content, type, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }) as IntegrationEvent;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services
|
||||
public interface IIntegrationEventLogService
|
||||
{
|
||||
public interface IIntegrationEventLogService
|
||||
{
|
||||
Task<IEnumerable<IntegrationEventLogEntry>> RetrieveEventLogsPendingToPublishAsync(Guid transactionId);
|
||||
Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction);
|
||||
Task MarkEventAsPublishedAsync(Guid eventId);
|
||||
Task MarkEventAsInProgressAsync(Guid eventId);
|
||||
Task MarkEventAsFailedAsync(Guid eventId);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,11 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services
|
||||
public class IntegrationEventLogService : IIntegrationEventLogService, IDisposable
|
||||
{
|
||||
public class IntegrationEventLogService : IIntegrationEventLogService, IDisposable
|
||||
{
|
||||
private readonly IntegrationEventLogContext _integrationEventLogContext;
|
||||
private readonly DbConnection _dbConnection;
|
||||
private readonly List<Type> _eventTypes;
|
||||
private volatile bool disposedValue;
|
||||
private volatile bool _disposedValue;
|
||||
|
||||
public IntegrationEventLogService(DbConnection dbConnection)
|
||||
{
|
||||
@ -89,7 +79,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Servi
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
@ -97,7 +87,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Servi
|
||||
}
|
||||
|
||||
|
||||
disposedValue = true;
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,5 +96,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Servi
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Utilities;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Utilities
|
||||
public class ResilientTransaction
|
||||
{
|
||||
public class ResilientTransaction
|
||||
{
|
||||
private DbContext _context;
|
||||
private ResilientTransaction(DbContext context) =>
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
|
||||
public static ResilientTransaction New(DbContext context) =>
|
||||
new ResilientTransaction(context);
|
||||
public static ResilientTransaction New(DbContext context) => new(context);
|
||||
|
||||
public async Task ExecuteAsync(Func<Task> action)
|
||||
{
|
||||
@ -27,5 +22,4 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Utili
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
namespace Basket.API.Infrastructure.Middlewares;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class FailingMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private bool _mustFail;
|
||||
private readonly FailingOptions _options;
|
||||
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FailingMiddleware(RequestDelegate next, Microsoft.Extensions.Logging.ILogger<FailingMiddleware> logger, FailingOptions options)
|
||||
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
|
||||
{
|
||||
_next = next;
|
||||
_options = options;
|
||||
|
@ -1,11 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
namespace Basket.FunctionalTests.Base;
|
||||
|
||||
namespace Basket.FunctionalTests.Base
|
||||
class AutoAuthorizeMiddleware
|
||||
{
|
||||
class AutoAuthorizeMiddleware
|
||||
{
|
||||
public const string IDENTITY_ID = "9e3163b9-1ae6-4652-9dc6-7898ab7b7a00";
|
||||
|
||||
private readonly RequestDelegate _next;
|
||||
@ -27,5 +23,4 @@ namespace Basket.FunctionalTests.Base
|
||||
|
||||
await _next.Invoke(httpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
namespace Basket.FunctionalTests.Base;
|
||||
|
||||
namespace Basket.FunctionalTests.Base
|
||||
public class BasketScenarioBase
|
||||
{
|
||||
public class BasketScenarioBase
|
||||
{
|
||||
private const string ApiUrlBase = "api/v1/basket";
|
||||
|
||||
public TestServer CreateServer()
|
||||
@ -39,5 +33,4 @@ namespace Basket.FunctionalTests.Base
|
||||
public static string Basket = $"{ApiUrlBase}/";
|
||||
public static string CheckoutOrder = $"{ApiUrlBase}/checkout";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
|
||||
namespace Basket.FunctionalTests.Base
|
||||
{
|
||||
|
@ -1,11 +1,7 @@
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
namespace Basket.FunctionalTests.Base;
|
||||
|
||||
namespace Basket.FunctionalTests.Base
|
||||
static class HttpClientExtensions
|
||||
{
|
||||
static class HttpClientExtensions
|
||||
{
|
||||
public static HttpClient CreateIdempotentClient(this TestServer server)
|
||||
{
|
||||
var client = server.CreateClient();
|
||||
@ -14,5 +10,4 @@ namespace Basket.FunctionalTests.Base
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="Moq" Version="4.15.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
|
@ -1,17 +1,8 @@
|
||||
using Basket.FunctionalTests.Base;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
namespace Basket.FunctionalTests;
|
||||
|
||||
namespace Basket.FunctionalTests
|
||||
{
|
||||
public class BasketScenarios
|
||||
public class BasketScenarios
|
||||
: BasketScenarioBase
|
||||
{
|
||||
{
|
||||
[Fact]
|
||||
public async Task Post_basket_and_response_ok_status_code()
|
||||
{
|
||||
@ -91,5 +82,4 @@ namespace Basket.FunctionalTests
|
||||
|
||||
return JsonSerializer.Serialize(checkoutBasket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
src/Services/Basket/Basket.FunctionalTests/GlobalUsings.cs
Normal file
23
src/Services/Basket/Basket.FunctionalTests/GlobalUsings.cs
Normal file
@ -0,0 +1,23 @@
|
||||
global using Basket.FunctionalTests.Base;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.Routing;
|
||||
global using Microsoft.AspNetCore.TestHost;
|
||||
global using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
|
||||
global using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
global using Microsoft.eShopOnContainers.Services.Basket.API;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using StackExchange.Redis;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Net.Http;
|
||||
global using System.Reflection;
|
||||
global using System.Security.Claims;
|
||||
global using System.Text.Json;
|
||||
global using System.Text;
|
||||
global using System.Threading.Tasks;
|
||||
global using System;
|
||||
global using Xunit;
|
@ -1,12 +1,4 @@
|
||||
using Basket.FunctionalTests.Base;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Basket.FunctionalTests
|
||||
{
|
||||
|
@ -1,23 +1,9 @@
|
||||
using Basket.API.IntegrationEvents.Events;
|
||||
using Basket.API.Model;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using IBasketIdentityService = Microsoft.eShopOnContainers.Services.Basket.API.Services.IIdentityService;
|
||||
namespace UnitTest.Basket.Application;
|
||||
|
||||
namespace UnitTest.Basket.Application
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
|
||||
public class BasketWebApiTest
|
||||
{
|
||||
public class BasketWebApiTest
|
||||
{
|
||||
private readonly Mock<IBasketRepository> _basketRepositoryMock;
|
||||
private readonly Mock<IBasketIdentityService> _identityServiceMock;
|
||||
private readonly Mock<IEventBus> _serviceBusMock;
|
||||
@ -151,5 +137,4 @@ namespace UnitTest.Basket.Application
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.WebMVC.Controllers;
|
||||
using Microsoft.eShopOnContainers.WebMVC.Services;
|
||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using BasketModel = Microsoft.eShopOnContainers.WebMVC.ViewModels.Basket;
|
||||
namespace UnitTest.Basket.Application;
|
||||
|
||||
namespace UnitTest.Basket.Application
|
||||
public class CartControllerTest
|
||||
{
|
||||
public class CartControllerTest
|
||||
{
|
||||
private readonly Mock<ICatalogService> _catalogServiceMock;
|
||||
private readonly Mock<IBasketService> _basketServiceMock;
|
||||
private readonly Mock<IIdentityParser<ApplicationUser>> _identityParserMock;
|
||||
@ -126,5 +114,4 @@ namespace UnitTest.Basket.Application
|
||||
Price = 20
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.0" />
|
||||
<PackageReference Include="Moq" Version="4.15.2" />
|
||||
|
19
src/Services/Basket/Basket.UnitTests/GlobalUsings.cs
Normal file
19
src/Services/Basket/Basket.UnitTests/GlobalUsings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
global using Basket.API.IntegrationEvents.Events;
|
||||
global using Basket.API.Model;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
global using Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
|
||||
global using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using Moq;
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Security.Claims;
|
||||
global using System.Threading.Tasks;
|
||||
global using Xunit;
|
||||
global using IBasketIdentityService = Microsoft.eShopOnContainers.Services.Basket.API.Services.IIdentityService;
|
||||
global using Microsoft.eShopOnContainers.WebMVC.Controllers;
|
||||
global using Microsoft.eShopOnContainers.WebMVC.Services;
|
||||
global using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
||||
global using BasketModel = Microsoft.eShopOnContainers.WebMVC.ViewModels.Basket;
|
@ -42,30 +42,37 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="5.0.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />
|
||||
<PackageReference Include="Azure.Identity" Version="1.5.0-beta.3" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="5.1.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="5.0.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="5.0.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="5.0.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="5.0.3" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
|
||||
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.1" />
|
||||
<PackageReference Include="Azure.Identity" Version="1.4.0" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0-preview.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.14.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.34.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.34.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.16.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.3" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.18.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.18.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="2.0.2-beta2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="5.0.2" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.1-dev-00216" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00834" />
|
||||
<PackageReference Include="Serilog.Sinks.Http" Version="7.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.18" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="6.0.0-preview.7.21378.6" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.1-dev-00229" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.1-dev-00787" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0-dev-00291" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1-dev-00876" />
|
||||
<PackageReference Include="Serilog.Sinks.Http" Version="8.0.0-beta.9" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="4.1.0-dev-00166" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.2.1" />
|
||||
<PackageReference Include="System.Data.SqlClient" version="4.8.2"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.0-preview.7.21378.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.7.21378.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.7.21378.4"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user