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: 4 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# Default severity for analyzer diagnostics with category 'Major Code Smell'
dotnet_analyzer_diagnostic.category-Major Code Smell.severity = none
6 changes: 4 additions & 2 deletions src/API/AdventureWorksDemo.API/AdventureWorksDemo.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.53" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
<PackageReference Include="Scalar.AspNetCore" Version="2.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual async Task<IActionResult> DeleteAsync(int id)
[HttpGet()]
[ProducesResponseType<Product>(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public virtual async Task<IActionResult> FindAllAsync([FromQuery] PageingFilter pageingFilter)
public virtual async Task<IActionResult> FindAllAsync([FromBody] PageingFilter pageingFilter)
{
WriteToTraceLog(nameof(GenericControllerBase<TModel>), nameof(FindAllAsync), "pageingFilter");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Default": "Trace",
"Microsoft.AspNetCore": "Warning"
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/API/AdventureWorksDemo.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Paging": {
"MaxRowsPerPage": 100,
"RowsPerPage": 25
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace AdventureWorksDemo.Common.Tests.Extensions
{
public static class IntegerExtentions
{
public static Guid ToGuid(this int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
namespace AdventureWorksDemo.Common.Tests.Extensions
using System.Text;

namespace AdventureWorksDemo.Common.Tests.Extensions
{
public static class StringExtensions
{
private const string DateTimeFormat = "dd MMM yyyy hh:mm:ss";

public static string FullNameReadable(this Type t)
{
var value = t.FullName;
var sb = new StringBuilder();
sb.Append(t.FullName);

if (!value!.Contains('[')) return value;
value = t.FullName!.Split('`')[0] + "<";
if (!sb.ToString()!.Contains('['))
return sb.ToString();
sb.Clear();
sb.Append(t.FullName!.Split('`')[0] + "<");
foreach (var item in t.GenericTypeArguments)
{
value += item.FullName + ", ";
sb.Append(item.FullName + ", ");
}
value = (value + ">").Replace(", >", ">");

return value;
return (sb.ToString() + ">").Replace(", >", ">");
}

public static string InterpretValue(this string value)
Expand All @@ -25,11 +30,11 @@ public static string InterpretValue(this string value)
}

value = value.Replace("{{pipe}}", "|")
.Replace("{{DateTime.Now}}", DateTime.Now.ToString("dd MMM yyyy hh:mm:ss"))
.Replace("{{DateTime.UtcNow}}", DateTime.UtcNow.ToString("dd MMM yyyy hh:mm:ss"))
.Replace("{{DateTime.UTCLastWeek}}", DateTime.UtcNow.AddDays(-7).ToString("dd MMM yyyy hh:mm:ss"))
.Replace("{{DateTime.UTCNextWeek}}", DateTime.UtcNow.AddDays(7).ToString("dd MMM yyyy hh:mm:ss"))
.Replace("{{DateTime.UTCLastWeek}}", DateTime.UtcNow.AddDays(-7).ToString("dd MMM yyyy hh:mm:ss"))
.Replace("{{DateTime.Now}}", DateTime.Now.ToString(DateTimeFormat))
.Replace("{{DateTime.UtcNow}}", DateTime.UtcNow.ToString(DateTimeFormat))
.Replace("{{DateTime.UTCLastWeek}}", DateTime.UtcNow.AddDays(-7).ToString(DateTimeFormat))
.Replace("{{DateTime.UTCNextWeek}}", DateTime.UtcNow.AddDays(7).ToString(DateTimeFormat))
.Replace("{{DateTime.UTCLastWeek}}", DateTime.UtcNow.AddDays(-7).ToString(DateTimeFormat))
.Replace("{{DateTime.Tomorrow}}", DateTime.Today.AddDays(1).ToString("dd MMM yyyy"))
.Replace("{{DateTime.TomorrowResult}}", DateTime.Today.AddDays(1).ToString("M/d/yyyy 12:00:00 AM"))
.Replace("{{CrLf}}", "\r\n");
Expand All @@ -47,6 +52,7 @@ public static string InterpretValue(this string value)
var replacementText = character.PadRight(iterations, Convert.ToChar(character));
value = value.Replace(textToReplace, replacementText);
}

return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

</PropertyGroup>
<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="Polly" Version="8.5.1" />
<PackageReference Include="Reqnroll.MsTest" Version="2.2.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
<PackageReference Include="FluentAssertions" Version="8.0.1" />
<PackageReference Include="Testcontainers.MsSql" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AdventureWorksDemo.Common.Tests.Extensions\AdventureWorksDemo.Common.Tests.Extensions.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DockerMsSqlServerDatabase(string databaseName)
}

public readonly string DatabaseName;
internal Microsoft.Extensions.Configuration.IConfiguration? configuration;
// internal Microsoft.Extensions.Configuration.IConfiguration? configuration;
private const string Image = "mcr.microsoft.com/mssql/server";
private const string Password = "!Passw0rd";
private const string Tag = "latest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<SonarQubeExclude>false</SonarQubeExclude>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.0.0" />
<PackageReference Include="MockQueryable.Moq" Version="7.0.3" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="8.0.1.2" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="MockQueryable.Moq" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="9.0.0.1" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AdventureWorksDemo.Common.Tests\AdventureWorksDemo.Common.Tests.csproj" />
<ProjectReference Include="..\AdventureWorksDemo.Common.Tests.Extensions\AdventureWorksDemo.Common.Tests.Extensions.csproj" />
<ProjectReference Include="..\AdventureWorksDemo.Data\AdventureWorksDemo.Data.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AdventureWorksDemo.Data.Entities;

namespace AdventureWorksDemo.Data.Tests.nUnit.Fakes
{
[ExcludeFromCodeCoverage]
internal static class FakeDbContext
{
[ExcludeFromCodeCoverage]
internal static List<Address> FakeAddresses
{
get
{
return [
new Address()
{
AddressId = 1,
AddressLine1 = "2564 S. Redwood Rd.",
City = "Riverton",
StateProvince = "Utah",
CountryRegion = "United States",
PostalCode = "84065",
Rowguid = new Guid("E299E96D-63CB-4ACC-9BFD-5F0C23AE5820"),
ModifiedDate = Convert.ToDateTime("12 May 2005 01:52:23")
},
new Address()
{
AddressId = 2,
AddressLine1 = "9905 Three Rivers Drive",
City = "Kelso",
StateProvince = "Washington",
CountryRegion = "United States",
PostalCode = "98626",
Rowguid = new Guid("01A85112-6EE1-4F2C-9212-1C2ABC612E67"),
ModifiedDate = Convert.ToDateTime("12 May 2005 01:52:23")
},
new Address()
{
AddressId = 3,
AddressLine1 = "25 First Canadian Place",
City = "Toronto",
StateProvince = "Ontario",
CountryRegion = "Canada",
PostalCode = "M4B 1V5",
Rowguid = new Guid("07A009B2-1421-4597-AB85-22BCE3C82B2C"),
ModifiedDate = Convert.ToDateTime("12 May 2005 01:52:24")
},
new Address()
{
AddressId = 4,
AddressLine1 = "2560 Bay Street",
City = "Toronto",
StateProvince = "Ontario",
CountryRegion = "Canada",
PostalCode = "M4B 1V7",
Rowguid = new Guid("726819A8-1B02-4EFD-AEB9-3FD801D9F153"),
ModifiedDate = Convert.ToDateTime("13 May 2005 01:45:23")
},
new Address()
{
AddressId = 5,
AddressLine1 = "9992 Whipple Rd",
City = "Union City",
StateProvince = "California",
CountryRegion = "United States",
PostalCode = "94587",
Rowguid = new Guid("88258A1B-B50F-440F-93B9-5D7AF831D5FC"),
ModifiedDate = Convert.ToDateTime("14 May 2005 06:52:23")
},
new Address()
{
AddressId = 6,
AddressLine1 = "25915 140th Ave Ne",
City = "Bellevue",
StateProvince = "Washington",
CountryRegion = "United States",
PostalCode = "98004",
Rowguid = new Guid("0D46F203-CDB6-4495-83F5-A97FF0CEC174"),
ModifiedDate = Convert.ToDateTime("28 May 2005 22:52:23")
},
new Address()
{
AddressId = 7,
AddressLine1 = "2574 Milton Park",
City = "Oxford",
StateProvince = "England",
CountryRegion = "United Kingdom",
PostalCode = "OX14 4SE",
Rowguid = new Guid("62D0C689-CF44-4AB3-9C3E-6142F4E0101C"),
ModifiedDate = Convert.ToDateTime("12 June 2005 01:52:23")
}
];
}
}

internal static Address NewAddress1() => new()
{
AddressLine1 = "Ping",
AddressLine2 = "Pong",
City = "Ping Pong",
StateProvince = "Foo",
CountryRegion = "Bar",
PostalCode = "98765",
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Moq;

namespace AdventureWorksDemo.Data.Tests.nUnit.Helpers
namespace AdventureWorksDemo.Data.Tests.nUnit.Fakes
{
internal static class MockedDbContext
{
Expand Down
4 changes: 1 addition & 3 deletions src/API/AdventureWorksDemo.Data.Tests.nUnit/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
global using NUnit.Framework;

global using FluentAssertions;
global using NUnit.Framework;

global using Microsoft.Extensions.Time.Testing;

Expand Down
Loading