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.
- Loading branch information
Showing
5 changed files
with
501 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Net.Mime; | ||
using Dfe.Identifiers.Api.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:DefaultConnection"; | ||
private const string connectionString = "Server=localhost,1433;Database=ApiTests;User Id=sa;TrustServerCertificate=True;Password=StrongPassword905"; | ||
private DbContextOptions<MstrContext> _dbContextOptions { get; init; } | ||
|
||
public ApiTestFixture() | ||
{ | ||
_dbContextOptions = new DbContextOptionsBuilder<MstrContext>() | ||
.UseSqlServer(connectionString) | ||
.Options; | ||
using var context = GetMstrContext(); | ||
context.Database.EnsureDeleted(); | ||
context.Database.Migrate(); | ||
} | ||
|
||
public MstrContext GetMstrContext() => new MstrContext(_dbContextOptions); | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
// private static string BuildDatabaseConnectionString(IConfigurationBuilder config) | ||
// { | ||
// var currentConfig = config.Build(); | ||
// var connection = currentConfig[ConnectionStringKey]; | ||
// var sqlBuilder = new SqlConnectionStringBuilder(connection); | ||
// sqlBuilder.InitialCatalog = "ApiTests"; | ||
// | ||
// var result = sqlBuilder.ToString(); | ||
// | ||
// 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,51 @@ | ||
using AutoFixture; | ||
using Dfe.Identifiers.Api.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.CurrentSingleListGrouping = result.CurrentSingleListGrouping.Substring(0, 19); | ||
result.FollowUpLetterSent = result.CurrentSingleListGrouping.Substring(0, 19); | ||
result.PrioritisedForReview = result.PrioritisedForReview.Substring(0, 19); | ||
result.RID = result.RID.Substring(0, 10); | ||
|
||
return result; | ||
} | ||
|
||
public static Establishment BuildEstablishment() | ||
{ | ||
var result = _fixture.Create<Establishment>(); | ||
result.SK = null; | ||
result.IfdPipeline = null; | ||
result.LocalAuthority = null; | ||
result.EstablishmentType = null; | ||
result.PK_GIAS_URN = _fixture.Create<int>().ToString(); | ||
result.EstablishmentTypeId = 228; | ||
result.LocalAuthorityId = 1; | ||
|
||
return result; | ||
} | ||
|
||
public static IfdPipeline BuildIfdPipeline() | ||
{ | ||
var result = _fixture.Create<IfdPipeline>(); | ||
result.SK = null; | ||
result.GeneralDetailsUrn = _fixture.Create<int>().ToString(); | ||
|
||
return result; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
using Dfe.Identifiers.Api.Models; | ||
using FluentAssertions; | ||
using Dfe.Identifiers.Api.Models.Identifiers; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Dfe.Identifiers.Api.Test.Extensions; | ||
|
||
public static class ActionResultExtension | ||
{ | ||
public static Models.Identifiers.Identifiers? GetIdentifiers(this ActionResult<Models.Identifiers.Identifiers> actionResult) | ||
{ | ||
return (Models.Identifiers.Identifiers?)((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.