Skip to content

Commit c282fc6

Browse files
committed
Enhanced the unit test that ensures the functions are resolvable by having it pick up all functions automagically.
1 parent 3c4f676 commit c282fc6

File tree

2 files changed

+12
-53
lines changed
  • src
    • GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp/Extensions
    • GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Tests

2 files changed

+12
-53
lines changed

src/GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Tests/ProgramTests.cs

+12-52
Original file line numberDiff line numberDiff line change
@@ -248,66 +248,26 @@ public void GivenNotConfigured_WhenResolvingAzureSearchOptions_ThenShouldResolve
248248

249249
public class ResolveFunctionTests : ProgramTests
250250
{
251-
[Fact]
252-
public void Can_resolve_OnReleaseSlugChangedFunction()
253-
{
254-
// ARRANGE
255-
var sut = GetSut();
256-
257-
// ACT
258-
var actual = ActivatorUtilities.CreateInstance<OnReleaseSlugChangedFunction>(sut.Services);
259-
260-
// ASSERT
261-
Assert.NotNull(actual);
262-
}
263-
264-
[Fact]
265-
public void Can_resolve_OnReleaseVersionPublishedFunction()
266-
{
267-
// ARRANGE
268-
var sut = GetSut();
269-
270-
// ACT
271-
var actual = ActivatorUtilities.CreateInstance<OnReleaseVersionPublishedFunction>(sut.Services);
272-
273-
// ASSERT
274-
Assert.NotNull(actual);
275-
}
276-
277-
[Fact]
278-
public void Can_resolve_OnThemeUpdatedFunction()
279-
{
280-
// ARRANGE
281-
var sut = GetSut();
282-
283-
// ACT
284-
var actual = ActivatorUtilities.CreateInstance<OnThemeUpdatedFunction>(sut.Services);
285-
286-
// ASSERT
287-
Assert.NotNull(actual);
288-
}
289-
290-
[Fact]
291-
public void Can_resolve_RefreshSearchableDocumentFunction()
251+
public static TheoryData<Type> GetAzureFunctionTypes()
292252
{
293-
// ARRANGE
294-
var sut = GetSut();
295-
296-
// ACT
297-
var actual = ActivatorUtilities.CreateInstance<RefreshSearchableDocumentFunction>(sut.Services);
298-
299-
// ASSERT
300-
Assert.NotNull(actual);
253+
var types = typeof(Program)
254+
.Assembly
255+
.GetTypes()
256+
.Where(type => type.Namespace?.StartsWith("GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp.Functions.") == true)
257+
.Where(type => type.Name.EndsWith("Function"));
258+
259+
return new TheoryData<Type>(types);
301260
}
302261

303-
[Fact]
304-
public void Can_resolve_ReindexSearchableDocumentFunction()
262+
[Theory]
263+
[MemberData(nameof(GetAzureFunctionTypes))]
264+
public void Can_resolve_AzureFunction(Type functionType)
305265
{
306266
// ARRANGE
307267
var sut = GetSut();
308268

309269
// ACT
310-
var actual = ActivatorUtilities.CreateInstance<ReindexSearchableDocumentsFunction>(sut.Services);
270+
var actual = ActivatorUtilities.CreateInstance(sut.Services, functionType);
311271

312272
// ASSERT
313273
Assert.NotNull(actual);

src/GovUk.Education.ExploreEducationStatistics.Content.Search.FunctionApp/Extensions/HostBuilderExtension.cs

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static IHost BuildHost(this IHostBuilder hostBuilder) => hostBuilder
7272
});
7373
clientBuilder.UseCredential(new DefaultAzureCredential());
7474
})
75-
.AddTransient<IContentApiClient, ContentApiClient>()
7675
.AddHttpClient<IContentApiClient, ContentApiClient>(
7776
(provider, httpClient) =>
7877
{

0 commit comments

Comments
 (0)