Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:DFE-Digital/academy-transfers-api
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartBarker committed Mar 10, 2022
2 parents c85fc7c + 453b988 commit af4fd8f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Data.TRAMS.Tests/Data.TRAMS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Data.TRAMS\Data.TRAMS.csproj"/>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.0"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="Moq" Version="4.17.2"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<ProjectReference Include="..\Data.TRAMS\Data.TRAMS.csproj" />
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.17.2" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

</Project>
15 changes: 14 additions & 1 deletion Data.TRAMS.Tests/TramsEducationPerformanceRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xunit;
using EducationPerformance = Data.Models.KeyStagePerformance.EducationPerformance;
using KeyStage2 = Data.Models.KeyStagePerformance.KeyStage2;
using FluentAssertions;

namespace Data.TRAMS.Tests
{
Expand Down Expand Up @@ -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<TramsEducationPerformance>(_client, null, httpStatusCode);

await Assert.ThrowsAsync<TramsApiException>(() => _subject.GetByAcademyUrn("12345"));
}

[Fact]
public async void GivenApiReturnsNotFound_ShouldReturnEmptyEducationPerformance()
{
HttpClientTestHelpers.SetupGet<TramsEducationPerformance>(_client, null, HttpStatusCode.NotFound);
var result = await _subject.GetByAcademyUrn("12345");

var blankEducationPerformance = new EducationPerformance();

Assert.IsType<EducationPerformance>(result.Result);
blankEducationPerformance.Should().BeEquivalentTo(result.Result);
}
}
}
}
9 changes: 9 additions & 0 deletions Data.TRAMS/TramsEducationPerformanceRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Data.Models.KeyStagePerformance;
using Data.TRAMS.Models.EducationPerformance;
Expand Down Expand Up @@ -49,6 +50,14 @@ public async Task<RepositoryResult<EducationPerformance>> GetByAcademyUrn(string
return mappedResult;
}

if (response.StatusCode == HttpStatusCode.NotFound)
{
return new RepositoryResult<EducationPerformance>()
{
Result = new EducationPerformance()
};
}

throw new TramsApiException(response);
}
}
Expand Down
7 changes: 7 additions & 0 deletions Data/Models/KeyStagePerformance/EducationPerformance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ namespace Data.Models.KeyStagePerformance
{
public class EducationPerformance
{
public EducationPerformance()
{
KeyStage2Performance = new List<KeyStage2>();
KeyStage4Performance = new List<KeyStage4>();
KeyStage5Performance = new List<KeyStage5>();
}

//todo: remove this when view models/view component
#region remove
public string ProjectUrn { get;set; }
Expand Down

0 comments on commit af4fd8f

Please sign in to comment.