Ich habe eine gemeinsame Anwendungsweite der Singleton-Modellklasse (Projekt) durch Abhängigkeitsinjektion.
funktioniert in der Anwendung hervorragend. Aber wegen der DI habe ich Schwierigkeiten, dies zu testen.public partial class App : Application
{
public IHost AppHost;
///
/// Default constructor
///
public App()
{
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddSingleton();
})
.Build();
...
}
}
< /code>
public partial class Analysis
{
public void AnalysisMethod()
{
IProject project = ((App)Application.Current).AppHost.Services.GetRequiredService();
}
}
< /code>
I'm trying to unit test AnalysisMethod but of course it fails because there is no Application.Current. How should I be coding/testing this, keeping in mind that I'd like to keep a singleton IProject created by DI?
Was ist die korrekte Implementierung für das Testen einer WPF -Anwendung mit Abhängigkeitsinjektion für Unit -Testen? ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Testen von Postgresql in Unit-Tests – Mocking- und Unit-Test-Bibliotheken
by Anonymous » » in Python - 0 Replies
- 4 Views
-
Last post by Anonymous
-
Mobile version