Was ist die korrekte Implementierung für das Testen einer WPF -Anwendung mit Abhängigkeitsinjektion für Unit -Testen?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Was ist die korrekte Implementierung für das Testen einer WPF -Anwendung mit Abhängigkeitsinjektion für Unit -Testen?

Post by Anonymous »

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?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post