InstallationManagerTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Net.Http;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using AutoFixture;
  7. using AutoFixture.AutoMoq;
  8. using Emby.Server.Implementations.Updates;
  9. using MediaBrowser.Model.Updates;
  10. using Moq;
  11. using Moq.Protected;
  12. using Xunit;
  13. namespace Jellyfin.Server.Implementations.Tests.Updates
  14. {
  15. public class InstallationManagerTests
  16. {
  17. private readonly Fixture _fixture;
  18. private readonly InstallationManager _installationManager;
  19. public InstallationManagerTests()
  20. {
  21. var messageHandler = new Mock<HttpMessageHandler>();
  22. messageHandler.Protected()
  23. .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
  24. .Returns<HttpRequestMessage, CancellationToken>(
  25. (m, _) =>
  26. {
  27. return Task.FromResult(new HttpResponseMessage()
  28. {
  29. Content = new StreamContent(File.OpenRead("Test Data/Updates/" + m.RequestUri?.Segments[^1]))
  30. });
  31. });
  32. var http = new Mock<IHttpClientFactory>();
  33. http.Setup(x => x.CreateClient(It.IsAny<string>()))
  34. .Returns(new HttpClient(messageHandler.Object));
  35. _fixture = new Fixture();
  36. _fixture.Customize(new AutoMoqCustomization
  37. {
  38. ConfigureMembers = true
  39. }).Inject(http);
  40. _installationManager = _fixture.Create<InstallationManager>();
  41. }
  42. [Fact]
  43. public async Task GetPackages_Valid_Success()
  44. {
  45. IList<PackageInfo> packages = await _installationManager.GetPackages(
  46. "Jellyfin Stable",
  47. "https://repo.jellyfin.org/releases/plugin/manifest-stable.json",
  48. false);
  49. Assert.Equal(25, packages.Count);
  50. }
  51. }
  52. }