Skip to content

Commit

Permalink
initial set-up for stylecop
Browse files Browse the repository at this point in the history
  • Loading branch information
DustSwiffer committed Jul 18, 2024
1 parent 3f4b767 commit 02807b4
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 51 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[*.cs]


# SA1404: Code analysis suppression should have justification
dotnet_diagnostic.SA1404.severity = none

# SA1633: File header
dotnet_diagnostic.SA1633.severity = none

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none

# SA1611: Element parameters should be documented
dotnet_diagnostic.SA1611.severity = none

# SA1309: starting underscore
dotnet_diagnostic.SA1309.severity = none

dotnet_diagnostic.SA1615.severity = none

dotnet_diagnostic.SA1642.severity = none

dotnet_diagnostic.SA1623.severity = none
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ $RECYCLE.BIN/

_NCrunch*
*.idea*
.vs
14 changes: 12 additions & 2 deletions AdvancedAPI.Business/AdvancedAPI.Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Business-63FD5173-E1FF-446F-A3C3-0D5E7DA4C0FF</UserSecretsId>
<RootNamespace>Business</RootNamespace>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AdvancedAPI.Data\AdvancedAPI.Data.csproj" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
</Project>

2 changes: 1 addition & 1 deletion AdvancedAPI.Business/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.ConfigureServices(services => { services.AddHostedService<Worker>(); })
.Build();

await host.RunAsync();
await host.RunAsync();
6 changes: 3 additions & 3 deletions AdvancedAPI.Business/Services/HouseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Business.Services;

/// <inheritdoc />
public class HouseService: IHouseService
public class HouseService : IHouseService
{

private readonly IHouseRepository _houseRepository;

/// <summary>
/// Constructor.
/// </summary>
Expand All @@ -30,4 +30,4 @@ public HouseService(IHouseRepository houseRepository)

return new List<HouseResponseModel>();
}
}
}
4 changes: 2 additions & 2 deletions AdvancedAPI.Business/Services/Interfaces/IHouseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Business.Services.Interfaces;
public interface IHouseService
{
/// <summary>
/// Obtaining List of all houses
/// Obtaining List of all houses.
/// </summary>
public Task<List<HouseResponseModel>?> GetAllHouses(CancellationToken ct = default);
}
}
11 changes: 10 additions & 1 deletion AdvancedAPI.Business/Worker.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
namespace Business;

/// <summary>
/// Default.
/// </summary>
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;

/// <summary>
/// Default.
/// </summary>
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}

/// <summary>
/// Default.
/// </summary>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
Expand All @@ -17,4 +26,4 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await Task.Delay(1000, stoppingToken);
}
}
}
}
11 changes: 10 additions & 1 deletion AdvancedAPI.Data/AdvancedAPI.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-AdvancedAPI.Data-FC4EB265-FB30-4113-B83E-B67571392567</UserSecretsId>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions AdvancedAPI.Data/Models/House.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AdvancedAPI.Data.Models;

/// <summary>
/// Model of house.
/// </summary>
public class House
{

}
}
2 changes: 1 addition & 1 deletion AdvancedAPI.Data/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.ConfigureServices(services => { services.AddHostedService<Worker>(); })
.Build();

await host.RunAsync();
await host.RunAsync();
6 changes: 3 additions & 3 deletions AdvancedAPI.Data/Repositories/HouseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace AdvancedAPI.Data.Repositories;

/// <inheritdoc />
public class HouseRepository: IHouseRepository
/// <inheritdoc />
public class HouseRepository : IHouseRepository
{
/// <inheritdoc />
public Task<List<House>> GetAllHouses()
{
throw new NotImplementedException();
}
}
}
3 changes: 1 addition & 2 deletions AdvancedAPI.Data/Repositories/Interfaces/IHouseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public interface IHouseRepository
/// <summary>
/// obtaining a List of <see cref="House"/>.
/// </summary>
/// <returns></returns>
public Task<List<House>> GetAllHouses();
}
}
17 changes: 13 additions & 4 deletions AdvancedAPI.Data/ViewModels/ErrorResponseModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
namespace AdvancedAPI.Models;
namespace AdvancedAPI.Data.ViewModels;

/// <summary>
/// Error response model. Will be sent to the requester.
/// </summary>
public class ErrorResponseModel
{
public string? RequestId { get; set; }
/// <summary>
/// Status code of the error.
/// </summary>
public int Code { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
/// <summary>
/// Message of the error.
/// </summary>
public string Message { get; set; } = string.Empty;
}
6 changes: 3 additions & 3 deletions AdvancedAPI.Data/ViewModels/Houses/HouseResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class HouseResponseModel
/// <summary>
/// Name of the street where the house is located.
/// </summary>
[JsonProperty("street Name")]
public string StreetName { get; set; } = String.Empty;
}
[JsonProperty("street Name")]
public string StreetName { get; set; } = string.Empty;
}
11 changes: 10 additions & 1 deletion AdvancedAPI.Data/Worker.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
namespace AdvancedAPI.Data;

/// <summary>
/// Default.
/// </summary>
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;

/// <summary>
/// Default.
/// </summary>
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}

/// <summary>
/// Default.
/// </summary>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
Expand All @@ -17,4 +26,4 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await Task.Delay(1000, stoppingToken);
}
}
}
}
11 changes: 9 additions & 2 deletions AdvancedAPI.Tests/AdvancedAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<RootNamespace>Tests</RootNamespace>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,6 +15,10 @@
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -35,4 +38,8 @@
<Folder Include="Repositories\" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

</Project>
14 changes: 8 additions & 6 deletions AdvancedAPI.Tests/Services/HouseServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class HouseServiceTests
{
private readonly IHouseService _houseService;
private readonly Mock<IHouseRepository> _houseRepository;

/// <summary>
/// Constructor.
/// </summary>
Expand All @@ -32,18 +33,19 @@ public HouseServiceTests()
public async Task GetAllHousesReturnsNull()
{
_houseRepository.Setup(x => x.GetAllHouses()).ReturnsAsync(new List<House>());
var result = await _houseService.GetAllHouses();
Assert.Equal(null, result);
List<HouseResponseModel>? result = await _houseService.GetAllHouses();

Assert.Null(result);
}

/// <summary>
/// Tests if <see cref="HouseService.GetAllHouses"/> returns a valid list.
/// </summary>
[Fact]
public async Task GetAllHousesReturnsList()
{
_houseRepository.Setup(x => x.GetAllHouses()).ReturnsAsync(new List<House>{new()});
var result = await _houseService.GetAllHouses();
_houseRepository.Setup(x => x.GetAllHouses()).ReturnsAsync(new List<House> { new() });
List<HouseResponseModel>? result = await _houseService.GetAllHouses();
Assert.Equal(new List<HouseResponseModel>(), result);
}
}
}
2 changes: 1 addition & 1 deletion AdvancedAPI.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using Xunit;
global using Xunit;
19 changes: 15 additions & 4 deletions AdvancedAPI.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedAPI", "AdvancedAPI\AdvancedAPI.csproj", "{C8B1A7A2-655B-4CC4-83B8-317E47737D64}"
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdvancedAPI", "AdvancedAPI\AdvancedAPI.csproj", "{C8B1A7A2-655B-4CC4-83B8-317E47737D64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedAPI.Tests", "AdvancedAPI.Tests\AdvancedAPI.Tests.csproj", "{68B1C0FF-763F-49DC-B214-1EA6687BC8BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdvancedAPI.Tests", "AdvancedAPI.Tests\AdvancedAPI.Tests.csproj", "{68B1C0FF-763F-49DC-B214-1EA6687BC8BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedAPI.Business", "AdvancedAPI.Business\AdvancedAPI.Business.csproj", "{5B50610A-4319-4A94-B572-C206F2D4854C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdvancedAPI.Business", "AdvancedAPI.Business\AdvancedAPI.Business.csproj", "{5B50610A-4319-4A94-B572-C206F2D4854C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedAPI.Data", "AdvancedAPI.Data\AdvancedAPI.Data.csproj", "{00677115-7649-43C1-BDA6-27F403170575}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdvancedAPI.Data", "AdvancedAPI.Data\AdvancedAPI.Data.csproj", "{00677115-7649-43C1-BDA6-27F403170575}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{086D46AA-3EB5-4C94-980B-F9DDCE428E3F}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -31,4 +39,7 @@ Global
{00677115-7649-43C1-BDA6-27F403170575}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00677115-7649-43C1-BDA6-27F403170575}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions AdvancedAPI/AdvancedAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AdvancedAPI.Business\AdvancedAPI.Business.csproj" />
<ProjectReference Include="..\AdvancedAPI.Data\AdvancedAPI.Data.csproj" />
</ItemGroup>
<ItemGroup>
<Content Remove="stylecop.json" />
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

</Project>
Loading

0 comments on commit 02807b4

Please sign in to comment.