Browse Source

Swamy/15jan2021 small refactoring (#1580)

* Small Refactoring inside Basket Service folder

* Small Refactoring
pull/1583/head
Viswanatha Swamy 4 years ago
committed by GitHub
parent
commit
130e46ccdf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 39 additions and 36 deletions
  1. +2
    -2
      src/Services/Basket/Basket.API/Controllers/BasketController.cs
  2. +1
    -1
      src/Services/Basket/Basket.API/Infrastructure/Middlewares/ByPassAuthMiddleware.cs
  3. +4
    -2
      src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs
  4. +1
    -1
      src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingOptions.cs
  5. +1
    -1
      src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs
  6. +1
    -1
      src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs
  7. +1
    -1
      src/Services/Basket/Basket.API/Model/BasketItem.cs
  8. +3
    -2
      src/Services/Basket/Basket.API/Program.cs
  9. +1
    -1
      src/Services/Basket/Basket.API/Services/IdentityService.cs
  10. +17
    -17
      src/Services/Basket/Basket.API/Startup.cs
  11. +3
    -3
      src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs
  12. +1
    -1
      src/Services/Basket/Basket.FunctionalTests/BasketScenarios.cs
  13. +2
    -2
      src/Services/Basket/Basket.FunctionalTests/RedisBasketRepositoryTests.cs
  14. +1
    -1
      src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs

+ 2
- 2
src/Services/Basket/Basket.API/Controllers/BasketController.cs View File

@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
[HttpPost]
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody]CustomerBasket value)
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody] CustomerBasket value)
{
return Ok(await _repository.UpdateBasketAsync(value));
}
@ -55,7 +55,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.Accepted)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<ActionResult> CheckoutAsync([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
public async Task<ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
{
var userId = _identityService.GetUserIdentity();


+ 1
- 1
src/Services/Basket/Basket.API/Infrastructure/Middlewares/ByPassAuthMiddleware.cs View File

@ -62,7 +62,7 @@ namespace Basket.API.Infrastructure.Middlewares
new Claim("name", "Test user"),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "Test user"),
new Claim("nonce", Guid.NewGuid().ToString()),
new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", "ByPassAuthMiddleware"),
new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", "ByPassAuthMiddleware"),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","User"),
new Claim("sub", currentUserId),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","Microsoft")}


+ 4
- 2
src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs View File

@ -12,6 +12,7 @@ namespace Basket.API.Infrastructure.Middlewares
private bool _mustFail;
private readonly FailingOptions _options;
private readonly ILogger _logger;
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
{
_next = next;
@ -19,6 +20,7 @@ namespace Basket.API.Infrastructure.Middlewares
_mustFail = false;
_logger = logger;
}
public async Task Invoke(HttpContext context)
{
var path = context.Request.Path;
@ -44,7 +46,7 @@ namespace Basket.API.Infrastructure.Middlewares
private async Task ProcessConfigRequest(HttpContext context)
{
var enable = context.Request.Query.Keys.Any(k => k == "enable");
var disable = context.Request.Query.Keys.Any(k => k == "disable");
var disable = context.Request.Query.Keys.Any(k => k == "disable");
if (enable && disable)
{
@ -86,7 +88,7 @@ namespace Basket.API.Infrastructure.Middlewares
}
return _mustFail &&
(_options.EndpointPaths.Any(x => x == rpath)
(_options.EndpointPaths.Any(x => x == rpath)
|| _options.EndpointPaths.Count == 0);
}
}


+ 1
- 1
src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingOptions.cs View File

@ -7,6 +7,6 @@ namespace Basket.API.Infrastructure.Middlewares
public string ConfigPath = "/Failing";
public List<string> EndpointPaths { get; set; } = new List<string>();
public List<string> NotFilteredPaths {get; set;} = new List<string>();
public List<string> NotFilteredPaths { get; set; } = new List<string>();
}
}

+ 1
- 1
src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs View File

@ -10,6 +10,6 @@ namespace Basket.API.IntegrationEvents.Events
public string UserId { get; set; }
public OrderStartedIntegrationEvent(string userId)
=> UserId = userId;
=> UserId = userId;
}
}

+ 1
- 1
src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs View File

@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
{
{
public int ProductId { get; private set; }
public decimal NewPrice { get; private set; }


+ 1
- 1
src/Services/Basket/Basket.API/Model/BasketItem.cs View File

@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
if (Quantity < 1)
{
results.Add(new ValidationResult("Invalid number of units", new []{ "Quantity" }));
results.Add(new ValidationResult("Invalid number of units", new[] { "Quantity" }));
}
return results;


+ 3
- 2
src/Services/Basket/Basket.API/Program.cs View File

@ -61,9 +61,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
})
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
.UseFailing(options => {
.UseFailing(options =>
{
options.ConfigPath = "/Failing";
options.NotFilteredPaths.AddRange(new[] {"/hc","/liveness"});
options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" });
})
.UseStartup<Startup>()
.UseContentRoot(Directory.GetCurrentDirectory())


+ 1
- 1
src/Services/Basket/Basket.API/Services/IdentityService.cs View File

@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
{
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
private IHttpContextAccessor _context;
public IdentityService(IHttpContextAccessor context)
{


+ 17
- 17
src/Services/Basket/Basket.API/Startup.cs View File

@ -211,7 +211,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
ConfigureAuth(app);
app.UseStaticFiles();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<BasketService>();
@ -253,22 +253,22 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
private void ConfigureAuthService(IServiceCollection services)
{
// prevent from mapping "sub" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.Audience = "basket";
});
// prevent from mapping "sub" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.Audience = "basket";
});
}
protected virtual void ConfigureAuth(IApplicationBuilder app)


+ 3
- 3
src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs View File

@ -1,9 +1,9 @@
using System;
using Microsoft.AspNetCore.Builder;
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
{
@ -20,7 +20,7 @@ namespace Basket.FunctionalTests.Base
services.Configure<RouteOptions>(Configuration);
return base.ConfigureServices(services);
}
protected override void ConfigureAuth(IApplicationBuilder app)
{
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())


+ 1
- 1
src/Services/Basket/Basket.FunctionalTests/BasketScenarios.cs View File

@ -73,7 +73,7 @@ namespace Basket.FunctionalTests
string BuildCheckout()
{
var checkoutBasket = new
var checkoutBasket = new
{
City = "city",
Street = "street",


+ 2
- 2
src/Services/Basket/Basket.FunctionalTests/RedisBasketRepositoryTests.cs View File

@ -33,7 +33,7 @@ namespace Basket.FunctionalTests
Assert.Single(basket.Items);
}
}
[Fact]
@ -58,7 +58,7 @@ namespace Basket.FunctionalTests
Assert.True(deleteResult);
Assert.Null(result);
}
}
}
RedisBasketRepository BuildBasketRepository(ConnectionMultiplexer connMux)


+ 1
- 1
src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs View File

@ -19,7 +19,7 @@ namespace Catalog.API.Grpc
private readonly CatalogContext _catalogContext;
private readonly CatalogSettings _settings;
private readonly ILogger _logger;
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
{
_settings = settings.Value;


Loading…
Cancel
Save