Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />
<PackageVersion Include="FluentValidation" Version="12.0.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
Expand All @@ -72,7 +72,7 @@
<PackageVersion Include="MassTransit" Version="8.3.4" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.3.4" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Duende.IdentityServer.AspNetIdentity" version="7.2.4" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.11" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Basket.API.Models;
using Marten;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Basket.API.Models;
using Marten;

namespace Basket.API.IntegrationTests.Database.Postgres;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using Basket.API.Models;
using Google.Protobuf;
using Microsoft.Extensions.Caching.Distributed;

Expand Down Expand Up @@ -60,7 +59,7 @@ private static byte[] GetShoppingCartAsByteArray(ShoppingCart basket)
{
Color = x.Color,
Price = x.Price.ToString(CultureInfo.InvariantCulture),
ProduceId = x.ProductId.ToString(),
ProduceId = x.ProductId?.ToString(),
ProductName = x.ProductName,
Quantity = x.Quantity
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace Basket.API.IntegrationTests.Features.CheckoutBasket;
[Collection(GetWebApiContainerFactory.Name)]
public class CheckoutBasketTests : BaseEndpoint
{
private HttpClient _client = default!;
private PostgresDataSeeder _postgresDataSeeder = default!;
private RedisDataSeeder _redisDataSeeder = default!;
private OrderCommandGiven _OrderCommandGiven = default!;
private readonly HttpClient _client;
private readonly PostgresDataSeeder _postgresDataSeeder;
private readonly RedisDataSeeder _redisDataSeeder;
private readonly OrderCommandGiven _orderCommandGiven;

public CheckoutBasketTests(ApiSpecification apiSpecification) : base(apiSpecification)
{
_postgresDataSeeder = _apiSpecification.PostgresDataSeeder;
_redisDataSeeder = _apiSpecification.RedisDataSeeder;
_client = _apiSpecification.HttpClient;
_OrderCommandGiven = _apiSpecification.CreateOrderCommandServerGiven();
_orderCommandGiven = _apiSpecification.CreateOrderCommandServerGiven();
}

[Theory]
Expand Down Expand Up @@ -383,7 +383,7 @@ public async Task CheckoutBasket_when_order_command_returns_un_authorized_should
await _postgresDataSeeder.SeedDatabaseAsync(shoppingCart, timeout);
await _redisDataSeeder.AddShoppingCartAsync(shoppingCart, timeout);

_OrderCommandGiven.ReturningUnauthorized();
_orderCommandGiven.ReturningUnauthorized();

// Act
var response = await CallSutAsync(request, timeout);
Expand Down Expand Up @@ -416,7 +416,7 @@ public async Task CheckoutBasket_when_order_command_returns_forbidden_should_ret
await _postgresDataSeeder.SeedDatabaseAsync(shoppingCart, timeout);
await _redisDataSeeder.AddShoppingCartAsync(shoppingCart, timeout);

_OrderCommandGiven.ReturningForbidden();
_orderCommandGiven.ReturningForbidden();

// Act
var response = await CallSutAsync(request, timeout);
Expand Down Expand Up @@ -450,7 +450,7 @@ public async Task CheckoutBasket_when_order_command_returns_internal_server_erro
await _postgresDataSeeder.SeedDatabaseAsync(shoppingCart, timeout);
await _redisDataSeeder.AddShoppingCartAsync(shoppingCart, timeout);

_OrderCommandGiven.ReturningInternalServerError();
_orderCommandGiven.ReturningInternalServerError();

// Act
var response = await CallSutAsync(request, timeout);
Expand Down Expand Up @@ -484,7 +484,7 @@ public async Task CheckoutBasket_when_order_command_returns_bad_request_should_r
await _postgresDataSeeder.SeedDatabaseAsync(shoppingCart, timeout);
await _redisDataSeeder.AddShoppingCartAsync(shoppingCart, timeout);

_OrderCommandGiven.ReturningBadRequest(new ValidationErrors(
_orderCommandGiven.ReturningBadRequest(new ValidationErrors(
[
new ValidationError("order_id", "invalid order id")
]));
Expand Down Expand Up @@ -527,7 +527,7 @@ public async Task CheckoutBasket_when_valid_request_should_return_ok_with_order_

await _postgresDataSeeder.SeedDatabaseAsync(shoppingCart, timeout);
await _redisDataSeeder.AddShoppingCartAsync(shoppingCart, timeout);
_OrderCommandGiven.ACreateOrderSuccessResponse(customerId, orderId);
_orderCommandGiven.ACreateOrderSuccessResponse(customerId, orderId);

// Act
var response = await _client
Expand All @@ -541,7 +541,7 @@ public async Task CheckoutBasket_when_valid_request_should_return_ok_with_order_
// Assert
response.StatusCode.ShouldBe(HttpStatusCode.OK);
result.ShouldNotBeNull();
result!.OrderId.ShouldBe(orderId);
result.OrderId.ShouldBe(orderId);
}

private async Task<HttpResponseMessage> CallSutAsync(CheckoutBasketRequest request, CancellationToken timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Basket.API.IntegrationTests.Features.DeleteBasket;
[Collection(GetWebApiContainerFactory.Name)]
public class DeleteBasketTests : BaseEndpoint
{
private HttpClient _client = default!;
private PostgresDataSeeder _postgresDataSeeder = default!;
private RedisDataSeeder _redisDataSeeder = default!;
private HttpClient _client;
private PostgresDataSeeder _postgresDataSeeder;
private RedisDataSeeder _redisDataSeeder;

public DeleteBasketTests(ApiSpecification apiSpecification) : base(apiSpecification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Basket.API.IntegrationTests.Features.GetBasket;
[Collection(GetWebApiContainerFactory.Name)]
public class GetBasketTests : BaseEndpoint
{
private HttpClient _client = default!;
private PostgresDataSeeder _postgresDataSeeder = default!;
private RedisDataSeeder _redisDataSeeder = default!;
private HttpClient _client;
private PostgresDataSeeder _postgresDataSeeder;
private RedisDataSeeder _redisDataSeeder;

public GetBasketTests(ApiSpecification apiSpecification) : base(apiSpecification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace Basket.API.IntegrationTests.Features.StoreBasket;
[Collection(GetWebApiContainerFactory.Name)]
public class StoreBasketTests : BaseEndpoint
{
private HttpClient _client = default!;
private DiscountGiven _discountGiven = default!;
private PostgresDataSeeder _postgresDataSeeder = default!;
private RedisDataSeeder _redisDataSeeder = default!;
private HttpClient _client;
private DiscountGiven _discountGiven;
private PostgresDataSeeder _postgresDataSeeder;
private RedisDataSeeder _redisDataSeeder;

public StoreBasketTests(ApiSpecification apiSpecification) : base(apiSpecification)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ public async Task StoreBasket_Valid_Request_Saves_Data_In_PostgresDb_And_Redis(S
var resultInPostgresDb =
await _postgresDataSeeder.GetBasketAsync(request.ShoppingCart!.Username, token);
resultInPostgresDb.ShouldNotBeNull();
response.ShoppingCart.Username.ShouldBe(resultInPostgresDb!.Username);
response.ShoppingCart.Username.ShouldBe(resultInPostgresDb.Username);
JsonConvert.SerializeObject(response.ShoppingCart.Items)
.ShouldBe(JsonConvert.SerializeObject(resultInPostgresDb.Items));

Expand Down Expand Up @@ -209,7 +209,7 @@ public async Task StoreBasket_Valid_Request_Saves_Data_With_Valid_TotalPrice(Sto
var resultInPostgresDb =
await _postgresDataSeeder.GetBasketAsync(validRequest.ShoppingCart!.Username, token);
resultInPostgresDb.ShouldNotBeNull();
response.ShoppingCart.Username.ShouldBe(resultInPostgresDb!.Username);
response.ShoppingCart.Username.ShouldBe(resultInPostgresDb.Username);
JsonConvert.SerializeObject(response.ShoppingCart.Items)
.ShouldBe(JsonConvert.SerializeObject(resultInPostgresDb.Items));
resultInPostgresDb.TotalPrice.ShouldBe(180);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Basket.API.ApiClient.AccessToken;
using eshop.Shared;
using eshop.Shared.Configurations;
using Refit;

namespace Basket.API.ApiClient.OrderCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Basket.API.ApiClient;
namespace Basket.API.ApiClient.OrderCommand;

public record CreateOrderRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using eshop.Shared;
using eshop.Shared.Configurations;
using eshop.Shared.HealthChecks;

namespace Basket.API.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static byte[] GetShoppingCartAsByteArray(ShoppingCart basket)
{
Color = x.Color,
Price = x.Price.ToString(CultureInfo.InvariantCulture),
ProduceId = x.ProductId.ToString(),
ProduceId = x.ProductId?.ToString(),
ProductName = x.ProductName,
Quantity = x.Quantity
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static async Task<IResult> CheckoutBasketAsync(
var isAuthorized =
await authorizationService.CanCheckoutBasketAsync(httpContext, request.Username ?? string.Empty);

var userId = httpContext.User?.FindFirstValue(ClaimTypes.NameIdentifier);
var userId = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

if (!isAuthorized)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static CreteOrderCommandParameters MapParameter(
BillingAddress = MapAddress(checkoutRequestModel.BillingAddress!),
Payment = MapPayment(checkoutRequestModel.Payment!),
OrderItems = shoppingCart.Items.Select(x => new CreteOrderCommandParameters.ModuleOrderItem(
x.ProductId, x.Quantity, x.Price)).ToList()
x.ProductId!, x.Quantity, x.Price)).ToList()
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Basket.API.Features.CheckoutBasket.Commands.CreateOrder;

public record CreteOrderCommandParameters
{
public string OrderId { get; set; }
public string CustomerId { get; set; }
public string? OrderId { get; set; }
public string? CustomerId { get; set; }
public string? OrderName { get; set; }
public ModuleAddress? ShippingAddress { get; set; }
public ModuleAddress? BillingAddress { get; set; }
Expand Down Expand Up @@ -57,8 +57,8 @@ public async Task<CreateOrderCommandResult> CreateOrderAsync(
try
{
var response = await client.CreateOrder(
parameters.CustomerId,
parameters.OrderId,
parameters.CustomerId!,
parameters.OrderId!,
body,
cancellationToken);

Expand All @@ -74,7 +74,7 @@ public async Task<CreateOrderCommandResult> CreateOrderAsync(
case StatusCodes.Status400BadRequest:
{
var errorContent = await e.GetContentAsAsync<ValidationErrors>();
var errors = errorContent?.Errors?
var errors = errorContent?.Errors
.Select(x => new Error(x.PropertyName, x.Reason))
.ToArray() ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ private static GetBasketResponse Map(ShoppingCart result)

private static List<BasketItem> MapItems(List<ShoppingCartItem> items)
{
return items.Select(x => new BasketItem(x.Quantity, x.Color, x.Price, x.ProductId, x.ProductName)).ToList();
return items.Select(x => new BasketItem(x.Quantity, x.Color, x.Price, x.ProductId!, x.ProductName)).ToList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static StoreBasketResult MapToResult(ShoppingCart shoppingCart)
x.Quantity,
x.Color,
x.Price,
x.ProductId,
x.ProductId!,
x.ProductName)).ToList(),
shoppingCart.TotalPrice));
}
Expand Down
1 change: 0 additions & 1 deletion src/Services/Basket/Basket.API/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
global using Basket.API.Models;
global using Basket.API.Models.Dtos;
global using Basket.API.Exceptions;
global using Marten;
global using Basket.API.Data;
global using System.Text.Json.Serialization;
Expand Down
6 changes: 3 additions & 3 deletions src/Services/Basket/Basket.API/Models/ShoppingCartItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Basket.API.Models;
public class ShoppingCartItem
{
public int Quantity { get; set; }
public string Color { get; set; } = default!;
public string Color { get; set; } = null!;
public decimal Price { get; set; }
public string ProductId { get; set; }
public string ProductName { get; set; } = default!;
public string? ProductId { get; set; }
public string ProductName { get; set; } = null!;
}
32 changes: 5 additions & 27 deletions src/Services/Basket/Basket.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using eshop.Shared.Middlewares;
using eshop.Shared.OpenTelemetry;
using Microsoft.AspNetCore.Authorization;
using eshop.Shared.Configurations;

var builder = WebApplication.CreateBuilder(args);
builder.Services.RegisterMediateR(typeof(Program).Assembly);
Expand All @@ -20,33 +21,10 @@
const string serviceName = "eshop.basket.api";
builder.Services.AddOpenTelemetryOtl(serviceName);

builder.Services
.AddOptions<DatabaseConfigurations>()
.Bind(builder.Configuration)
.ValidateDataAnnotationsRecursively()
.ValidateOnStart();

builder.Services
.AddOptions<DiscountGrpcConfigurations>()
.Bind(builder.Configuration)
.ValidateDataAnnotationsRecursively()
.ValidateOnStart();

builder.Services
.AddOptions<LoggerConfigurations>()
.Bind(builder.Configuration)
.ValidateDataAnnotationsRecursively()
.ValidateOnStart();

builder.Services
.AddOptions<OrderCommandClientConfigurations>()
.Bind(builder.Configuration)
.ValidateDataAnnotationsRecursively()
.ValidateOnStart();

var discountGrpcConfiguration = builder.Configuration.TryGetValidatedOptions<DiscountGrpcConfigurations>();
var databaseConfigurations = builder.Configuration.TryGetValidatedOptions<DatabaseConfigurations>();
var loggerConfigurations = builder.Configuration.TryGetValidatedOptions<LoggerConfigurations>();
builder.Services.TrySetConfiguration<DiscountGrpcConfigurations>(builder.Configuration, out var discountGrpcConfiguration);
builder.Services.TrySetConfiguration<DatabaseConfigurations>(builder.Configuration, out var databaseConfigurations);
builder.Services.TrySetConfiguration<LoggerConfigurations>(builder.Configuration, out var loggerConfigurations);
builder.Services.TrySetConfiguration<OrderCommandClientConfigurations>(builder.Configuration, out _);

builder.SetupLogging("Basket Service", environment, loggerConfigurations.ElasticSearch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Catalog.API.IntegrationTests.Database;

public record ProductConfiguration
{
public string Id { get; set; }
public string? Id { get; set; }
public string Name { get; set; } = null!;
public List<string> Category { get; set; } = [];
public string? Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task CreateProduct_Zero_Price_Will_Return_BadRequest(CreateProductR
var response = await result.Content.ReadFromJsonAsync<ProblemDetails>();

// Assert
result.StatusCode.ShouldBe(System.Net.HttpStatusCode.BadRequest);
result.StatusCode.ShouldBe(HttpStatusCode.BadRequest);
response.ShouldNotBeNull();
response.Detail.ShouldNotBeNull();
response.Detail.ShouldContain("Price must be greater than 0");
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task CreateProduct_With_Valid_Object_Return_Created(CreateProductRe
public async Task CreateProduct_With_Invalid_Id_Return_NotFound(CreateProductRequest createProductRequest)
{
// Arrange
createProductRequest = createProductRequest with { Id = default };
createProductRequest = createProductRequest with { Id = null! };

// Act
var result = await _client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ await _dataSeeder.SeedDataBaseAsync(x =>
var response = await result.Content.ReadFromJsonAsync<GetProductByIdResponse>();

// Assert
result.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
result.StatusCode.ShouldBe(HttpStatusCode.OK);
response.ShouldNotBeNull();
response.Id.ShouldBe(Ulid.Parse(productId));
response.Name.ShouldBe("IPhone X");
Expand Down
Loading
Loading