diff --git a/Childrens-Social-Care-CPD-Tests/Controllers/ContentController.ServerTests.cs b/Childrens-Social-Care-CPD-Tests/Controllers/ContentController.ServerTests.cs index de87e688..0b8fd21e 100644 --- a/Childrens-Social-Care-CPD-Tests/Controllers/ContentController.ServerTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Controllers/ContentController.ServerTests.cs @@ -18,7 +18,7 @@ public class ContentControllerServerTests { private CpdTestServerApplication _application; private HttpClient _httpClient; - private static string ContentUrl = "/"; + private static readonly string _contentUrl = "/"; [SetUp] public void SetUp() @@ -40,7 +40,7 @@ public async Task Content_Will_Contain_Warning_If_Data_Is_Self_Referential() _application.CpdContentfulClient.GetEntries(Arg.Any>(), Arg.Any()).Returns(contentCollection); // act - var response = await _httpClient.GetAsync(ContentUrl); + var response = await _httpClient.GetAsync(_contentUrl); var responseContent = await response.Content.ReadAsStringAsync(); // assert @@ -52,13 +52,15 @@ public async Task Content_Will_Contain_Warning_If_Data_Is_Self_Referential() public async Task Content_Will_Contain_Warning_If_Data_Has_An_Unknown_Content_Type() { // arrange - var content = new Content(); - content.Items = new List { new TestingContentItem() }; + var content = new Content + { + Items = new List { new TestingContentItem() } + }; var contentCollection = new ContentfulCollection() { Items = new List() { content } }; _application.CpdContentfulClient.GetEntries(Arg.Any>(), Arg.Any()).Returns(contentCollection); // act - var response = await _httpClient.GetAsync(ContentUrl); + var response = await _httpClient.GetAsync(_contentUrl); var responseContent = await response.Content.ReadAsStringAsync(); // assert diff --git a/Childrens-Social-Care-CPD-Tests/Controllers/ContentControllerTests.cs b/Childrens-Social-Care-CPD-Tests/Controllers/ContentControllerTests.cs index 089477e2..a3c89caa 100644 --- a/Childrens-Social-Care-CPD-Tests/Controllers/ContentControllerTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Controllers/ContentControllerTests.cs @@ -54,9 +54,11 @@ public void SetUp() _contentfulClient = Substitute.For(); - _contentController = new ContentController(_contentfulClient); - _contentController.ControllerContext = controllerContext; - _contentController.TempData = Substitute.For(); + _contentController = new ContentController(_contentfulClient) + { + ControllerContext = controllerContext, + TempData = Substitute.For() + }; } [Test] @@ -124,13 +126,13 @@ public async Task Index_Sets_The_ContextModel_Preferences_Set_Value_Correctly(bo actual.PreferenceSet.Should().Be(preferenceSet); } - public static object[] SideMenuContent = + private static readonly object[] _sideMenuContent = { new object[] { new SideMenu() }, new object[] { null }, }; - [TestCaseSource(nameof(SideMenuContent))] + [TestCaseSource(nameof(_sideMenuContent))] public async Task Index_Sets_The_ContextModel_UseContainers_From_SideMenu_Value_Correctly(SideMenu sideMenu) { // arrange diff --git a/Childrens-Social-Care-CPD-Tests/Controllers/CookieControllerTests.cs b/Childrens-Social-Care-CPD-Tests/Controllers/CookieControllerTests.cs index 800c50f3..1acd856c 100644 --- a/Childrens-Social-Care-CPD-Tests/Controllers/CookieControllerTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Controllers/CookieControllerTests.cs @@ -63,9 +63,11 @@ public void SetUp() _contentfulClient = Substitute.For(); - _cookieController = new CookieController(_contentfulClient, new CookieHelper(new ApplicationConfiguration())); - _cookieController.ControllerContext = controllerContext; - _cookieController.TempData = Substitute.For(); + _cookieController = new CookieController(_contentfulClient, new CookieHelper(new ApplicationConfiguration())) + { + ControllerContext = controllerContext, + TempData = Substitute.For() + }; } [Test] @@ -120,13 +122,13 @@ public async Task Cookies_Sets_The_ContextModel_Preferences_Set_Value_Correctly( actual.PreferenceSet.Should().Be(preferenceSet); } - public static object[] SideMenuContent = + private static readonly object[] _sideMenuContent = { new object[] { new SideMenu() }, new object[] { null }, }; - [TestCaseSource(nameof(SideMenuContent))] + [TestCaseSource(nameof(_sideMenuContent))] public async Task Cookies_Sets_The_ContextModel_UseContainers_Ignoring_The_SideMenu_Value(SideMenu sideMenu) { // arrange diff --git a/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs b/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs index 51adb3af..60ad48bf 100644 --- a/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs @@ -79,7 +79,7 @@ public async Task Search_With_Empty_Query_Returns_View() SetContent(null, null); // act - var actual = await _resourcesController.Search(_cancellationTokenSource.Token, query: null) as ViewResult; + var actual = await _resourcesController.Search(query: null, _cancellationTokenSource.Token) as ViewResult; // assert actual.Should().BeOfType(); @@ -92,14 +92,9 @@ public async Task Search_Page_Resource_Is_Passed_To_View() // arrange var content = new Content(); SetContent(content, null); - var query = new ResourcesQuery - { - Page = 1, - Tags = Array.Empty() - }; // act - var actual = (await _resourcesController.Search(_cancellationTokenSource.Token, query: null) as ViewResult)?.Model as ResourcesListViewModel; + var actual = (await _resourcesController.Search(query: null, _cancellationTokenSource.Token) as ViewResult)?.Model as ResourcesListViewModel; // assert actual.Content.Should().Be(content); @@ -112,7 +107,7 @@ public async Task Search_Sets_The_ViewState_ContextModel() SetContent(null, null); // act - await _resourcesController.Search(_cancellationTokenSource.Token, null); + await _resourcesController.Search(null, _cancellationTokenSource.Token); var actual = _resourcesController.ViewData["ContextModel"] as ContextModel; // assert @@ -134,7 +129,7 @@ public async Task Search_Selected_Tags_Are_Passed_Into_View() }; // act - var actual = (await _resourcesController.Search(_cancellationTokenSource.Token, query) as ViewResult)?.Model as ResourcesListViewModel; + var actual = (await _resourcesController.Search(query, _cancellationTokenSource.Token) as ViewResult)?.Model as ResourcesListViewModel; // assert actual.SelectedTags.Should().Equal(query.Tags); @@ -159,7 +154,7 @@ public async Task Search_Page_Set_To_Be_In_Bounds() }; // act - var actual = (await _resourcesController.Search(_cancellationTokenSource.Token, query) as ViewResult)?.Model as ResourcesListViewModel; + var actual = (await _resourcesController.Search(query, _cancellationTokenSource.Token) as ViewResult)?.Model as ResourcesListViewModel; // assert actual.CurrentPage.Should().Be(1); @@ -178,9 +173,9 @@ public async Task Search_Invalid_Tags_Logs_Warning() }; // act - await _resourcesController.Search(_cancellationTokenSource.Token, query); + await _resourcesController.Search(query, _cancellationTokenSource.Token); //assert _logger.ReceivedWithAnyArgs(1).LogWarning(default, args: default); } -} +} \ No newline at end of file diff --git a/Childrens-Social-Care-CPD-Tests/CpdTestServerApplication.cs b/Childrens-Social-Care-CPD-Tests/CpdTestServerApplication.cs index 1601c7a4..899fdbe6 100644 --- a/Childrens-Social-Care-CPD-Tests/CpdTestServerApplication.cs +++ b/Childrens-Social-Care-CPD-Tests/CpdTestServerApplication.cs @@ -10,7 +10,7 @@ namespace Childrens_Social_Care_CPD_Tests; internal class CpdTestServerApplication : WebApplicationFactory { - private ICpdContentfulClient _cpdContentfulClient; + private readonly ICpdContentfulClient _cpdContentfulClient; private ILoggerFactory _loggerFactory; public CpdTestServerApplication() diff --git a/Childrens-Social-Care-CPD/Controllers/CookieController.cs b/Childrens-Social-Care-CPD/Controllers/CookieController.cs index e2e501f7..7161577f 100644 --- a/Childrens-Social-Care-CPD/Controllers/CookieController.cs +++ b/Childrens-Social-Care-CPD/Controllers/CookieController.cs @@ -11,7 +11,7 @@ public class CookieController : Controller { private readonly ICpdContentfulClient _cpdClient; private readonly ICookieHelper _cookieHelper; - private const string PageName = "cookies"; + private const string _pageName = "cookies"; public CookieController(ICpdContentfulClient cpdClient, ICookieHelper cookieHelper) { @@ -39,11 +39,11 @@ public IActionResult SetPreferences(string consentValue, string sourcePage = nul [Route("/cookies")] public async Task Cookies(CancellationToken cancellationToken, string sourcePage = null, bool preferenceSet = false) { - sourcePage = sourcePage ?? string.Empty; + sourcePage ??= string.Empty; var queryBuilder = QueryBuilder.New .ContentTypeIs("content") - .FieldEquals("fields.id", PageName) + .FieldEquals("fields.id", _pageName) .Include(10); var result = await _cpdClient.GetEntries(queryBuilder, cancellationToken); @@ -60,7 +60,7 @@ public async Task Cookies(CancellationToken cancellationToken, st } var consentState = _cookieHelper.GetRequestAnalyticsCookieState(HttpContext); - var contextModel = new ContextModel(pageContent.Id, pageContent.Title, PageName, pageContent.Category, true, preferenceSet, true); + var contextModel = new ContextModel(pageContent.Id, pageContent.Title, _pageName, pageContent.Category, true, preferenceSet, true); ViewData["ContextModel"] = contextModel; var model = new CookiesAndAnalyticsConsentModel diff --git a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs index 9637af3a..a243e073 100644 --- a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs +++ b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs @@ -62,7 +62,7 @@ private Task> FetchResourcesContentAsync(Cancellat return _cpdClient.GetEntries(queryBuilder, cancellationToken); } - private Task> FetchResourceSearchResultsAsync(CancellationToken cancellationToken, int[] tags, int skip = 0, int limit = 5) + private Task> FetchResourceSearchResultsAsync(int[] tags, CancellationToken cancellationToken, int skip = 0, int limit = 5) { var queryBuilder = QueryBuilder.New .ContentTypeIs("resource") @@ -75,10 +75,10 @@ private Task> FetchResourceSearchResultsAsync(Can return _cpdClient.GetEntries(queryBuilder, cancellationToken); } - private async Task>> GetContentAsync(CancellationToken cancellationToken, int[] tags, int skip = 0, int limit = 5) + private async Task>> GetContentAsync(int[] tags, CancellationToken cancellationToken, int skip = 0, int limit = 5) { var pageContentTask = FetchResourcesContentAsync(cancellationToken); - var searchContentTask = FetchResourceSearchResultsAsync(cancellationToken, tags, skip, limit); + var searchContentTask = FetchResourceSearchResultsAsync(tags, cancellationToken, skip, limit); await Task.WhenAll(pageContentTask, searchContentTask); return Tuple.Create(pageContentTask.Result?.FirstOrDefault(), searchContentTask.Result); @@ -105,13 +105,13 @@ private static string GetPagingFormatString(int[] tags) [Route("resources", Name = "Resource")] [HttpGet] - public async Task Search(CancellationToken cancellationToken, [FromQuery] ResourcesQuery query, bool preferencesSet = false) + public async Task Search([FromQuery] ResourcesQuery query, CancellationToken cancellationToken, bool preferencesSet = false) { query ??= new ResourcesQuery(); query.Tags ??= Array.Empty(); (var page, var skip, var pageSize) = CalculatePaging(query); - (var pageContent, var contentCollection) = await GetContentAsync(cancellationToken, query.Tags, skip, pageSize); + (var pageContent, var contentCollection) = await GetContentAsync(query.Tags, cancellationToken, skip, pageSize); var totalPages = (int)Math.Ceiling((decimal)contentCollection.Total / pageSize); page = Math.Min(page, totalPages);