-
Notifications
You must be signed in to change notification settings - Fork 123
How to mock Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet? #890
Comments
can you add like this in your startup.cs ? |
Thanks for the suggestion.
Which sounds like I need to add a mock I guess I could create an interface that both the unit test and production runtimes will use, and then from that I can call JavaScriptSnippet.FullScript. |
@Daniel-Khodabakhsh do you need any additional help? Closing this for now. reopen if you have questions. |
@cijothomas May I change this question into a feature request? |
Will tag as enhancement. We gladly accept a pull request, if you have time for this as well. |
Thanks @cijothomas! |
Just saw it. We'll review it next week. |
Background
I have a project which is testing views served from a class library (
Microsoft.NET.Sdk.Razor
).In order to do this, the test project itself is of MsBuild SDK type
Microsoft.NET.Sdk.Web
.The views in the class library use the injected
Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet
.When I run a unit test where an
HttpClient
tries to render the view, I get the following error:Question
How can I mock
Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet
?I tried adding singleton via my test's
StaptUp.cs - ConfigureServices(IServiceCollection ...)
:services.AddSingleton(JavaScriptSnippet, JavaScriptSnippet);
but this fails becauseJavaScriptSnippet
is a type.The
JavaScriptSnippet
metadata doesn't show any interface it's using so I'm not able to register my own mock.Repro Steps
Microsoft.NET.Sdk.Razor
and add views which useMicrosoft.ApplicationInsights.AspNetCore.JavaScriptSnippet
.Microsoft.NET.Sdk.Web
and add the class library as a project reference.Actual Behavior
The above callstack occurs.
Expected Behavior
The test should complete without the exception.
Version Info
SDK Version : 2.2.204
.NET Version : dotnet-core 2.2
How Application was onboarded with SDK: VisualStudio
OS : Windows 10
Hosting Info : xUnit
The text was updated successfully, but these errors were encountered: