Skip to content

Commit

Permalink
Better exception messages from TestServiceProvider when registering s…
Browse files Browse the repository at this point in the history
…ervices after first render. Closes #336.
  • Loading branch information
egil committed Mar 9, 2021
1 parent f77bb41 commit 57e8e1c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bunit.core/TestServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ public bool Remove(ServiceDescriptor item)
private void CheckInitializedAndThrow()
{
if (IsProviderInitialized)
throw new InvalidOperationException("Services cannot be added to provider after it has been initialized.");
{
throw new InvalidOperationException(
$"New services/implementations cannot be registered with the " +
$"Services provider in a TestContext, after the first services has been retrieved " +
$"from it using e.g. the GetService or GetRequiredService methods. " +
$"This typically happens when a component is rendered, so make " +
$"sure all services are added before that.");
}
}
}
}

0 comments on commit 57e8e1c

Please sign in to comment.