diff --git a/Data.TRAMS.Tests/Data.TRAMS.Tests.csproj b/Data.TRAMS.Tests/Data.TRAMS.Tests.csproj index 2fd8d15bd..693de60e6 100644 --- a/Data.TRAMS.Tests/Data.TRAMS.Tests.csproj +++ b/Data.TRAMS.Tests/Data.TRAMS.Tests.csproj @@ -7,12 +7,13 @@ - - - - - - + + + + + + + diff --git a/Data.TRAMS.Tests/TramsEducationPerformanceRepositoryTests.cs b/Data.TRAMS.Tests/TramsEducationPerformanceRepositoryTests.cs index 054eb5882..263fb066c 100644 --- a/Data.TRAMS.Tests/TramsEducationPerformanceRepositoryTests.cs +++ b/Data.TRAMS.Tests/TramsEducationPerformanceRepositoryTests.cs @@ -11,6 +11,7 @@ using Xunit; using EducationPerformance = Data.Models.KeyStagePerformance.EducationPerformance; using KeyStage2 = Data.Models.KeyStagePerformance.KeyStage2; +using FluentAssertions; namespace Data.TRAMS.Tests { @@ -108,14 +109,26 @@ public async void GivenResultFromApi_ReturnsMappedResult() } [Theory] - [InlineData(HttpStatusCode.NotFound)] [InlineData(HttpStatusCode.InternalServerError)] + [InlineData(HttpStatusCode.Unauthorized)] public async void GivenApiReturnsError_ThrowsApiError(HttpStatusCode httpStatusCode) { HttpClientTestHelpers.SetupGet(_client, null, httpStatusCode); await Assert.ThrowsAsync(() => _subject.GetByAcademyUrn("12345")); } + + [Fact] + public async void GivenApiReturnsNotFound_ShouldReturnEmptyEducationPerformance() + { + HttpClientTestHelpers.SetupGet(_client, null, HttpStatusCode.NotFound); + var result = await _subject.GetByAcademyUrn("12345"); + + var blankEducationPerformance = new EducationPerformance(); + + Assert.IsType(result.Result); + blankEducationPerformance.Should().BeEquivalentTo(result.Result); + } } } } \ No newline at end of file diff --git a/Data.TRAMS/TramsEducationPerformanceRepository.cs b/Data.TRAMS/TramsEducationPerformanceRepository.cs index 54dfc6090..b550b23b1 100644 --- a/Data.TRAMS/TramsEducationPerformanceRepository.cs +++ b/Data.TRAMS/TramsEducationPerformanceRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Threading.Tasks; using Data.Models.KeyStagePerformance; using Data.TRAMS.Models.EducationPerformance; @@ -49,6 +50,14 @@ public async Task> GetByAcademyUrn(string return mappedResult; } + if (response.StatusCode == HttpStatusCode.NotFound) + { + return new RepositoryResult() + { + Result = new EducationPerformance() + }; + } + throw new TramsApiException(response); } } diff --git a/Data/Models/KeyStagePerformance/EducationPerformance.cs b/Data/Models/KeyStagePerformance/EducationPerformance.cs index 0a39cfa5f..b3ada43c9 100644 --- a/Data/Models/KeyStagePerformance/EducationPerformance.cs +++ b/Data/Models/KeyStagePerformance/EducationPerformance.cs @@ -5,6 +5,13 @@ namespace Data.Models.KeyStagePerformance { public class EducationPerformance { + public EducationPerformance() + { + KeyStage2Performance = new List(); + KeyStage4Performance = new List(); + KeyStage5Performance = new List(); + } + //todo: remove this when view models/view component #region remove public string ProjectUrn { get;set; }