Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed logic for returning trusts and associated address information #324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions TramsDataApi.Test/UseCases/SearchTrustsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,12 +33,10 @@ public void SearchTrusts_ReturnsEmptyList_WhenNoTrustsFound()
result.Should().BeEquivalentTo(new List<TrustSummaryResponse>());
}

[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
private IList<Group> Test(string groupName)
{
var groupName = "groupName";

var expectedTrusts = Builder<Group>.CreateListOfSize(10)
return Builder<Group>.CreateListOfSize(10)
.TheFirst(5)
.With(g => g.GroupType = "Trust")
.TheNext(3)
Expand All @@ -47,6 +46,14 @@ public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
.All()
.With(g => g.GroupName = groupName)
.Build();
}

[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
{
var groupName = "groupName";

var expectedTrusts = Test(groupName);

var trustsGateway = new Mock<ITrustGateway>();
var establishmentsGateway = new Mock<IEstablishmentGateway>();
Expand All @@ -69,6 +76,45 @@ public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()

result.Should().BeEquivalentTo(expected);
}
[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponsesWithAddresses_WhenTrustsFound()
{
var groupName = "groupName";

var expectedGroups = Test(groupName);

IDictionary<String, Trust> trusts = new Dictionary<String, Trust>();

foreach (var expectedGroup in expectedGroups)
{
var expectedTrust = Builder<Trust>
.CreateNew()
.With(g => g.TrustRef = expectedGroup.GroupId)
.Build();
trusts.Add(expectedGroup.GroupId, expectedTrust);
}

var trustsGateway = new Mock<ITrustGateway>();
var establishmentsGateway = new Mock<IEstablishmentGateway>();

trustsGateway.Setup(g => g.SearchGroups(1, 10, groupName, string.Empty, string.Empty))
.Returns((expectedGroups, expectedGroups.Count));

trustsGateway.Setup(m => m.GetIfdTrustsByTrustRef(It.IsAny<string[]>()))
.Returns(trusts.Values.ToList());

establishmentsGateway.Setup(g => g.GetByTrustUids(It.IsAny<string[]>()))
.Returns(new List<Establishment>());

var expected = expectedGroups.
Select(e => TrustSummaryResponseFactory.Create(e, new List<Establishment>(), trusts[e.GroupId]))
.ToList();

var searchTrusts = new SearchTrusts(trustsGateway.Object, establishmentsGateway.Object);
var (result, _) = searchTrusts.Execute(1, 10, groupName);

result.Should().BeEquivalentTo(expected);
}

[Fact]
public void SearchTrusts_ShouldGetTrustsWithEstablishments_WhenTrustsAndEstablishmentsAreFound()
Expand Down Expand Up @@ -132,5 +178,6 @@ public void SearchTrusts_WithoutEstablishments()
var (result, _) = searchTrusts.Execute(1, 10, ukPrn: ukprn, includeEstablishments: false);
result.Should().BeEquivalentTo(expected);
}

}
}
2 changes: 1 addition & 1 deletion TramsDataApi/UseCases/SearchTrusts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public SearchTrusts(ITrustGateway trustGateway, IEstablishmentGateway establishm
return (
groups.Select(group =>
{
var trust = trustsForGroup.FirstOrDefault(e => e.TrustRef == group.GroupId);
var establishments = establishmentsForGroup.Where(e => e.TrustsCode == group.GroupUid);
var trust = trustsForGroup.FirstOrDefault(e => e.TrustRef == group.GroupUid);
return TrustSummaryResponseFactory.Create(group, establishments, trust);
}).ToArray(),
recordCount
Expand Down