Skip to content

Commit

Permalink
wip cleanup (#498)
Browse files Browse the repository at this point in the history
* wip cleanup

* cleanup

* cleanup

* test for assertion
  • Loading branch information
Iain-Stanger authored Feb 8, 2024
1 parent 6dce184 commit e32d7a0
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Runtime.Serialization;

namespace Dfe.PlanTech.Infrastructure.Contentful.Helpers;
namespace Dfe.PlanTech.Infrastructure.Contentful.Helpers;

[Serializable]
public class GetEntitiesException(string? message) : Exception(message), ISerializable
public class GetEntitiesException(string? message) : Exception(message)

Check warning on line 4 in src/Dfe.PlanTech.Infrastructure.Contentful/Helpers/GetEntitiesException.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern. Add a 'protected' constructor 'GetEntitiesException(SerializationInfo, StreamingContext)'. (https://rules.sonarsource.com/csharp/RSPEC-3925)
{
}
4 changes: 2 additions & 2 deletions src/Dfe.PlanTech.Web/Helpers/RouteDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public static class RouteDataExtensions
// DefaultPageTitle.
public static string GetTitleForPage(this RouteData routeData)
{
var sectionSlug = routeData.Values.OrderByDescending(routePart => routePart.Key)
.Where(routePart =>
var sectionSlug = routeData.Values.Where(routePart =>
{
if (routePart.Key == SectionSlugKey)
{
Expand All @@ -25,6 +24,7 @@ public static string GetTitleForPage(this RouteData routeData)

return !string.IsNullOrEmpty(routePartValue) && routePartValue != "/" && !routePartValue.Any(char.IsNumber);
})
.OrderByDescending(routePart => routePart.Key)
.Select(routePart => routePart.Value!.ToString())
.FirstOrDefault();

Expand Down
2 changes: 1 addition & 1 deletion src/Dfe.PlanTech.Web/ProgramExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static IServiceCollection AddCaching(this IServiceCollection services)

public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
var serviceProvider = services.BuildServiceProvider();
IServiceProvider serviceProvider = services.BuildServiceProvider();

void databaseOptionsAction(DbContextOptionsBuilder options) => options.UseSqlServer(configuration.GetConnectionString("Database"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GetButtonWithEntryReferencesQueryTests
private readonly ICmsDbContext _db = Substitute.For<ICmsDbContext>();
private readonly ILogger<GetButtonWithEntryReferencesQuery> _logger = Substitute.For<ILogger<GetButtonWithEntryReferencesQuery>>();

private readonly IGetPageChildrenQuery _getButtonWithEntryReferencesQuery;
private readonly GetButtonWithEntryReferencesQuery _getButtonWithEntryReferencesQuery;

private readonly static PageDbEntity _pageWithButton = new()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dfe.PlanTech.Application.Content.Queries;
using Dfe.PlanTech.Application.Persistence.Interfaces;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models;
using Dfe.PlanTech.Domain.Questionnaire.Enums;
using Dfe.PlanTech.Domain.Questionnaire.Models;
Expand All @@ -14,7 +13,7 @@ public class GetCategorySectionsQueryTests
private readonly ICmsDbContext _db = Substitute.For<ICmsDbContext>();
private readonly ILogger<GetCategorySectionsQuery> _logger = Substitute.For<ILogger<GetCategorySectionsQuery>>();

private readonly IGetPageChildrenQuery _getCategorySectionsQuery;
private readonly GetCategorySectionsQuery _getCategorySectionsQuery;

private readonly static PageDbEntity _loadedPage = new()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dfe.PlanTech.Application.Content.Queries;
using Dfe.PlanTech.Application.Persistence.Interfaces;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models;
using Microsoft.Extensions.Logging;
using NSubstitute;
Expand Down Expand Up @@ -45,7 +44,7 @@ public async Task Should_Retrieve_Nav_Links_From_Database()
return queryable.ToList();
});

IGetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);
GetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);

var result = await navQuery.GetNavigationLinks();

Expand All @@ -66,7 +65,7 @@ public async Task Should_Retrieve_Nav_Links_From_Contentful_When_No_Db_Results()
return queryable.ToList();
});

IGetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);
GetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);

var result = await navQuery.GetNavigationLinks();

Expand All @@ -86,7 +85,7 @@ public async Task Should_LogError_When_DbException()
throw new Exception("Error occurred");
});

IGetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);
GetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);

var result = await navQuery.GetNavigationLinks();

Expand All @@ -113,7 +112,7 @@ public async Task Should_LogError_When_Contentful_Exception()
});


IGetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);
GetNavigationQuery navQuery = new GetNavigationQuery(_db, _logger, _contentRepository);

var result = await navQuery.GetNavigationLinks();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dfe.PlanTech.Application.Content.Queries;
using Dfe.PlanTech.Application.Persistence.Interfaces;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models;
using Microsoft.Extensions.Logging;
using NSubstitute;
Expand All @@ -12,7 +11,7 @@ public class GetRichTextsQueryTests
private readonly ICmsDbContext _db = Substitute.For<ICmsDbContext>();
private readonly ILogger<GetRichTextsQuery> _logger = Substitute.For<ILogger<GetRichTextsQuery>>();

private readonly IGetPageChildrenQuery _getRichTextsQuery;
private readonly GetRichTextsQuery _getRichTextsQuery;

private readonly static PageDbEntity _loadedPage = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Dfe.PlanTech.Application.UnitTests.Cookie.Service
{
public class CookieServiceTests
{
IHttpContextAccessor Http = Substitute.For<IHttpContextAccessor>();
readonly IHttpContextAccessor Http = Substitute.For<IHttpContextAccessor>();

private CookieService CreateStrut()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GetLatestResponsesQueryTests
private const int QUESTION_PER_SECTION_COUNT = 5;
private const int ANSWER_PER_QUESTION_COUNT = 4;

private IPlanTechDbContext _planTechDbContextSubstitute;
private readonly IPlanTechDbContext _planTechDbContextSubstitute;
private readonly GetLatestResponsesQuery _getLatestResponseListForSubmissionQuery;

private readonly List<Submission> _submissions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Dfe.PlanTech.Application.Persistence.Interfaces;
using Dfe.PlanTech.Application.Submissions.Commands;
using Dfe.PlanTech.Domain.Questionnaire.Models;
using Dfe.PlanTech.Domain.Submissions.Interfaces;
using Dfe.PlanTech.Domain.Users.Interfaces;
using Microsoft.Data.SqlClient;
using NSubstitute;
Expand All @@ -12,7 +11,7 @@ namespace Dfe.PlanTech.Application.UnitTests.Submissions.Commands;

public class SubmitAnswerCommandTests
{
private readonly ISubmitAnswerCommand _submitAnswerCommand;
private readonly SubmitAnswerCommand _submitAnswerCommand;
private readonly IPlanTechDbContext _db;
private readonly IUser _user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task Should_Use_StatusCheckers()

_failureStatusChecker.IsMatchingSubmissionStatus(Arg.Any<SubmissionStatusProcessor>()).Returns(false);

ISubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
SubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
_getSubmissionStatusesQuery,
new[] { _statusCheckers[0], successStatusChecker },
_getResponsesQuery,
Expand All @@ -96,7 +96,7 @@ public async Task Should_Throw_Exception_When_NoStatusChecker_Matches()
{
_failureStatusChecker.IsMatchingSubmissionStatus(Arg.Any<SubmissionStatusProcessor>()).Returns(false);

ISubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
SubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
_getSubmissionStatusesQuery,
_statusCheckers,
_getResponsesQuery,
Expand All @@ -111,7 +111,7 @@ public async Task Should_Throw_Exception_When_NoStatusChecker_Matches()
[Fact]
public async Task Should_ThrowException_When_Section_NotFound()
{
ISubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
SubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery,
_getSubmissionStatusesQuery,
_statusCheckers,
_getResponsesQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RecordUserSigninCommandTests
public IGetUserIdQuery UserQuery = Substitute.For<IGetUserIdQuery>();
public ICreateUserCommand CreateUserCommand = Substitute.For<ICreateUserCommand>();
public IGetEstablishmentIdQuery GetEstablishmentIdQuery = Substitute.For<IGetEstablishmentIdQuery>();
private ICreateEstablishmentCommand CreateEstablishmentCommand = Substitute.For<ICreateEstablishmentCommand>();
private readonly ICreateEstablishmentCommand CreateEstablishmentCommand = Substitute.For<ICreateEstablishmentCommand>();

public RecordUserSignInCommand CreateStrut()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Dfe.PlanTech.AzureFunctions.UnitTests;
using Microsoft.EntityFrameworkCore.Query;
using System.Linq.Expressions;

namespace Dfe.PlanTech.AzureFunctions.UnitTests;

public class AsyncQueryProvider<TEntity> : IAsyncQueryProvider
{
private readonly IQueryProvider _inner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void ReturnEmptyBodyError_Should_ReturnBadResponse_And_LogMessage()

var response = _baseFunction.ReturnEmptyBodyError(request);

Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
_logger.ReceivedWithAnyArgs(1);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
var x = _logger.ReceivedWithAnyArgs(1);
Assert.NotNull(x);
}

[Fact]
Expand All @@ -37,7 +38,7 @@ public void ReturnServerErrorResponse_Should_LogError()

var response = _baseFunction.ReturnServerErrorResponse(request, exception);

Assert.True(response.StatusCode == HttpStatusCode.InternalServerError);
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);

_logger.ReceivedWithAnyArgs(1);
var loggerArguments = _logger.ReceivedCalls().First().GetArguments();
Expand All @@ -60,6 +61,6 @@ public void ReturnOkResponse_Should_ReturnOkResponse()

var response = BaseFunction.ReturnOkResponse(request);

Assert.True(response.StatusCode == HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task WebhookReceiver_Should_Error_If_NullOrEmptyBody()

var result = await _contentfulWebHook.WebhookReceiver(request);

Assert.True(result.StatusCode == HttpStatusCode.BadRequest);
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
}

[Fact]
Expand All @@ -87,7 +87,7 @@ public async Task WebhookReceiver_Should_ReturnOk_When_BodyNotNull()

var result = await _contentfulWebHook.WebhookReceiver(request);

Assert.True(result.StatusCode == HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, result.StatusCode);

Assert.NotNull(serviceBusMessage);

Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task WebhookReceiver_Should_ReturnError_When_ExceptionThrown()

var result = await _contentfulWebHook.WebhookReceiver(request);

Assert.True(result.StatusCode == HttpStatusCode.InternalServerError);
Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode);
}

[Fact]
Expand All @@ -143,6 +143,6 @@ public async Task WebhookReceiver_Should_ReturnError_When_NullOrEmptyHeader()

var result = await _contentfulWebHook.WebhookReceiver(request);

Assert.True(result.StatusCode == HttpStatusCode.InternalServerError);
Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SectionMapperTests()
{
Id = "Interstitial page id",
};

var list = new List<PageDbEntity>() { pageDbEntity };
IQueryable<PageDbEntity> queryable = list.AsQueryable();

Expand All @@ -51,7 +51,7 @@ public SectionMapperTests()
((IQueryable<PageDbEntity>)mockPageDataSet).Expression.Returns(queryable.Expression);
((IQueryable<PageDbEntity>)mockPageDataSet).ElementType.Returns(queryable.ElementType);
((IQueryable<PageDbEntity>)mockPageDataSet).GetEnumerator().Returns(queryable.GetEnumerator());

_logger = Substitute.For<ILogger<SectionMapper>>();
_mapper = new SectionMapper(_db, _logger, JsonOptions);

Expand Down Expand Up @@ -91,7 +91,7 @@ public void Mapper_Should_Map_Relationship()
Assert.Equal(InterstitialPage.Sys.Id, concrete.InterstitialPageId);

Assert.Equal(Questions.Length, _attachedQuestions.Count);

foreach (var question in Questions)
{
var contains = _attachedQuestions.Any(attached => attached.Id == question.Sys.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Dfe.PlanTech.AzureFunctions.UnitTests;

public class TextBodyMapperTests : BaseMapperTests
{
private string TextBodyId = "text body id";
private readonly string TextBodyId = "text body id";
private readonly TextBodyMapper _mapper;
private readonly ILogger<TextBodyMapper> _logger;
private readonly RichTextContentMapper _richTextMapper = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Dfe.PlanTech.Infrastructure.Contentful.UnitTests.Content.Renderers.Mod
public class RichTextRendererTests
{
private readonly RichTextRenderer _renderer;
private IRichTextContentPartRenderer _partRenderer = Substitute.For<IRichTextContentPartRenderer>();
private readonly IRichTextContentPartRenderer _partRenderer = Substitute.For<IRichTextContentPartRenderer>();

public RichTextRendererTests()
{
Expand Down
Loading

0 comments on commit e32d7a0

Please sign in to comment.