Skip to content

Commit

Permalink
chore: Remove unnecessary using statements and update namespaces in m…
Browse files Browse the repository at this point in the history
…ultiple test and builder files
  • Loading branch information
foxminchan committed Sep 16, 2024
1 parent 12b9dc4 commit f740c70
Show file tree
Hide file tree
Showing 48 changed files with 89 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspireVersion>8.2.0</AspireVersion>
<AspirantVersion>0.0.4</AspirantVersion>
<MicrosoftExtensionsVersion>8.8.0</MicrosoftExtensionsVersion>
<MicrosoftExtensionsVersion>8.9.1</MicrosoftExtensionsVersion>
<AspnetVersion>8.0.8</AspnetVersion>
<EfCoreVersion>8.0.8</EfCoreVersion>
<XabarilVersion>8.0.1</XabarilVersion>
Expand All @@ -27,7 +27,7 @@
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="$(AspireUnstablePackagesVersion)" />
<PackageVersion Include="Aspire.StackExchange.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.StackExchange.Redis.OutputCaching" Version="$(AspireVersion)" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.9.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<!-- Aspirant -->
<PackageVersion Include="Aspirant.Hosting" Version="$(AspirantVersion)" />
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"url": "git+https://github.com/foxminchan/BookWorm"
},
"devDependencies": {
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@types/bun": "latest",
"husky": "^9.1.5"
"husky": "^9.1.6"
},
"peerDependencies": {
"typescript": "^5.5.3"
Expand Down
15 changes: 8 additions & 7 deletions src/BookWorm.Basket/Grpc/BasketService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BookWorm.Basket.Features;
using BookWorm.Basket.Features.Get;
using Google.Protobuf.WellKnownTypes;
using GrpcBasketBase = BookWorm.Basket.Grpc.Basket.BasketBase;

namespace BookWorm.Basket.Grpc;
Expand All @@ -8,21 +9,21 @@ public sealed class BasketService(ISender sender, IBookService bookService, ILog
: GrpcBasketBase
{
[AllowAnonymous]
public override async Task<BasketResponse> GetBasket(BasketRequest request, ServerCallContext context)
public override async Task<BasketResponse> GetBasket(Empty request, ServerCallContext context)
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("[{Service}] - - Begin grpc call {Method} with {BasketId}",
nameof(BasketService), nameof(GetBasket), request.BasketId);
}

var userId = context.GetUserIdentity();

if (string.IsNullOrEmpty(userId))
{
return new();
}

if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("[{Service}] - - Begin grpc call {Method} with {BasketId}",
nameof(BasketService), nameof(GetBasket), userId);
}

var basket = await sender.Send(new GetBasketQuery());

return basket.Value is not null ? await MapToBasketResponse(basket.Value) : new();
Expand Down
8 changes: 3 additions & 5 deletions src/BookWorm.Basket/Protos/basket.proto
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

option csharp_namespace = "BookWorm.Basket.Grpc";

package BasketApi;

service Basket {
rpc GetBasket (BasketRequest) returns (BasketResponse);
}

message BasketRequest {
string basketId = 1;
rpc GetBasket (google.protobuf.Empty) returns (BasketResponse);
}

message BasketResponse {
Expand Down
5 changes: 4 additions & 1 deletion src/BookWorm.Catalog/BookWorm.Catalog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
<ItemGroup>
<PackageReference Include="Polly" />
<PackageReference Include="Polly.Extensions" />
<PackageReference Include="Pgvector.EntityFrameworkCore" />
<PackageReference Include="Grpc.AspNetCore" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Pgvector.EntityFrameworkCore" />
<PackageReference Include="EFCore.NamingConventions" />
<PackageReference Include="EntityFrameworkCore.Exceptions.PostgreSQL" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/BookWorm.Catalog/Infrastructure/Ai/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public static IHostApplicationBuilder AddAi(this IHostApplicationBuilder builder

builder.AddAzureOpenAIClient(ServiceName.OpenAi);
builder.Services.AddOpenAITextEmbeddingGeneration(modelName);

builder.Services.AddSingleton<IAiService, AiService>();

return builder;
Expand Down
4 changes: 4 additions & 0 deletions src/BookWorm.MailDev.Hosting/MailDevResource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace BookWorm.MailDev.Hosting;

/// <summary>
/// https://github.com/davidfowl/Build2024AspireDemo/blob/main/AppHost/MailDev/MailDevResource.cs
/// </summary>
/// <param name="name"></param>
public sealed class MailDevResource(string name) : ContainerResource(name), IResourceWithConnectionString
{
internal const string SmtpEndpointName = "smtp";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace BookWorm.MailDev.Hosting;

/// <summary>
/// https://github.com/davidfowl/Build2024AspireDemo/blob/main/AppHost/MailDev/MailDevResourceBuilderExtensions.cs
/// </summary>
public static class MailDevResourceBuilderExtensions
{
public static IResourceBuilder<MailDevResource> AddMailDev(
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Ordering/Grpc/BasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task<Basket> GetBasketAsync(Guid basketId, CancellationToken cancel
basketId);
}

var response = await basketClient.GetBasketAsync(new() { BasketId = basketId.ToString() },
var response = await basketClient.GetBasketAsync(new(),
cancellationToken: cancellationToken);

return MapBasket(response);
Expand Down
8 changes: 3 additions & 5 deletions src/BookWorm.ServiceDefaults/BookWorm.ServiceDefaults.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
<PackageReference Include="MongoDB.Bson" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" />
<PackageReference Include="MongoDB.Bson" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BookWorm.Shared/BookWorm.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Scrutor" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="FluentValidation.AspNetCore" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Scrutor" />
<PackageReference Include="MassTransit.RabbitMQ" />
<PackageReference Include="FluentValidation.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="ReportGenerator" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="ReportGenerator" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Basket.Domain;
using BookWorm.Basket.Features;
using BookWorm.Basket.Features;
using BookWorm.Basket.Features.Get;
using BasketModel = BookWorm.Basket.Domain.Basket;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Basket.Domain;
using BookWorm.Basket.Features.ReduceItemQuantity;
using BookWorm.Basket.Features.ReduceItemQuantity;
using BasketModel = BookWorm.Basket.Domain.Basket;

namespace BookWorm.Basket.UnitTests.Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Basket.Domain;
using BookWorm.Basket.Features.RemoveItem;
using BookWorm.Basket.Features.RemoveItem;
using BasketModel = BookWorm.Basket.Domain.Basket;

namespace BookWorm.Basket.UnitTests.Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Xunit.Combinatorial" />
Expand All @@ -16,7 +14,9 @@
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="ReportGenerator" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions tests/BookWorm.Basket.UnitTests/Domain/BasketItemTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BookWorm.Basket.Domain;

namespace BookWorm.Basket.UnitTests.Domain;
namespace BookWorm.Basket.UnitTests.Domain;

public class BasketItemTests
{
Expand Down
3 changes: 1 addition & 2 deletions tests/BookWorm.Basket.UnitTests/Domain/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Basket.Domain;
using BasketModel = BookWorm.Basket.Domain.Basket;
using BasketModel = BookWorm.Basket.Domain.Basket;

namespace BookWorm.Basket.UnitTests.Domain;

Expand Down
7 changes: 6 additions & 1 deletion tests/BookWorm.Basket.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
global using Ardalis.GuardClauses;
global using Ardalis.GuardClauses;
global using BookWorm.Basket.Domain;
global using BookWorm.Basket.Grpc;
global using BookWorm.Basket.Infrastructure.Redis;
global using BookWorm.Shared.Identity;
global using Google.Protobuf.WellKnownTypes;
global using Grpc.Core;
global using MediatR;
global using Microsoft.AspNetCore.Http;
global using Microsoft.Extensions.Logging;
10 changes: 2 additions & 8 deletions tests/BookWorm.Basket.UnitTests/Services/BasketServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using BookWorm.Basket.Features;
using BookWorm.Basket.Features.Get;
using BookWorm.Basket.UnitTests.Helpers;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace BookWorm.Basket.UnitTests.Services;

Expand All @@ -25,7 +22,6 @@ public BasketServiceTests()
public async Task GetBasket_ShouldReturnBasketResponse_WhenBasketExists()
{
// Arrange
var basketId = Guid.NewGuid().ToString();
var basket = new BasketDto(Guid.NewGuid(),
[
new(Guid.NewGuid(), "Dummy Book", 10, 15m, 12m)
Expand All @@ -41,7 +37,7 @@ public async Task GetBasket_ShouldReturnBasketResponse_WhenBasketExists()
.Setup(x => x.GetBookAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(book);

var request = new BasketRequest { BasketId = basketId };
var request = new Empty();
var context = TestServerCallContext.Create();
context.SetUserState("__HttpContext", new DefaultHttpContext());

Expand All @@ -56,13 +52,11 @@ public async Task GetBasket_ShouldReturnBasketResponse_WhenBasketExists()
public async Task GetBasket_ShouldReturnEmpty_WhenBasketNotFound()
{
// Arrange
var basketId = Guid.NewGuid().ToString();

_senderMock
.Setup(x => x.Send(It.IsAny<GetBasketQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((BasketDto?)null!);

var request = new BasketRequest { BasketId = basketId };
var request = new Empty();
var context = TestServerCallContext.Create();
context.SetUserState("__HttpContext", new DefaultHttpContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="ReportGenerator" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="ReportGenerator" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Authors.Create;
using BookWorm.Catalog.Features.Authors.Create;

namespace BookWorm.Catalog.UnitTests.Application.Authors;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Authors.Delete;
using BookWorm.Catalog.Features.Authors.Delete;
using BookWorm.Catalog.UnitTests.Builder;

namespace BookWorm.Catalog.UnitTests.Application.Authors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Authors.List;
using BookWorm.Catalog.Features.Authors.List;
using BookWorm.Catalog.UnitTests.Builder;

namespace BookWorm.Catalog.UnitTests.Application.Authors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Categories.Create;
using BookWorm.Catalog.Features.Categories.Create;

namespace BookWorm.Catalog.UnitTests.Application.Categories;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Categories.List;
using BookWorm.Catalog.Features.Categories.List;
using BookWorm.Catalog.UnitTests.Builder;

namespace BookWorm.Catalog.UnitTests.Application.Categories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Publishers.Create;
using BookWorm.Catalog.Features.Publishers.Create;

namespace BookWorm.Catalog.UnitTests.Application.Publishers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BookWorm.Catalog.Domain;
using BookWorm.Catalog.Features.Publishers.List;
using BookWorm.Catalog.Features.Publishers.List;
using BookWorm.Catalog.UnitTests.Builder;

namespace BookWorm.Catalog.UnitTests.Application.Publishers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Xunit.Combinatorial" />
Expand All @@ -16,7 +14,9 @@
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="ReportGenerator" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f740c70

Please sign in to comment.