UsecaseTestHost.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Microsoft.Extensions.DependencyInjection;
  2. using NSubstitute;
  3. using RackPeek.Domain.Resources;
  4. using RackPeek.Domain.Resources.Hardware;
  5. using RackPeek.Domain.Resources.Services;
  6. using RackPeek.Domain.Resources.SystemResources;
  7. namespace Tests.HardwareResources;
  8. public class UsecaseTestHost
  9. {
  10. private readonly ServiceCollection _sc;
  11. public UsecaseTestHost()
  12. {
  13. HardwareRepo = Substitute.For<IHardwareRepository>();
  14. SystemRepo = Substitute.For<ISystemRepository>();
  15. ServiceRepo = Substitute.For<IServiceRepository>();
  16. ResourceRepo = Substitute.For<IResourceRepository>();
  17. _sc = new ServiceCollection();
  18. _sc.AddSingleton<IHardwareRepository>(HardwareRepo);
  19. _sc.AddSingleton<ISystemRepository>(SystemRepo);
  20. _sc.AddSingleton<IServiceRepository>(ServiceRepo);
  21. _sc.AddSingleton<IResourceRepository>(ResourceRepo);
  22. }
  23. public IHardwareRepository HardwareRepo { get; set; }
  24. public ISystemRepository SystemRepo { get; set; }
  25. public IServiceRepository ServiceRepo { get; set; }
  26. public IResourceRepository ResourceRepo { get; set; }
  27. public T Get<T>() where T : notnull
  28. {
  29. _sc.AddSingleton(typeof(T));
  30. var sp = _sc.BuildServiceProvider();
  31. return sp.GetRequiredService<T>();
  32. }
  33. }