diff --git a/src/Dfe.PlanTech.Infrastructure.Contentful/Helpers/GetEntitiesException.cs b/src/Dfe.PlanTech.Infrastructure.Contentful/Helpers/GetEntitiesException.cs index 0dfd3812b..934fe3da1 100644 --- a/src/Dfe.PlanTech.Infrastructure.Contentful/Helpers/GetEntitiesException.cs +++ b/src/Dfe.PlanTech.Infrastructure.Contentful/Helpers/GetEntitiesException.cs @@ -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) { } \ No newline at end of file diff --git a/src/Dfe.PlanTech.Web/Helpers/RouteDataExtensions.cs b/src/Dfe.PlanTech.Web/Helpers/RouteDataExtensions.cs index f655a4d7a..c93de13b8 100644 --- a/src/Dfe.PlanTech.Web/Helpers/RouteDataExtensions.cs +++ b/src/Dfe.PlanTech.Web/Helpers/RouteDataExtensions.cs @@ -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) { @@ -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(); diff --git a/src/Dfe.PlanTech.Web/ProgramExtensions.cs b/src/Dfe.PlanTech.Web/ProgramExtensions.cs index 15769c7de..d83ead493 100644 --- a/src/Dfe.PlanTech.Web/ProgramExtensions.cs +++ b/src/Dfe.PlanTech.Web/ProgramExtensions.cs @@ -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")); diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetButtonWithEntryReferencesQueryTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetButtonWithEntryReferencesQueryTests.cs index ef8cd9cc3..31e258c49 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetButtonWithEntryReferencesQueryTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetButtonWithEntryReferencesQueryTests.cs @@ -13,7 +13,7 @@ public class GetButtonWithEntryReferencesQueryTests private readonly ICmsDbContext _db = Substitute.For(); private readonly ILogger _logger = Substitute.For>(); - private readonly IGetPageChildrenQuery _getButtonWithEntryReferencesQuery; + private readonly GetButtonWithEntryReferencesQuery _getButtonWithEntryReferencesQuery; private readonly static PageDbEntity _pageWithButton = new() { diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetCategorySectionsQueryTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetCategorySectionsQueryTests.cs index d67077179..7df457b13 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetCategorySectionsQueryTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetCategorySectionsQueryTests.cs @@ -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; @@ -14,7 +13,7 @@ public class GetCategorySectionsQueryTests private readonly ICmsDbContext _db = Substitute.For(); private readonly ILogger _logger = Substitute.For>(); - private readonly IGetPageChildrenQuery _getCategorySectionsQuery; + private readonly GetCategorySectionsQuery _getCategorySectionsQuery; private readonly static PageDbEntity _loadedPage = new() { diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetNavigationQueryTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetNavigationQueryTests.cs index 010529bb9..2f5ba84a4 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetNavigationQueryTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetNavigationQueryTests.cs @@ -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; @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetRichTextsQueryTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetRichTextsQueryTests.cs index bec5411bb..b31279fa2 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetRichTextsQueryTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Content/Queries/GetRichTextsQueryTests.cs @@ -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; @@ -12,7 +11,7 @@ public class GetRichTextsQueryTests private readonly ICmsDbContext _db = Substitute.For(); private readonly ILogger _logger = Substitute.For>(); - private readonly IGetPageChildrenQuery _getRichTextsQuery; + private readonly GetRichTextsQuery _getRichTextsQuery; private readonly static PageDbEntity _loadedPage = new() { diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Cookie/Service/CookieServiceTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Cookie/Service/CookieServiceTests.cs index 5f2b29bad..00a7cb521 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Cookie/Service/CookieServiceTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Cookie/Service/CookieServiceTests.cs @@ -9,7 +9,7 @@ namespace Dfe.PlanTech.Application.UnitTests.Cookie.Service { public class CookieServiceTests { - IHttpContextAccessor Http = Substitute.For(); + readonly IHttpContextAccessor Http = Substitute.For(); private CookieService CreateStrut() { diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Responses/Queries/GetLatestResponsesQueryTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Responses/Queries/GetLatestResponsesQueryTests.cs index f08e85e38..7be307fe4 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Responses/Queries/GetLatestResponsesQueryTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Responses/Queries/GetLatestResponsesQueryTests.cs @@ -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 _submissions; diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Commands/SubmitAnswerCommandTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Commands/SubmitAnswerCommandTests.cs index df9f1725b..3876db575 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Commands/SubmitAnswerCommandTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Commands/SubmitAnswerCommandTests.cs @@ -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; @@ -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; diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Queries/SubmissionStatusProcessorTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Queries/SubmissionStatusProcessorTests.cs index 955069f5f..92336de01 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Queries/SubmissionStatusProcessorTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Submissions/Queries/SubmissionStatusProcessorTests.cs @@ -71,7 +71,7 @@ public async Task Should_Use_StatusCheckers() _failureStatusChecker.IsMatchingSubmissionStatus(Arg.Any()).Returns(false); - ISubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery, + SubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery, _getSubmissionStatusesQuery, new[] { _statusCheckers[0], successStatusChecker }, _getResponsesQuery, @@ -96,7 +96,7 @@ public async Task Should_Throw_Exception_When_NoStatusChecker_Matches() { _failureStatusChecker.IsMatchingSubmissionStatus(Arg.Any()).Returns(false); - ISubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery, + SubmissionStatusProcessor processor = new SubmissionStatusProcessor(_getSectionQuery, _getSubmissionStatusesQuery, _statusCheckers, _getResponsesQuery, @@ -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, diff --git a/tests/Dfe.PlanTech.Application.UnitTests/Users/Commands/RecordUserSigninCommandTests.cs b/tests/Dfe.PlanTech.Application.UnitTests/Users/Commands/RecordUserSigninCommandTests.cs index 836349a4a..16141de72 100644 --- a/tests/Dfe.PlanTech.Application.UnitTests/Users/Commands/RecordUserSigninCommandTests.cs +++ b/tests/Dfe.PlanTech.Application.UnitTests/Users/Commands/RecordUserSigninCommandTests.cs @@ -15,7 +15,7 @@ public class RecordUserSigninCommandTests public IGetUserIdQuery UserQuery = Substitute.For(); public ICreateUserCommand CreateUserCommand = Substitute.For(); public IGetEstablishmentIdQuery GetEstablishmentIdQuery = Substitute.For(); - private ICreateEstablishmentCommand CreateEstablishmentCommand = Substitute.For(); + private readonly ICreateEstablishmentCommand CreateEstablishmentCommand = Substitute.For(); public RecordUserSignInCommand CreateStrut() { diff --git a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/AsyncQueryProvider.cs b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/AsyncQueryProvider.cs index 8389d4828..a2e1cc5ef 100644 --- a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/AsyncQueryProvider.cs +++ b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/AsyncQueryProvider.cs @@ -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 : IAsyncQueryProvider { private readonly IQueryProvider _inner; diff --git a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/BaseFunctionTests.cs b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/BaseFunctionTests.cs index 8f9eee67c..e8ffa7a3a 100644 --- a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/BaseFunctionTests.cs +++ b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/BaseFunctionTests.cs @@ -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] @@ -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(); @@ -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); } } \ No newline at end of file diff --git a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/ContentfulWebHookTests.cs b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/ContentfulWebHookTests.cs index be3b42c24..c6f6d6f94 100644 --- a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/ContentfulWebHookTests.cs +++ b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Functions/ContentfulWebHookTests.cs @@ -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] @@ -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); @@ -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] @@ -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); } } \ No newline at end of file diff --git a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/SectionMapperTests.cs b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/SectionMapperTests.cs index 07c324415..bcecaf9b2 100644 --- a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/SectionMapperTests.cs +++ b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/SectionMapperTests.cs @@ -40,7 +40,7 @@ public SectionMapperTests() { Id = "Interstitial page id", }; - + var list = new List() { pageDbEntity }; IQueryable queryable = list.AsQueryable(); @@ -51,7 +51,7 @@ public SectionMapperTests() ((IQueryable)mockPageDataSet).Expression.Returns(queryable.Expression); ((IQueryable)mockPageDataSet).ElementType.Returns(queryable.ElementType); ((IQueryable)mockPageDataSet).GetEnumerator().Returns(queryable.GetEnumerator()); - + _logger = Substitute.For>(); _mapper = new SectionMapper(_db, _logger, JsonOptions); @@ -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); diff --git a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/TextBodyMapperTests.cs b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/TextBodyMapperTests.cs index 4307fff31..e486fba04 100644 --- a/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/TextBodyMapperTests.cs +++ b/tests/Dfe.PlanTech.AzureFunctions.UnitTests/Mappers/TextBodyMapperTests.cs @@ -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 _logger; private readonly RichTextContentMapper _richTextMapper = new(); diff --git a/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Content/Renderers/Models/RichTextRendererTests.cs b/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Content/Renderers/Models/RichTextRendererTests.cs index dbdd8f8ec..19c2fea33 100644 --- a/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Content/Renderers/Models/RichTextRendererTests.cs +++ b/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Content/Renderers/Models/RichTextRendererTests.cs @@ -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(); + private readonly IRichTextContentPartRenderer _partRenderer = Substitute.For(); public RichTextRendererTests() { diff --git a/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Persistence/ContentfulRepositoryTests.cs b/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Persistence/ContentfulRepositoryTests.cs index 991f338d3..1214e936b 100644 --- a/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Persistence/ContentfulRepositoryTests.cs +++ b/tests/Dfe.PlanTech.Infrastructure.Contentful.UnitTests/Persistence/ContentfulRepositoryTests.cs @@ -1,7 +1,6 @@ using Contentful.Core; using Contentful.Core.Models; using Contentful.Core.Search; -using Dfe.PlanTech.Application.Persistence.Interfaces; using Dfe.PlanTech.Infrastructure.Contentful.Persistence; using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; @@ -11,7 +10,7 @@ namespace Dfe.PlanTech.Infrastructure.Contentful.UnitTests.Persistence { public class ContentfulRepositoryTests { - private IContentfulClient _clientSubstitute = Substitute.For(); + private readonly IContentfulClient _clientSubstitute = Substitute.For(); private readonly List _substituteData = new() { new TestClass(), new TestClass("testId"), new TestClass("anotherId"), new TestClass("abcd1234") @@ -68,8 +67,7 @@ public ContentfulRepositoryTests() [Fact] public async Task Should_Call_Client_Method_When_Using_GetEntities() { - - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntities(); @@ -79,7 +77,7 @@ public async Task Should_Call_Client_Method_When_Using_GetEntities() [Fact] public async Task Should_CallClientMethod_When_Using_GetEntityById() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntityById("testId"); @@ -89,7 +87,7 @@ public async Task Should_CallClientMethod_When_Using_GetEntityById() [Fact] public async Task GetEntities_Should_ReturnItems_When_ClassMatches() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntities(); @@ -101,7 +99,7 @@ public async Task GetEntities_Should_ReturnItems_When_ClassMatches() [Fact] public async Task GetEntities_Should_ReturnEmptyIEnumerable_When_NoDataFound() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntities(); @@ -114,7 +112,7 @@ public async Task GetEntityById_Should_FindMatchingItem_When_IdMatches() { var testId = "testId"; - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntityById(testId); @@ -125,7 +123,7 @@ public async Task GetEntityById_Should_FindMatchingItem_When_IdMatches() [Fact] public async Task GetEntityById_Should_ThrowException_When_IdIsNull() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); await Assert.ThrowsAsync(() => repository.GetEntityById(null)); } @@ -133,7 +131,7 @@ public async Task GetEntityById_Should_ThrowException_When_IdIsNull() [Fact] public async Task GetEntityById_Should_ThrowException_When_IdIsEmpty() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); await Assert.ThrowsAsync(() => repository.GetEntityById("")); } @@ -141,7 +139,7 @@ public async Task GetEntityById_Should_ThrowException_When_IdIsEmpty() [Fact] public async Task Should_ReturnNull_When_IdNotFound() { - IContentRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); + ContentfulRepository repository = new ContentfulRepository(new NullLoggerFactory(), _clientSubstitute); var result = await repository.GetEntityById("not a real id"); diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Authorisation/PageModelAuthorisationPolicyTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Authorisation/PageModelAuthorisationPolicyTests.cs index f31f1aeb2..d8a4c32e4 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Authorisation/PageModelAuthorisationPolicyTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Authorisation/PageModelAuthorisationPolicyTests.cs @@ -14,11 +14,11 @@ namespace Dfe.PlanTech.Web.Authorisation; public class PageModelAuthorisationPolicyTests { - private IGetPageQuery _getPageQuery; - private PageModelAuthorisationPolicy _policy; + private readonly IGetPageQuery _getPageQuery; + private readonly PageModelAuthorisationPolicy _policy; private AuthorizationHandlerContext _authContext; - private ILogger _logger; - private HttpContext _httpContext; + private readonly ILogger _logger; + private readonly HttpContext _httpContext; public PageModelAuthorisationPolicyTests() { diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Controllers/CookieControllerTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Controllers/CookieControllerTests.cs index 5147facc8..b983b7c11 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Controllers/CookieControllerTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Controllers/CookieControllerTests.cs @@ -59,7 +59,7 @@ public void HideBanner_Redirects_BackToPlaceOfOrigin(string url) //Arrange var strut = CreateStrut(); var httpContext = new DefaultHttpContext(); - httpContext.Request.Headers["Referer"] = url; + httpContext.Request.Headers.Referer = url; strut.ControllerContext = new ControllerContext { @@ -82,7 +82,7 @@ public void Accept_Redirects_BackToPlaceOfOrigin(string url) //Arrange var strut = CreateStrut(); var httpContext = new DefaultHttpContext(); - httpContext.Request.Headers["Referer"] = url; + httpContext.Request.Headers.Referer = url; strut.ControllerContext = new ControllerContext { HttpContext = httpContext @@ -104,7 +104,7 @@ public void Reject_Redirects_BackToPlaceOfOrigin(string url) //Arrange var strut = CreateStrut(); var httpContext = new DefaultHttpContext(); - httpContext.Request.Headers["Referer"] = url; + httpContext.Request.Headers.Referer = url; strut.ControllerContext = new ControllerContext { HttpContext = httpContext @@ -173,8 +173,8 @@ public void settingCookiePreferenceBasedOnInputRedirectsToCookiePage(string user if (res != null) { - Assert.True(res.ActionName == "GetByRoute"); - Assert.True(res.ControllerName == "Pages"); + Assert.Equal("GetByRoute", res.ActionName); + Assert.Equal("Pages", res.ControllerName); } } diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Controllers/PagesControllerTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Controllers/PagesControllerTests.cs index 49bf2185e..0b6071fbd 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Controllers/PagesControllerTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Controllers/PagesControllerTests.cs @@ -21,8 +21,8 @@ public class PagesControllerTests private const string INDEX_SLUG = "/"; private const string INDEX_TITLE = "Index"; private const string SELF_ASSESSMENT_SLUG = "self-assessment"; - ICookieService cookiesSubstitute = Substitute.For(); - IUser userSubstitute = Substitute.For(); + readonly ICookieService cookiesSubstitute = Substitute.For(); + readonly IUser userSubstitute = Substitute.For(); private readonly PagesController _controller; private readonly ControllerContext _controllerContext; diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Helpers/RouteDataExtensionsTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Helpers/RouteDataExtensionsTests.cs index 7cf59a1d7..0a09ecea7 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Helpers/RouteDataExtensionsTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Helpers/RouteDataExtensionsTests.cs @@ -1,51 +1,54 @@ -using Microsoft.AspNetCore.Routing; using Dfe.PlanTech.Web.Helpers; +using Microsoft.AspNetCore.Routing; using Xunit; -public class RouteDataExtensionsTests +namespace Dfe.PlanTech.Web.UnitTests.Helpers { - [Fact] - public void GetTitleForPage_WhenSectionSlugIsEmpty_ReturnsDefaultPageTitle() - { - var routeData = new RouteData(); + public class RouteDataExtensionsTests + { + [Fact] + public void GetTitleForPage_WhenSectionSlugIsEmpty_ReturnsDefaultPageTitle() + { + var routeData = new RouteData(); - var result = routeData.GetTitleForPage(); + var result = routeData.GetTitleForPage(); - Assert.Equal(RouteDataExtensions.DefaultPageTitle, result); - } + Assert.Equal(RouteDataExtensions.DefaultPageTitle, result); + } - [Fact] - public void GetTitleForPage_Returns_SectionSlug() - { - var routeData = new RouteData(); - routeData.Values.Add("sectionSlug", "broadband-connection"); + [Fact] + public void GetTitleForPage_Returns_SectionSlug() + { + var routeData = new RouteData(); + routeData.Values.Add("sectionSlug", "broadband-connection"); - var result = routeData.GetTitleForPage(); + var result = routeData.GetTitleForPage(); - Assert.Equal("Broadband connection", result); - } + Assert.Equal("Broadband connection", result); + } - [Fact] - public void GetTitleForPage_Ignores_ForwardSlashes() - { - var routeData = new RouteData(); - routeData.Values.Add("sectionSlug", "broadband-connection"); - routeData.Values.Add("route", "/"); + [Fact] + public void GetTitleForPage_Ignores_ForwardSlashes() + { + var routeData = new RouteData(); + routeData.Values.Add("sectionSlug", "broadband-connection"); + routeData.Values.Add("route", "/"); - var result = routeData.GetTitleForPage(); + var result = routeData.GetTitleForPage(); - Assert.Equal("Broadband connection", result); - } + Assert.Equal("Broadband connection", result); + } - [Fact] - public void GetTitleForPage_Ignores_Numbers() - { - var routeData = new RouteData(); - routeData.Values.Add("sectionSlug", "broadband-connection"); - routeData.Values.Add("route", "abcd-1234"); + [Fact] + public void GetTitleForPage_Ignores_Numbers() + { + var routeData = new RouteData(); + routeData.Values.Add("sectionSlug", "broadband-connection"); + routeData.Values.Add("route", "abcd-1234"); - var result = routeData.GetTitleForPage(); + var result = routeData.GetTitleForPage(); - Assert.Equal("Broadband connection", result); - } + Assert.Equal("Broadband connection", result); + } + } } \ No newline at end of file diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Helpers/UserHelperTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Helpers/UserHelperTests.cs index 712cfb2ed..748d15b89 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Helpers/UserHelperTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Helpers/UserHelperTests.cs @@ -17,13 +17,13 @@ public class UserHelperTests private const string FIRST_ESTABLISHMENT_REF = "131"; private readonly UserHelper _userHelper; - private IHttpContextAccessor _httpContextAccessorSubstitute; - private IPlanTechDbContext _planTechDbContextSubstitute; - private ICreateEstablishmentCommand _createEstablishmentCommandSubstitute; + private readonly IHttpContextAccessor _httpContextAccessorSubstitute; + private readonly IPlanTechDbContext _planTechDbContextSubstitute; + private readonly ICreateEstablishmentCommand _createEstablishmentCommandSubstitute; private IGetUserIdQuery _getUserIdQuerySubstitute; private IGetEstablishmentIdQuery _getEstablishmentIdQuerySubstitute; - private List _users = new(){ + private readonly List _users = new(){ new User(){ DfeSignInRef = FIRST_USER_REF, Id = 1 @@ -34,7 +34,7 @@ public class UserHelperTests } }; - private List _establishments = new(){ + private readonly List _establishments = new(){ new Establishment(){ EstablishmentRef = FIRST_ESTABLISHMENT_REF, Id = 1 diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Models/ComponentModelTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Models/ComponentModelTests.cs index 6334b0979..c131489f8 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Models/ComponentModelTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Models/ComponentModelTests.cs @@ -5,7 +5,7 @@ namespace Dfe.PlanTech.Web.UnitTests.Models { public class ComponentModelTests { - private IComponentBuilder _componentBuilder; + private readonly IComponentBuilder _componentBuilder; public ComponentModelTests() { @@ -16,7 +16,7 @@ public ComponentModelTests() public void Should_render_button_component() { var actual = _componentBuilder.BuildButtonWithLink(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Submit", actual.Button.Value); Assert.False(actual.Button.IsStartButton); Assert.Equal("/FakeLink", actual.Href); @@ -26,7 +26,7 @@ public void Should_render_button_component() public void Should_render_dropdown_component() { var actual = _componentBuilder.BuildDropDownComponent(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Dropdown", actual.Title); Assert.Equal("Content", actual.Content.Value); } @@ -35,7 +35,7 @@ public void Should_render_dropdown_component() public void Should_render_textbody_component() { var actual = _componentBuilder.BuildTextBody(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Content", actual.RichText.Value); } @@ -43,7 +43,7 @@ public void Should_render_textbody_component() public void Should_render_category_component() { var actual = _componentBuilder.BuildCategory(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Category", actual.Header.Text); Assert.Equal("Section", actual.Sections[0].Name); Assert.True(actual.Sections[0].Questions != null); @@ -59,7 +59,7 @@ public void Should_render_category_component() public void Should_Render_ButtonWithEntryReference() { var actual = _componentBuilder.BuildButtonWithEntryReference(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Submit", actual.Button.Value); Assert.False(actual.Button.IsStartButton); Assert.NotNull(actual.LinkToEntry); @@ -70,7 +70,7 @@ public void Should_Render_InsetText() { var actual = _componentBuilder.BuildInsetText(); - Assert.True(actual != null); + Assert.NotNull(actual); Assert.Equal("Inset Text", actual.Text); } diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Routing/CheckAnswersRouterTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Routing/CheckAnswersRouterTests.cs index 1226cfd8c..4ed6f351e 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Routing/CheckAnswersRouterTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Routing/CheckAnswersRouterTests.cs @@ -26,7 +26,7 @@ public class CheckAnswersRouterTests private readonly CheckAnswersController _controller = new(new NullLogger()); - private readonly ICheckAnswersRouter _router; + private readonly CheckAnswersRouter _router; private const int establishmentId = 1; diff --git a/tests/Dfe.PlanTech.Web.UnitTests/Routing/GetRecommendationRouterTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/Routing/GetRecommendationRouterTests.cs index b7415af4a..890ea6613 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/Routing/GetRecommendationRouterTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/Routing/GetRecommendationRouterTests.cs @@ -24,7 +24,7 @@ public class GetRecommendationRouterTests private readonly IUser _user; private readonly RecommendationsController _controller; - private readonly IGetRecommendationRouter _router; + private readonly GetRecommendationRouter _router; private readonly Section _section = new() { diff --git a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs index 2f57b462e..37832f634 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/CategorySectionViewComponentTests.cs @@ -18,7 +18,7 @@ public class CategorySectionViewComponentTests private readonly CategorySectionViewComponent _categorySectionViewComponent; private Category _category; - private ILogger _loggerCategory; + private readonly ILogger _loggerCategory; public CategorySectionViewComponentTests() { diff --git a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/FooterLinksComponentTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/FooterLinksComponentTests.cs index 758aee7fd..a2f31fb50 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/FooterLinksComponentTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/FooterLinksComponentTests.cs @@ -11,7 +11,7 @@ namespace Dfe.PlanTech.Web.UnitTests.ViewComponents; public class FooterLinksComponentTests { - private NavigationLink[] _navigationLinks = new[]{ + private readonly NavigationLink[] _navigationLinks = new[]{ new NavigationLink(){ DisplayText = "Testing", Href = "/testing" diff --git a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/RecommendationsViewComponentTests.cs b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/RecommendationsViewComponentTests.cs index 468a2ef6a..bb0e81202 100644 --- a/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/RecommendationsViewComponentTests.cs +++ b/tests/Dfe.PlanTech.Web.UnitTests/ViewComponents/RecommendationsViewComponentTests.cs @@ -17,8 +17,8 @@ public class RecommendationsViewComponentTests private readonly RecommendationsViewComponent _recommendationsComponent; private readonly Category _category; private readonly Category _categoryTwo; - private IGetSubmissionStatusesQuery _getSubmissionStatusesQuery; - private ILogger _loggerCategory; + private readonly IGetSubmissionStatusesQuery _getSubmissionStatusesQuery; + private readonly ILogger _loggerCategory; public RecommendationsViewComponentTests() {