Skip to content

Commit affef06

Browse files
author
Bart Koelman
committed
TestContext: Only dispose factory when created
1 parent f116338 commit affef06

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public void Fails_at_startup_when_multiple_controllers_exist_for_same_resource_t
2222
// Assert
2323
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage("Multiple controllers found for resource type 'knownResources'.");
2424
}
25-
26-
public override void Dispose()
27-
{
28-
// Prevents crash when test cleanup tries to access lazily constructed Factory.
29-
}
3025
}

test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/UnknownResourceControllerTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public void Fails_at_startup_when_using_controller_for_resource_type_that_is_not
2222
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage($"Controller '{typeof(UnknownResourcesController)}' " +
2323
$"depends on resource type '{typeof(UnknownResource)}', which does not exist in the resource graph.");
2424
}
25-
26-
public override void Dispose()
27-
{
28-
// Prevents crash when test cleanup tries to access lazily constructed Factory.
29-
}
3025
}

test/TestBuildingBlocks/IntegrationTestContext.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ private WebApplicationFactory<TStartup> CreateFactory()
103103
return factoryWithConfiguredContentRoot;
104104
}
105105

106-
public virtual void Dispose()
106+
public void Dispose()
107107
{
108-
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();
108+
if (_lazyFactory.IsValueCreated)
109+
{
110+
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();
109111

110-
Factory.Dispose();
112+
_lazyFactory.Value.Dispose();
113+
}
111114
}
112115

113116
public void ConfigureLogging(Action<ILoggingBuilder> loggingConfiguration)

0 commit comments

Comments
 (0)