Skip to content

Commit b48dcff

Browse files
committed
Refactor and update .NET project structure and tests
Updated `solution_architect.mdc` to include support tools, revised file naming conventions, and improved examples. Refactored constructors in `CacheServiceTests` for readability and enhanced test handling with cancellation tokens. Simplified class definitions in `DistributedCacheServiceTests` and `LocalCacheServiceTests`. Upgraded `Infrastructure.Tests.csproj` to target `net9.0`, updated dependencies, and added `xunit.runner.json` for test configuration. Replaced outdated dependencies with modern equivalents to improve maintainability and compatibility.
1 parent b453444 commit b48dcff

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

.cursor/rules/solution_architect.mdc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
description: This rule provides comprehensive best practices for developing dotnet application templates, covering code organization, security, performance, testing, and common pitfalls. It aims to improve code quality, security posture, and overall efficiency when working with the .NET Core framework and application templates.
3-
globs: *.tf,*.bicep,*.json,*.yml,*.yaml,*.cs,*.csproj,*.sln
2+
description: This rule provides comprehensive best practices for developing dotnet application templates, covering code organization, support tools, performance, testing, and common pitfalls. It aims to speed up the development process and improve code quality, security posture, and overall efficiency when working with the .NET Core framework and application templates.
3+
globs: *.tf,*.json,*.yml,*.yaml,*.cs,*.csproj,*.sln
44
alwaysApply: false
55
---
66

77
# .NET Core Application Template Best Practices and Coding Standards
88

9-
This document outlines the recommended best practices for developing application templates using Microsoft .NET Core, Azure DevOps and Azure services. It covers various aspects including solution setup, code organization, security, and tooling to ensure robust, scalable, and secure application templates.
9+
This document outlines the recommended best practices for developing application templates using Microsoft .NET Core, support tools and services. It covers various aspects including solution setup, code organization, security, and tooling to ensure robust, scalable, and secure application templates.
1010

1111
## 1. Code Organization and Structure
1212

@@ -70,14 +70,15 @@ Maintain consistency in file naming to improve readability and searchability.
7070

7171
* Use descriptive names that reflect the file's purpose.
7272
* Use a consistent case (e.g., camelCase or kebab-case).
73-
* Use appropriate file extensions (e.g., `.cs`, `.csproj`, `.tf`, `.bicep`).
73+
* Use appropriate file extensions (e.g., `.cs`, `.csproj`, `.sln`, `.json`, `.yml`, `.yaml`).
7474
* For CSharp components, use `ClassName.cs` or `ComponentName.SubComponent.cs`.
7575

7676
Example:
7777

78-
* `user-service.js` (for a user service module)
79-
* `UserProfile.jsx` (for a user profile component)
80-
* `storage-account.tf` (for a Terraform file defining a storage account)
78+
* `ApplicationService.cs` (for a user service module)
79+
* `UserProfile.cs` (for a user profile class)
80+
* `appsettings.json` (for a JSON file defining application settings)
81+
* `docker-compose.yml` (for a Docker Compose file defining the application stack)
8182

8283
### Module Organization
8384

src/template/src/Infrastructure.Tests/Caching/CacheServiceTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ private record TestRecord(DefaultIdType Id, string StringValue, DateTime DateTim
1313

1414
private readonly ICacheService _sut;
1515

16-
protected CacheServiceTests(ICacheService cacheService) => _sut = cacheService;
16+
protected CacheServiceTests(ICacheService cacheService)
17+
{
18+
_sut = cacheService;
19+
}
1720

1821
[Fact]
1922
public void ThrowsGivenNullKey()
@@ -72,7 +75,7 @@ public async Task ReturnsNullGivenAnExpiredKeyAsync()
7275
string? result = _sut.Get<string>(_testKey);
7376
Assert.Equal(_testValue, result);
7477

75-
await Task.Delay(250);
78+
await Task.Delay(250, TestContext.Current.CancellationToken);
7679
result = _sut.Get<string>(_testKey);
7780

7881
result.Should().BeNull();

src/template/src/Infrastructure.Tests/Caching/DistributedCacheServiceTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,4 @@
22

33
namespace Genocs.Microservice.Template.Infrastructure.Tests.Caching;
44

5-
public class DistributedCacheServiceTests : CacheServiceTests
6-
{
7-
public DistributedCacheServiceTests(DistributedCacheService cacheService)
8-
: base(cacheService)
9-
{
10-
}
11-
}
5+
public class DistributedCacheServiceTests(DistributedCacheService cacheService) : CacheServiceTests(cacheService);

src/template/src/Infrastructure.Tests/Caching/LocalCacheServiceTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,4 @@
22

33
namespace Genocs.Microservice.Template.Infrastructure.Tests.Caching;
44

5-
public class LocalCacheServiceTests : CacheServiceTests
6-
{
7-
public LocalCacheServiceTests(LocalCacheService cacheService)
8-
: base(cacheService)
9-
{
10-
}
11-
}
5+
public class LocalCacheServiceTests(LocalCacheService cacheService) : CacheServiceTests(cacheService);

src/template/src/Infrastructure.Tests/Infrastructure.Tests.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
45
<TargetFramework>net9.0</TargetFramework>
56
<RootNamespace>Genocs.Microservice.Template.Infrastructure.Tests</RootNamespace>
67
<AssemblyName>Genocs.Microservice.Template.Infrastructure.Tests</AssemblyName>
78
<ImplicitUsings>enable</ImplicitUsings>
89
<Nullable>enable</Nullable>
9-
<IsPackable>false</IsPackable>
10+
<OutputType>Exe</OutputType>
11+
1012
</PropertyGroup>
1113

14+
<ItemGroup>
15+
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
16+
</ItemGroup>
17+
1218
<ItemGroup>
1319
<PackageReference Include="FluentAssertions" Version="8.8.0" />
14-
<PackageReference Include="coverlet.collector" Version="6.0.4" />
1520
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
16-
<PackageReference Include="xunit.assert" Version="2.9.3" />
17-
<PackageReference Include="Xunit.DependencyInjection" Version="11.0.0" />
21+
<PackageReference Include="xunit.v3" Version="3.1.0" />
1822
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
23+
<PackageReference Include="Xunit.DependencyInjection" Version="11.0.0" />
1924
</ItemGroup>
2025

26+
2127
<ItemGroup>
2228
<ProjectReference Include="..\..\src\Infrastructure\Infrastructure.csproj" />
2329
</ItemGroup>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
3+
}

0 commit comments

Comments
 (0)