Skip to content

Commit 7fc38a6

Browse files
committed
Add status
1 parent 9f86483 commit 7fc38a6

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

Dfe.Data.SearchPrototype/Infrastructure/Establishment.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public class Establishment
5252
/// "0" if the establishment does not include the post 16 phase of education
5353
/// </summary>
5454
public string? ISPOST16 { get; set; }
55+
/// <summary>
56+
/// The status of the establishment of the retrieved establishment result
57+
/// If "1" establishment status is open if "0" it's closed
58+
/// </summary>
59+
public string? ESTABLISHMENTSTATUSCODE { get; set; }
5560
}

Dfe.Data.SearchPrototype/Infrastructure/Mappers/AzureSearchResultToEstablishmentMapper.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ public SearchForEstablishments.Establishment MapFrom(Establishment input)
4545
ArgumentException.ThrowIfNullOrEmpty(input.ESTABLISHMENTNAME, nameof(input.ESTABLISHMENTNAME));
4646
ArgumentException.ThrowIfNullOrEmpty(input.TYPEOFESTABLISHMENTNAME, nameof(input.ESTABLISHMENTNAME));
4747

48-
return new(urn: input.id,
48+
var statusCode = input.ESTABLISHMENTSTATUSCODE == "1"
49+
? StatusCode.Open
50+
: input.ESTABLISHMENTSTATUSCODE == "0"
51+
? StatusCode.Closed
52+
: StatusCode.Unknown;
53+
54+
return new(
55+
urn: input.id,
4956
name: input.ESTABLISHMENTNAME,
5057
address: _addressMapper.MapFrom(input),
5158
establishmentType: input.TYPEOFESTABLISHMENTNAME,
52-
educationPhase: _educationPhaseMapper.MapFrom(input));
59+
educationPhase: _educationPhaseMapper.MapFrom(input),
60+
establishmentStatusCode: statusCode);
5361
}
5462
}

Dfe.Data.SearchPrototype/Infrastructure/Tests/Mappers/AzureSearchResultToEstablishmentMapperTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Dfe.Data.SearchPrototype.Common.Mappers;
22
using Dfe.Data.SearchPrototype.Infrastructure.Mappers;
33
using Dfe.Data.SearchPrototype.Infrastructure.Tests.TestDoubles;
4+
using Dfe.Data.SearchPrototype.SearchForEstablishments;
45
using FluentAssertions;
56
using Xunit;
67

@@ -19,11 +20,14 @@ public AzureSearchResultToEstablishmentMapperTests()
1920
_establishmentMapper = new AzureSearchResultToEstablishmentMapper(_addressMapper, _educationPhaseMapper);
2021
}
2122

22-
[Fact]
23-
public void MapFrom_With_Valid_Search_Result_Returns_Configured_Establishment()
23+
[Theory]
24+
[InlineData("1", StatusCode.Open)]
25+
[InlineData("0", StatusCode.Closed)]
26+
[InlineData("", StatusCode.Unknown)]
27+
public void MapFrom_With_Valid_Search_Result_Returns_Configured_Establishment(string statusCode, StatusCode expectedStatusCode)
2428
{
2529
// arrange
26-
Establishment establishmentFake = EstablishmentTestDouble.Create();
30+
Establishment establishmentFake = EstablishmentTestDouble.CreateWithStatusCode(statusCode);
2731

2832
// act
2933
SearchForEstablishments.Establishment? result = _establishmentMapper.MapFrom(establishmentFake);
@@ -40,6 +44,7 @@ public void MapFrom_With_Valid_Search_Result_Returns_Configured_Establishment()
4044
result.EducationPhase.IsPrimary.Should().Be(establishmentFake.ISPRIMARY == "1" ? true : false);
4145
result.EducationPhase.IsSecondary.Should().Be(establishmentFake.ISSECONDARY == "1" ? true : false);
4246
result.EducationPhase.IsPost16.Should().Be(establishmentFake.ISPOST16 == "1" ? true : false);
47+
result.EstablishmentStatusCode.Should().Be(expectedStatusCode);
4348
}
4449

4550
[Fact]

Dfe.Data.SearchPrototype/SearchForEstablishments/Establishment.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public class Establishment
2222
/// </summary>
2323
public string EstablishmentType { get; }
2424
public EducationPhase EducationPhase { get; }
25-
25+
/// <summary>
26+
/// The read-only status of the establishment.
27+
/// </summary>
28+
public StatusCode EstablishmentStatusCode { get; }
2629
/// <summary>
2730
/// Establishes an immutable establishment instance via the constructor arguments specified.
2831
/// </summary>
@@ -38,12 +41,16 @@ public class Establishment
3841
/// <param name="establishmentType">
3942
/// The type of the given establishment.
4043
/// </param>
41-
public Establishment(string urn, string name, Address address, string establishmentType, EducationPhase educationPhase)
44+
/// /// <param name="establishmentStatusCode">
45+
/// The status of the given establishment.
46+
/// </param>
47+
public Establishment(string urn, string name, Address address, string establishmentType, EducationPhase educationPhase, StatusCode establishmentStatusCode)
4248
{
4349
Urn = urn;
4450
Name = name;
4551
Address = address;
4652
EstablishmentType = establishmentType;
4753
EducationPhase = educationPhase;
54+
EstablishmentStatusCode = establishmentStatusCode;
4855
}
4956
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Dfe.Data.SearchPrototype.SearchForEstablishments;
2+
3+
public enum StatusCode
4+
{
5+
Closed = 0,
6+
Open = 1,
7+
Unknown
8+
}

Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/TestDoubles/EstablishmentTestDouble.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ private static string GetEstablishmentPostcodeFake() =>
3030
private static string GetEstablishmentTypeFake() =>
3131
new Faker().Random.Word();
3232

33+
private static StatusCode GetEstablishmentStatusCodeFake() =>
34+
(StatusCode)new Faker().Random.Int(0, 2);
35+
3336
private static string GetEstablishmentEducationPhaseFake() =>
3437
new Faker().Random.Int(0, 1).ToString();
3538

@@ -54,7 +57,8 @@ public static Establishment Create()
5457
name: GetEstablishmentNameFake(),
5558
address: address,
5659
establishmentType: GetEstablishmentTypeFake(),
57-
educationPhase: educationPhase
60+
educationPhase: educationPhase,
61+
establishmentStatusCode: GetEstablishmentStatusCodeFake()
5862
);
5963
}
6064
}

0 commit comments

Comments
 (0)