This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-sonarcloud' of https://github.com/DFE-Digital/ident…
…ifiers-api into add-sonarcloud
- Loading branch information
Showing
63 changed files
with
3,896 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Net.Mime; | ||
using Dfe.Identifiers.Infrastructure.Context; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Dfe.Identifiers.Api.Test | ||
{ | ||
public class ApiTestFixture : IDisposable | ||
{ | ||
private const string connectionStringKey = "ConnectionStrings:Default"; | ||
private DbContextOptions<MstrContext> _dbContextOptions { get; init; } | ||
|
||
public ApiTestFixture() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.AddUserSecrets<ApiTestFixture>(); | ||
|
||
Configuration = builder.Build(); | ||
_dbContextOptions = new DbContextOptionsBuilder<MstrContext>() | ||
.UseSqlServer(Configuration[connectionStringKey]) | ||
.Options; | ||
using var context = GetMstrContext(); | ||
context.Database.EnsureDeleted(); | ||
context.Database.Migrate(); | ||
} | ||
|
||
private IConfigurationRoot Configuration { get; init; } | ||
|
||
public MstrContext GetMstrContext() => new(_dbContextOptions); | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using AutoFixture; | ||
using Dfe.Identifiers.Domain.Models; | ||
|
||
namespace Dfe.Identifiers.Api.Test | ||
{ | ||
public static class DatabaseModelBuilder | ||
{ | ||
private static readonly Fixture _fixture = new Fixture(); | ||
|
||
public static Trust BuildTrust() | ||
{ | ||
var result = _fixture.Create<Trust>(); | ||
result.SK = null; | ||
result.TrustStatus = "Open"; | ||
result.TrustTypeId = 30; | ||
result.TrustType = null; | ||
result.TrustStatusId = null; | ||
result.RegionId = null; | ||
result.TrustBandingId = null; | ||
result.RID = result.RID.Substring(0, 10); | ||
|
||
return result; | ||
} | ||
|
||
public static Establishment BuildEstablishment() | ||
{ | ||
var result = _fixture.Create<Establishment>(); | ||
result.SK = null; | ||
result.LocalAuthority = null; | ||
result.EstablishmentType = null; | ||
result.PK_GIAS_URN = _fixture.Create<int>().ToString(); | ||
// Only 224 or 228 are valid in this subset of test data used (see mstr context) | ||
result.EstablishmentTypeId = 224; | ||
result.LocalAuthorityId = 1; | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<UserSecretsId>29f2c83e-d293-4cdb-b0bf-7ec5ed71bee5</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoFixture" Version="4.18.1" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Dfe.Identifiers.Api\Dfe.Identifiers.Api.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Update="appsettings.test.json"> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
16 changes: 16 additions & 0 deletions
16
Dfe.Identifiers.Api.Test/Extensions/ActionResultExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Dfe.Identifiers.Api.Test.Extensions; | ||
|
||
public static class ActionResultExtension | ||
{ | ||
public static Domain.Identifiers.IdentifiersCollection? GetIdentifiers(this ActionResult<Domain.Identifiers.IdentifiersCollection> actionResult) | ||
{ | ||
return (Domain.Identifiers.IdentifiersCollection?)((OkObjectResult?)actionResult.Result)?.Value; | ||
} | ||
|
||
public static int? GetStatusCode<T>(this ActionResult<T> actionResult) | ||
{ | ||
return ((ObjectResult?)actionResult.Result)?.StatusCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
Oops, something went wrong.