Skip to content

Commit 21a9891

Browse files
authored
remove education phase class to match field with new data (#37)
* remove education phase class to match field with new data * Replace statusCode field to StatusName , amends done as necessary * Correct few comments to follow with the previous changes * Correct tests to add exception message. As we test each of the fields, tests passed before due to exception thrown, not necessarily due to exception thrown due to the field we've tested.
1 parent c39621f commit 21a9891

File tree

9 files changed

+111
-197
lines changed

9 files changed

+111
-197
lines changed

Dfe.Data.SearchPrototype/Infrastructure/Establishment.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,11 @@ public class Establishment
3838
/// </summary>
3939
public string? TYPEOFESTABLISHMENTNAME { get; set; }
4040
/// <summary>
41-
/// "1" if the establishment includes the Primary phase of education
42-
/// "0" if the establishment does not include the Primary phase of education
41+
/// The education phase of the retrieved establishment result
4342
/// </summary>
44-
public string? ISPRIMARY { get; set; }
43+
public string? PHASEOFEDUCATION { get; set; }
4544
/// <summary>
46-
/// "1" if the establishment includes the secondary phase of education
47-
/// "0" if the establishment does not include the secondary phase of education
45+
/// Status of retrieved establishment result.
4846
/// </summary>
49-
public string? ISSECONDARY { get; set; }
50-
/// <summary>
51-
/// "1" if the establishment includes the post 16 phase of education
52-
/// "0" if the establishment does not include the post 16 phase of education
53-
/// </summary>
54-
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; }
47+
public string? ESTABLISHMENTSTATUSNAME { get; set; }
6048
}

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ namespace Dfe.Data.SearchPrototype.Infrastructure.Mappers;
1010
public sealed class AzureSearchResultToEstablishmentMapper : IMapper<Establishment, SearchForEstablishments.Models.Establishment>
1111
{
1212
private readonly IMapper<Establishment, Address> _addressMapper;
13-
private readonly IMapper<Establishment, EducationPhase> _educationPhaseMapper;
1413

1514
/// <summary>
1615
/// Constructor
1716
/// </summary>
1817
/// <param name="addressMapper">Address mapper instance</param>
19-
/// <param name="educationPhaseMapper">EducationPhase mapper instance</param>
2018
public AzureSearchResultToEstablishmentMapper(
21-
IMapper<Establishment, Address> addressMapper,
22-
IMapper<Establishment, EducationPhase> educationPhaseMapper)
19+
IMapper<Establishment, Address> addressMapper)
2320
{
2421
_addressMapper = addressMapper;
25-
_educationPhaseMapper = educationPhaseMapper;
2622
}
2723

2824
/// <summary>
@@ -43,20 +39,16 @@ public SearchForEstablishments.Models.Establishment MapFrom(Establishment input)
4339
{
4440
ArgumentException.ThrowIfNullOrEmpty(input.id, nameof(input.id));
4541
ArgumentException.ThrowIfNullOrEmpty(input.ESTABLISHMENTNAME, nameof(input.ESTABLISHMENTNAME));
46-
ArgumentException.ThrowIfNullOrEmpty(input.TYPEOFESTABLISHMENTNAME, nameof(input.ESTABLISHMENTNAME));
47-
48-
var statusCode = input.ESTABLISHMENTSTATUSCODE == "1"
49-
? EstablishmentStatusCode.Open
50-
: input.ESTABLISHMENTSTATUSCODE == "0"
51-
? EstablishmentStatusCode.Closed
52-
: EstablishmentStatusCode.Unknown;
42+
ArgumentException.ThrowIfNullOrEmpty(input.TYPEOFESTABLISHMENTNAME, nameof(input.TYPEOFESTABLISHMENTNAME));
43+
ArgumentException.ThrowIfNullOrEmpty(input.PHASEOFEDUCATION, nameof(input.PHASEOFEDUCATION));
44+
ArgumentException.ThrowIfNullOrEmpty(input.ESTABLISHMENTSTATUSNAME, nameof(input.ESTABLISHMENTSTATUSNAME));
5345

5446
return new(
5547
urn: input.id,
5648
name: input.ESTABLISHMENTNAME,
5749
address: _addressMapper.MapFrom(input),
5850
establishmentType: input.TYPEOFESTABLISHMENTNAME,
59-
educationPhase: _educationPhaseMapper.MapFrom(input),
60-
establishmentStatusCode: statusCode);
51+
phaseOfEducation: input.PHASEOFEDUCATION,
52+
establishmentStatusName: input.ESTABLISHMENTSTATUSNAME);
6153
}
6254
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ public sealed class AzureSearchResponseToEstablishmentResultMapperTests
1515
IMapper<Establishment, SearchForEstablishments.Models.Establishment> _searchResultToEstablishmentMapper;
1616
IMapper<Response<SearchResults<Establishment>>, EstablishmentResults> _searchResponseMapper;
1717
IMapper<Establishment, Address> _searchResultToAddressMapper;
18-
IMapper<Establishment, EducationPhase> _searchResultToEducationPhaseMapper;
1918

2019
public AzureSearchResponseToEstablishmentResultMapperTests()
2120
{
22-
_searchResultToEducationPhaseMapper = new AzureSearchResultToEducationPhaseMapper();
2321
_searchResultToAddressMapper = new AzureSearchResultToAddressMapper();
2422
_searchResultToEstablishmentMapper =
25-
new AzureSearchResultToEstablishmentMapper(_searchResultToAddressMapper, _searchResultToEducationPhaseMapper);
23+
new AzureSearchResultToEstablishmentMapper(_searchResultToAddressMapper);
2624
_searchResponseMapper =
2725
new AzureSearchResponseToEstablishmentResultMapper(_searchResultToEstablishmentMapper);
2826
}

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

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@ public sealed class AzureSearchResultToEstablishmentMapperTests
1111
{
1212
IMapper<Establishment, SearchForEstablishments.Models.Establishment> _establishmentMapper;
1313
IMapper<Establishment, Address> _addressMapper;
14-
IMapper<Establishment, EducationPhase> _educationPhaseMapper;
1514

1615
public AzureSearchResultToEstablishmentMapperTests()
1716
{
1817
_addressMapper = new AzureSearchResultToAddressMapper();
19-
_educationPhaseMapper = new AzureSearchResultToEducationPhaseMapper();
20-
_establishmentMapper = new AzureSearchResultToEstablishmentMapper(_addressMapper, _educationPhaseMapper);
18+
_establishmentMapper = new AzureSearchResultToEstablishmentMapper(_addressMapper);
2119
}
2220

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

3227
// act
3328
SearchForEstablishments.Models.Establishment? result = _establishmentMapper.MapFrom(establishmentFake);
@@ -41,10 +36,9 @@ public void MapFrom_With_Valid_Search_Result_Returns_Configured_Establishment(st
4136
result.Address.Address3.Should().Be(establishmentFake.ADDRESS3);
4237
result.Address.Town.Should().Be(establishmentFake.TOWN);
4338
result.Address.Postcode.Should().Be(establishmentFake.POSTCODE);
44-
result.EducationPhase.IsPrimary.Should().Be(establishmentFake.ISPRIMARY == "1" ? true : false);
45-
result.EducationPhase.IsSecondary.Should().Be(establishmentFake.ISSECONDARY == "1" ? true : false);
46-
result.EducationPhase.IsPost16.Should().Be(establishmentFake.ISPOST16 == "1" ? true : false);
47-
result.EstablishmentStatusCode.Should().Be(expectedStatusCode);
39+
result.EstablishmentType.Should().Be(establishmentFake.TYPEOFESTABLISHMENTNAME);
40+
result.PhaseOfEducation.Should().Be(establishmentFake.PHASEOFEDUCATION);
41+
result.EstablishmentStatusName.Should().Be(establishmentFake.ESTABLISHMENTSTATUSNAME);
4842
}
4943

5044
[Fact]
@@ -64,65 +58,111 @@ public void MapFrom_With_Null_Search_Result_Throws_Expected_Argument_Null_Except
6458
[Fact]
6559
public void MapFrom_With_Null_id_Throws_Expected_Argument_Exception()
6660
{
67-
// arrange.
68-
const string EstablishmentName = "Test Establishment";
69-
70-
// act.
61+
// arrange
7162
var establishmentFake = new Establishment()
7263
{
7364
id = null!,
74-
ESTABLISHMENTNAME = EstablishmentName
65+
ESTABLISHMENTNAME = "Test Establishment",
66+
TYPEOFESTABLISHMENTNAME = "secondaryFake",
67+
ESTABLISHMENTSTATUSNAME = "fake status",
68+
PHASEOFEDUCATION = "fake primary"
7569
};
7670

77-
// act.
71+
// act, assert
7872
_establishmentMapper
7973
.Invoking(mapper =>
8074
mapper.MapFrom(establishmentFake))
8175
.Should()
82-
.Throw<ArgumentException>();
76+
.Throw<ArgumentException>()
77+
.WithMessage("Value cannot be null. (Parameter 'id')");
8378
}
8479

8580
[Fact]
8681
public void MapFrom_With_Null_Name_Throws_Expected_Argument_Exception()
8782
{
88-
// arrange.
89-
const string EstablishmentId = "123456";
90-
91-
// act.
83+
// arrange
9284
var establishmentFake = new Establishment()
9385
{
94-
id = EstablishmentId,
86+
id = "123456",
87+
TYPEOFESTABLISHMENTNAME = "secondaryFake",
88+
ESTABLISHMENTSTATUSNAME = "fake status",
89+
PHASEOFEDUCATION = "fake primary",
9590
ESTABLISHMENTNAME = null!
9691
};
9792

98-
// act.
93+
// act, assert
9994
_establishmentMapper
10095
.Invoking(mapper =>
10196
mapper.MapFrom(establishmentFake))
10297
.Should()
103-
.Throw<ArgumentException>();
98+
.Throw<ArgumentException>()
99+
.WithMessage("Value cannot be null. (Parameter 'ESTABLISHMENTNAME')");
104100
}
105101

106102
[Fact]
107-
public void MapFrom_With_NullIsPrimary_Throws_Expected_Argument_Exception()
103+
public void MapFrom_With_NullPhaseOfEducation_Throws_Expected_Argument_Exception()
108104
{
109-
// arrange.
110-
const string EstablishmentId = "123456";
105+
// arrange
106+
var establishmentFake = new Establishment()
107+
{
108+
id = "123456",
109+
ESTABLISHMENTNAME = "Test Establishment",
110+
TYPEOFESTABLISHMENTNAME = "secondaryFake",
111+
ESTABLISHMENTSTATUSNAME = "fake status",
112+
PHASEOFEDUCATION = null!
113+
};
111114

112-
// act.
115+
// act, assert
116+
_establishmentMapper
117+
.Invoking(mapper =>
118+
mapper.MapFrom(establishmentFake))
119+
.Should()
120+
.Throw<ArgumentException>()
121+
.WithMessage("Value cannot be null. (Parameter 'PHASEOFEDUCATION')");
122+
}
123+
124+
[Fact]
125+
public void MapFrom_With_NullTypeOfEstablishment_Throws_Expected_Argument_Exception()
126+
{
127+
// arrange
113128
var establishmentFake = new Establishment()
114129
{
115-
id = EstablishmentId,
130+
id = "1111",
116131
ESTABLISHMENTNAME = "Test Establishment",
117-
ISPRIMARY = null!
132+
PHASEOFEDUCATION = "primaryFake",
133+
ESTABLISHMENTSTATUSNAME = "closedFake",
134+
TYPEOFESTABLISHMENTNAME = null!
118135
};
119136

120-
// act.
137+
// act, assert
138+
_establishmentMapper
139+
.Invoking(mapper =>
140+
mapper.MapFrom(establishmentFake))
141+
.Should()
142+
.Throw<ArgumentException>()
143+
.WithMessage("Value cannot be null. (Parameter 'TYPEOFESTABLISHMENTNAME')");
144+
}
145+
146+
[Fact]
147+
public void MapFrom_With_NullEstablishmentStatus_Throws_Expected_Argument_Exception()
148+
{
149+
// arrange
150+
var establishmentFake = new Establishment()
151+
{
152+
id = "1111",
153+
ESTABLISHMENTNAME = "Test Establishment",
154+
PHASEOFEDUCATION = "primaryFake",
155+
TYPEOFESTABLISHMENTNAME = "fakeType",
156+
ESTABLISHMENTSTATUSNAME = null!
157+
};
158+
159+
// act, assert
121160
_establishmentMapper
122161
.Invoking(mapper =>
123162
mapper.MapFrom(establishmentFake))
124163
.Should()
125-
.Throw<ArgumentException>();
164+
.Throw<ArgumentException>()
165+
.WithMessage("Value cannot be null. (Parameter 'ESTABLISHMENTSTATUSNAME')");
126166
}
127167

128168
[Theory]
@@ -139,14 +179,13 @@ public void MapFrom_With_NullAddressValues_Returns_Configured_Establishment(
139179
id = "000000",
140180
ESTABLISHMENTNAME = "fakename",
141181
TYPEOFESTABLISHMENTNAME = "FakeType",
142-
ISPRIMARY = "1",
143-
ISPOST16 = "0",
144-
ISSECONDARY = "0",
182+
PHASEOFEDUCATION = "fakePhaseOfEducation",
145183
STREET = street,
146184
LOCALITY = locality,
147185
ADDRESS3 = address3,
148186
TOWN = town,
149-
POSTCODE = postcode
187+
POSTCODE = postcode,
188+
ESTABLISHMENTSTATUSNAME = "fakeStatus"
150189
};
151190

152191
// act

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ private static string GetEstablishmentTypeFake() =>
2929
new Bogus.Faker().Random.Word();
3030

3131
private static string GetEstablishmentEducationPhaseFake() =>
32-
new Bogus.Faker().Random.Int(0, 1).ToString();
32+
new Bogus.Faker().Random.Word();
3333

34-
private static string GetEstablishmentStatusCodeFake() =>
35-
new Bogus.Faker().Random.Int(0, 1).ToString();
34+
private static string GetEstablishmentStatusNameFake() =>
35+
new Bogus.Faker().Random.Word();
3636

3737
public static Establishment Create()
3838
{
39-
var educationPhase = new EducationPhase(
40-
isPrimary: GetEstablishmentEducationPhaseFake(),
41-
isSecondary: GetEstablishmentEducationPhaseFake(),
42-
isPost16: GetEstablishmentEducationPhaseFake());
43-
4439
return new Establishment()
4540
{
4641
id = GetEstablishmentIdentifierFake(),
@@ -51,18 +46,9 @@ public static Establishment Create()
5146
TOWN = GetEstablishmentTownFake(),
5247
POSTCODE = GetEstablishmentPostcodeFake(),
5348
TYPEOFESTABLISHMENTNAME = GetEstablishmentTypeFake(),
54-
ESTABLISHMENTSTATUSCODE = GetEstablishmentStatusCodeFake(),
55-
ISPRIMARY = GetEstablishmentEducationPhaseFake(),
56-
ISSECONDARY = GetEstablishmentEducationPhaseFake(),
57-
ISPOST16 = GetEstablishmentEducationPhaseFake()
49+
ESTABLISHMENTSTATUSNAME = GetEstablishmentStatusNameFake(),
50+
PHASEOFEDUCATION = GetEstablishmentEducationPhaseFake()
5851
};
5952
}
6053

61-
public static Establishment CreateWithStatusCode(string status)
62-
{
63-
var searchResultFake = Create();
64-
searchResultFake.ESTABLISHMENTSTATUSCODE = status;
65-
return searchResultFake;
66-
}
67-
6854
}

0 commit comments

Comments
 (0)