Skip to content

Commit

Permalink
Merge branch 'release/153650-trusts-not-returning-academies'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestock-nimble committed Jan 23, 2024
2 parents d3ad5e7 + 9ed88b5 commit a7bc32f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
25 changes: 25 additions & 0 deletions TramsDataApi.Test/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using TramsDataApi.Extensions;
using Xunit;

namespace TramsDataApi.Test.Extensions
{
public class StringExtensionsTests
{
[Theory]
[InlineData("123", 123)]
[InlineData("456", 456)]
[InlineData("0", 0)]
[InlineData("-789", -789)]
[InlineData("abc", 0)] // Invalid string
[InlineData(null, 0)] // Null string
[InlineData("", 0)] // Empty string
public void ToInt_ReturnsExpectedResult(string input, int expectedResult)
{
// Act
int result = input.ToInt();

// Assert
Assert.Equal(expectedResult, result);
}
}
}
16 changes: 8 additions & 8 deletions TramsDataApi.Test/Integration/V3/TrustsV3IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public async Task ShouldReturnEstablishmentDataAgainstOpenTrust_WhenTrustHasAnEs
string TrustUKPRN = "123456789";

var closedTrustGroup = _fixture.Build<Group>()
.With(f => f.GroupUid, "1")
.With(f => f.GroupUid, "234")
.With(f => f.GroupId, groupID)
.With(f => f.GroupName, TrustName)
.With(f => f.Ukprn, TrustUKPRN)
Expand All @@ -208,14 +208,14 @@ public async Task ShouldReturnEstablishmentDataAgainstOpenTrust_WhenTrustHasAnEs
.Create();

var openTrustGroup = _fixture.Build<Group>()
.With(f => f.GroupUid, "2")
.With(f => f.GroupUid, "1234")
.With(f => f.GroupId, groupID)
.With(f => f.GroupName, TrustName)
.With(f => f.Ukprn, TrustUKPRN)
.With(f => f.GroupStatus, "Open")
.With(f => f.GroupStatusCode, "OPEN")
.With(f => f.GroupType, "Multi-academy trust")
.Create();
.With(f => f.GroupName, TrustName)
.With(f => f.Ukprn, TrustUKPRN)
.With(f => f.GroupStatus, "Open")
.With(f => f.GroupStatusCode, "OPEN")
.With(f => f.GroupType, "Multi-academy trust")
.Create();

_legacyDbContext.Group.AddRange(closedTrustGroup, openTrustGroup);

Expand Down
10 changes: 10 additions & 0 deletions TramsDataApi/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TramsDataApi.Extensions
{
public static class StringExtensions
{
public static int ToInt(this string value)
{
return int.TryParse(value, out var result) ? result : 0;
}
}
}
13 changes: 7 additions & 6 deletions TramsDataApi/Gateways/TrustGateway.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using TramsDataApi.DatabaseModels;
using TramsDataApi.Extensions;

namespace TramsDataApi.Gateways
{
public class TrustGateway : ITrustGateway
public class TrustGateway : ITrustGateway
{
private readonly LegacyTramsDbContext _dbContext;

Expand All @@ -24,7 +23,11 @@ public Group GetGroupByUkPrn(string ukPrn)

public Group GetLatestGroupByUkPrn(string ukPrn)
{
return _dbContext.Group.OrderByDescending(f=> f.GroupUid).FirstOrDefault(g => g.Ukprn == ukPrn);
var group = _dbContext.Group.Where(g => g.Ukprn == ukPrn).ToList();

var result = group.OrderByDescending(g => g.GroupUid.ToInt()).FirstOrDefault();

return result;
}

public Trust GetIfdTrustByGroupId(string groupId)
Expand Down Expand Up @@ -89,7 +92,5 @@ public TrustMasterData GetMstrTrustByGroupId(string groupId)
{
return _dbContext.TrustMasterData.FirstOrDefault(t => t.GroupID == groupId);
}


}
}

0 comments on commit a7bc32f

Please sign in to comment.