-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filters to the use-case request. (#47)
* Added filters to the use-case request. * change key-value pair to a list of FilterRequest * change to ctor --------- Co-authored-by: Spencer O'HEGARTY <[email protected]>
- Loading branch information
1 parent
cd946a1
commit 6729df0
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Dfe.Data.SearchPrototype/SearchForEstablishments/ByKeyword/Usecase/FilterRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase; | ||
|
||
/// <summary> | ||
/// Encapsulates a single filter to be applied to the search request | ||
/// </summary> | ||
public class FilterRequest | ||
{ | ||
/// <summary> | ||
/// The name of the filter field | ||
/// </summary> | ||
public string FilterName { get; } | ||
|
||
/// <summary> | ||
/// The readonly list of values of the filter to be included in the filter expression | ||
/// </summary> | ||
public IList<object> FilterValues => _filterValues.AsReadOnly(); | ||
|
||
private IList<object> _filterValues; | ||
|
||
/// <summary> | ||
/// Constructor that initialises the <see cref="FilterName"/> and the <see cref="FilterValues"/> | ||
/// </summary> | ||
/// <param name="filterName"></param> | ||
/// <param name="filterValues"></param> | ||
public FilterRequest(string filterName, IList<object> filterValues) | ||
{ | ||
FilterName = filterName; | ||
_filterValues = filterValues; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ta.SearchPrototype/Tests/SearchForEstablishments/ByKeyword/SearchByKeywordRequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Dfe.Data.SearchPrototype.Tests.SearchForEstablishments.ByKeyword; | ||
|
||
public class SearchByKeywordRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_WithFilterParam_PopulatesFilterRequests() | ||
{ | ||
// arrange | ||
var filterList = new List<FilterRequest>() | ||
{ | ||
new FilterRequest("EducationPhase", new List<object>() {"Primary", "Secondary"}), | ||
new FilterRequest("MaybeATypeCode", new List<object>() {1,2}) | ||
}; | ||
|
||
// act | ||
var request = new SearchByKeywordRequest("searchKeyword", filterList); | ||
|
||
// assert | ||
request.FilterRequests.Should().NotBeNull(); | ||
foreach (var item in filterList) | ||
{ | ||
var matchingRequest = request.FilterRequests!.First(x => x.FilterName == item.FilterName); | ||
matchingRequest.FilterValues.Should().BeEquivalentTo(item.FilterValues); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithNoFilterParam_HasFilterRequestsNull() | ||
{ | ||
// act | ||
var request = new SearchByKeywordRequest("searchKeyword"); | ||
|
||
// assert | ||
request.FilterRequests.Should().BeNull(); | ||
} | ||
} |