Skip to content

Prepare/Academies API: Excel exports fail if too many UKPRNs are queried #724

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task SearchEstablishmentsAsync_ShouldReturnAllEstablishments_WhenCl

// Assert
Assert.NotNull(establishmentDtos);
Assert.Equal(3, establishmentDtos.Count);
Assert.Equal(5, establishmentDtos.Count);
}

[Theory]
Expand All @@ -44,7 +44,7 @@ public async Task SearchEstablishmentsAsync_ShouldReturnAllEstablishments_WhenCl

// Assert
Assert.NotNull(establishmentDtos);
Assert.Equal(3, establishmentDtos.Count);
Assert.Equal(5, establishmentDtos.Count);
}

[Theory]
Expand All @@ -65,4 +65,98 @@ public async Task SearchEstablishmentsAsync_ShouldReturnAllEstablishments_WhenCl
Assert.NotNull(establishmentDtos);
Assert.Equal(2, establishmentDtos.Count);
}

[Theory]
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization<Startup>))]
public async Task EstablishmentsByUrnsAsync_ShouldReturnAllEstablishments_By_UKPRN(
CustomWebApplicationDbContextFactory<Startup> factory,
IEstablishmentsV4Client establishmentsClient)
{
// Arrange
factory.TestClaims = default;

var request = new UrnRequestModel
{
Urns = [22, 33]
};

// Act
var result = await establishmentsClient.GetEstablishmentsByUrnsAsync(request);

// Assert
Assert.NotNull(result);
Assert.Equal(2, result.Count);

var establishment = result.SingleOrDefault(x => x.Urn == request.Urns[0].ToString());
Assert.NotNull(establishment);

establishment = result.SingleOrDefault(x => x.Urn == request.Urns[1].ToString());
Assert.NotNull(establishment);
}

[Theory]
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization<Startup>))]
public async Task EstablishmentsByUrnsAsync_ShouldReturnNotFound(
CustomWebApplicationDbContextFactory<Startup> factory,
IEstablishmentsV4Client establishmentsClient)
{
// Arrange
factory.TestClaims = default;

var request = new UrnRequestModel
{
Urns = [10001, 10002] // those URNs do not exist
};

AcademiesApiException exception = await Assert.ThrowsAsync<AcademiesApiException>(() => establishmentsClient.GetEstablishmentsByUrnsAsync(request));

Assert.Equal(404, exception.StatusCode);
}

[Theory]
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization<Startup>))]
public async Task EstablishmentsByUkprnsAsync_ShouldReturnAllEstablishments_By_UKPRNs(
CustomWebApplicationDbContextFactory<Startup> factory,
IEstablishmentsV4Client establishmentsClient)
{
// Arrange
factory.TestClaims = default;

var request = new UkprnRequestModel
{
Ukprns = ["10060367", "10067112"]
};

// Act
var result = await establishmentsClient.GetEstablishmentsByUkprnsAsync(request);

// Assert
Assert.NotNull(result);
Assert.Equal(2, result.Count);

var establishment = result.SingleOrDefault(x => x.Ukprn == request.Ukprns[0]);
Assert.NotNull(establishment);

establishment = result.SingleOrDefault(x => x.Ukprn == request.Ukprns[1]);
Assert.NotNull(establishment);
}

[Theory]
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization<Startup>))]
public async Task EstablishmentsByUkprnsAsync_ShouldReturnNotFound(
CustomWebApplicationDbContextFactory<Startup> factory,
IEstablishmentsV4Client establishmentsClient)
{
// Arrange
factory.TestClaims = default;

var request = new UkprnRequestModel
{
Ukprns = ["10000000", "4634523"] // those UKPRN do not exist
};

AcademiesApiException exception = await Assert.ThrowsAsync<AcademiesApiException>(() => establishmentsClient.GetEstablishmentsByUkprnsAsync(request));

Assert.Equal(404, exception.StatusCode);
}
}
198 changes: 198 additions & 0 deletions Dfe.AcademiesApi.Client/Generated/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,105 @@ public virtual async System.Threading.Tasks.Task<EstablishmentDto> GetEstablishm
}
}

/// <summary>
/// Retrieves a list of establishments by their Unique Reference Numbers (URNs).
/// </summary>
/// <param name="model">Contains Unique Reference Number (URNs) of the establishments.</param>
/// <returns>Successfully found and returned the establishments.</returns>
/// <exception cref="AcademiesApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<EstablishmentDto>> GetEstablishmentsByUrnsAsync(UrnRequestModel model)
{
return GetEstablishmentsByUrnsAsync(model, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Retrieves a list of establishments by their Unique Reference Numbers (URNs).
/// </summary>
/// <param name="model">Contains Unique Reference Number (URNs) of the establishments.</param>
/// <returns>Successfully found and returned the establishments.</returns>
/// <exception cref="AcademiesApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<EstablishmentDto>> GetEstablishmentsByUrnsAsync(UrnRequestModel model, System.Threading.CancellationToken cancellationToken)
{
if (model == null)
throw new System.ArgumentNullException("model");

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(model, JsonSerializerSettings);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

var urlBuilder_ = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
// Operation Path: "v4/establishments/bulk/urns"
urlBuilder_.Append("v4/establishments/bulk/urns");

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
foreach (var item_ in response_.Headers)
headers_[item_.Key] = item_.Value;
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<System.Collections.ObjectModel.ObservableCollection<EstablishmentDto>>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new AcademiesApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 404)
{
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new AcademiesApiException("Establishments with specified Unique Reference Numbers (URNs) not found.", status_, responseText_, headers_, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new AcademiesApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

/// <summary>
/// Retrieves a list of establishments by their Trust UK Provider Reference Number (UKPRN) identifier.
/// </summary>
Expand Down Expand Up @@ -3380,6 +3479,105 @@ public virtual async System.Threading.Tasks.Task<EstablishmentDto> GetEstablishm
}
}

/// <summary>
/// Retrieves a list of establishments by their UKPRNs.
/// </summary>
/// <param name="model">Contains UKPRNs of the establishments.</param>
/// <returns>Successfully found and returned the establishments.</returns>
/// <exception cref="AcademiesApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<EstablishmentResponse>> GetEstablishmentsByUkprnsAsync(UkprnRequestModel model)
{
return GetEstablishmentsByUkprnsAsync(model, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Retrieves a list of establishments by their UKPRNs.
/// </summary>
/// <param name="model">Contains UKPRNs of the establishments.</param>
/// <returns>Successfully found and returned the establishments.</returns>
/// <exception cref="AcademiesApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<EstablishmentResponse>> GetEstablishmentsByUkprnsAsync(UkprnRequestModel model, System.Threading.CancellationToken cancellationToken)
{
if (model == null)
throw new System.ArgumentNullException("model");

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(model, JsonSerializerSettings);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

var urlBuilder_ = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
// Operation Path: "v4/establishments/bulk/ukprns"
urlBuilder_.Append("v4/establishments/bulk/ukprns");

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
foreach (var item_ in response_.Headers)
headers_[item_.Key] = item_.Value;
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<System.Collections.ObjectModel.ObservableCollection<EstablishmentResponse>>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new AcademiesApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 404)
{
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new AcademiesApiException("Establishments with specified UKPRNs not found.", status_, responseText_, headers_, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new AcademiesApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

protected struct ObjectResponseResult<T>
{
public ObjectResponseResult(T responseObject, string responseText)
Expand Down
Loading
Loading