public NuGetClientIntegrationTest(ITestOutputHelper helper) { Helper = helper ?? throw new ArgumentNullException(nameof(helper)); server = TestServerBuilder.Create().TraceToTestOutputHelper(Helper, LogLevel.Error).Build(); var providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); providers.Add(new Lazy <INuGetResourceProvider>(() => new PackageMetadataResourceV3Provider())); _httpClient = server.CreateClient(); providers.Insert(0, new Lazy <INuGetResourceProvider>(() => new HttpSourceResourceProviderTestHost(_httpClient))); indexUrl = new Uri(server.BaseAddress, IndexUrlString).AbsoluteUri; var packageSource = new PackageSource(indexUrl); _sourceRepository = new SourceRepository(packageSource, providers); _cacheContext = new SourceCacheContext() { NoCache = true, MaxAge = new DateTimeOffset(), DirectDownload = true }; _httpSource = _sourceRepository.GetResource <HttpSourceResource>(); Assert.IsType <HttpSourceTestHost>(_httpSource.HttpSource); }
public async Task AskServerForVersionsOfExistingPackageID() { var pkgService = new Mock <IPackageService>(MockBehavior.Strict); pkgService.Setup(p => p.FindAsync("abc", false, false)).ReturnsAsync(new Package[] { new Package() { Id = "abc", VersionString = "1.2.3" }, new Package() { Id = "abc", VersionString = "1.4.7" } }); using (TestServer server = TestServerBuilder.Create() .TraceToTestOutputHelper(Helper, LogLevel.Error) .WithMock(typeof(IPackageService), pkgService) .Build()) { var services = server.Host.Services; Assert.Equal(pkgService.Object, services.GetRequiredService <IPackageService>()); // https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource#enumerate-package-versions var response = await server.CreateClient().GetAsync(string.Format(IndexUrlFormatString, "abc")); Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode); var jsonString = await response.Content.ReadAsStringAsync(); var actual = JObject.Parse(jsonString); var expected = new JObject { { "versions", new JArray( "1.2.3", "1.4.7") } }; Assert.True(JToken.DeepEquals(expected, actual)); } }