public async Task TryCreate_WhenResourceIsPresent_CreatesVersionedHttpCacheEntry(string resourceUrl, string resourceType, string expectedCacheKey) { var serviceEntry = new ServiceIndexEntry(new Uri(resourceUrl), resourceType, _defaultVersion); var responses = new Dictionary <string, string>() { { serviceEntry.Uri.AbsoluteUri, GetRepositorySignaturesResourceJson(resourceUrl) } }; var httpSource = new TestHttpSource(_packageSource, responses); var resourceProviders = new ResourceProvider[] { CreateServiceIndexResourceV3Provider(serviceEntry), StaticHttpSource.CreateHttpSource(responses, httpSource: httpSource), _repositorySignatureResourceProvider }; var sourceRepository = new SourceRepository(_packageSource, resourceProviders); string actualCacheKey = null; httpSource.HttpSourceCachedRequestInspector = request => { actualCacheKey = request.CacheKey; }; var result = await _repositorySignatureResourceProvider.TryCreate(sourceRepository, CancellationToken.None); Assert.True(result.Item1); Assert.Equal(expectedCacheKey, actualCacheKey); }
internal static async Task <HttpFileSystemBasedFindPackageByIdResourceTest> CreateAsync(TestEnvironmentVariableReader testEnvironmentVariableReader = null) { var packageIdentity = new PackageIdentity(id: "DeepEqual", version: NuGetVersion.Parse("1.4.0")); var testDirectory = TestDirectory.Create(); var packageSource = new PackageSource("http://unit.test/v3-flatcontainer"); var package = await SimpleTestPackageUtility.CreateFullPackageAsync( testDirectory.Path, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var packageBytes = File.ReadAllBytes(package.FullName); var responses = new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > > { { $"{packageSource.Source}/deepequal/index.json", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new TestContent(JsonData.DeepEqualFlatContainerIndex) }) }, { $"{packageSource.Source}/deepequal/1.4.0/deepequal.1.4.0.nupkg", _ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(packageBytes) }) }, { $"{packageSource.Source}/a/index.json", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)) }, { $"{packageSource.Source}/socketexception/index.json", request => { SocketExceptionCallsMade += 1; throw new Exception("Oh this isn't going well", new IOException("This is what TCP hang-ups look like", new SocketException(123))); } }, }; var baseUris = new List <Uri>() { packageSource.SourceUri }; var httpSource = new TestHttpSource(packageSource, responses); var resource = new HttpFileSystemBasedFindPackageByIdResource( baseUris, httpSource, testEnvironmentVariableReader != null ? testEnvironmentVariableReader : EnvironmentVariableWrapper.Instance); return(new HttpFileSystemBasedFindPackageByIdResourceTest( resource, package, packageIdentity, new SourceCacheContext(), httpSource, testDirectory)); }
public async Task RawSearchResource_VerifyReadSyncIsNotUsed() { // Arrange var serviceAddress = ProtocolUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add( serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false" + "&supportedFramework=.NETFramework,Version=v4.5&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.V3Search.json", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); // throw if sync .Read is used httpSource.StreamWrapper = (stream) => new NoSyncReadStream(stream); var searchResource = new RawSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) }); var searchFilter = new SearchFilter(includePrerelease: false) { SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" } }; // Act var packages = await searchResource.Search("azure b", searchFilter, 0, 1, NullLogger.Instance, CancellationToken.None); var packagesArray = packages.ToArray(); // Assert // Verify that the url matches the one in the response dictionary // Verify no failures from Sync Read Assert.True(packagesArray.Length > 0); }
public async Task RawSearchResource_SearchEncoding() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false&supportedFramework=.NETFramework,Version=v4.5", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.V3Search.json", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); var searchResource = new RawSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) }); var searchFilter = new SearchFilter() { IncludePrerelease = false, SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" } }; // Act var packages = await searchResource.Search("azure b", searchFilter, 0, 1, NullLogger.Instance, CancellationToken.None); var packagesArray = packages.ToArray(); // Assert // Verify that the url matches the one in the response dictionary Assert.True(packagesArray.Length > 0); }
public void Initialize() { HttpSource = new TestHttpSource( PackageSource, new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > >() { { NupkgUrl, request => { RequestCount++; return(Task.FromResult(new HttpResponseMessage { StatusCode = StatusCode, Content = new ByteArrayContent(ExpectedContent) })); } } }) { HttpCacheDirectory = HttpCacheDirectory, DisableCaching = false }; RequestCount = 0; Target = new FindPackagesByIdNupkgDownloader(HttpSource); }
public async Task V2FeedParser_GetPackage_NotFoundOnBoth() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Packages(Id='xunit',Version='1.0.0-notfound')", string.Empty); responses.Add(serviceAddress + "FindPackagesById()?id='xunit'", string.Empty); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses, TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.500Error.xml", GetType())); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var packageIdentity = new PackageIdentity("xunit", new NuGetVersion("1.0.0-notfound")); // Act var exception = await Assert.ThrowsAsync <FatalProtocolException>(() => parser.GetPackage( packageIdentity, NullLogger.Instance, CancellationToken.None)); Assert.Equal( "The V2 feed at '" + serviceAddress + "FindPackagesById()?id='xunit'' " + "returned an unexpected status code '404 Not Found'.", exception.Message); }
public async Task V2FeedParser_Search_InternalServerError() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Search()?$filter=IsLatestVersion&searchTerm='azure'&targetFramework='net40-client'&includePrerelease=false&$skip=0&$top=1", null); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var searchFilter = new SearchFilter() { IncludePrerelease = false, SupportedFrameworks = new string[] { "net40-Client" } }; // Act & Assert var exception = await Assert.ThrowsAsync <FatalProtocolException>(() => parser.Search( "azure", searchFilter, 0, 1, NullLogger.Instance, CancellationToken.None)); Assert.Equal( "The V2 feed at '" + serviceAddress + "Search()?$filter=IsLatestVersion&searchTerm='azure'&targetFramework='net40-client'&includePrerelease=false&$skip=0&$top=1' " + "returned an unexpected status code '500 Internal Server Error'.", exception.Message); }
public async Task V2FeedParser_NexusFindPackagesByIdNullDependencyRange() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='PackageA'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.NexusFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act var packages = await parser.FindPackagesByIdAsync("PackageA", NullLogger.Instance, CancellationToken.None); var latest = packages.OrderByDescending(e => e.Version, VersionComparer.VersionRelease).FirstOrDefault(); // Assert Assert.Equal("PackageA", latest.Id); Assert.Equal("1.0.0.99", latest.Version.ToNormalizedString()); Assert.Equal("My Name", String.Join(",", latest.Authors)); Assert.Equal("", String.Join(",", latest.Owners)); Assert.True(latest.Description.StartsWith("Some description")); Assert.Equal(0, latest.DownloadCountAsInt); Assert.Equal("PackageB:null|EntityFramework:6.1.3|PackageC:3.7.0.15", latest.Dependencies); Assert.Equal(1, latest.DependencySets.Count()); Assert.Equal(VersionRange.All, latest.DependencySets.Single().Packages.Where(p => p.Id == "PackageB").Single().VersionRange); Assert.Equal("any", latest.DependencySets.First().TargetFramework.GetShortFolderName()); }
public async Task V2FeedParser_FollowNextLinks() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='ravendb.client'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.RavendbFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); responses.Add("https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','1.2.2067-Unstable'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.RavendbFindPackagesByIdPage1.xml", GetType())); responses.Add("https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','2.0.2183-Unstable'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.RavendbFindPackagesByIdPage2.xml", GetType())); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act var packages = await parser.FindPackagesByIdAsync("ravendb.client", NullLogger.Instance, CancellationToken.None); // Assert Assert.Equal(300, packages.Count()); }
public async Task V2FeedParser_SearchTop100() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Search()?$filter=IsLatestVersion&searchTerm='azure'&targetFramework='net40-client'&includePrerelease=false&$skip=0&$top=100", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.AzureSearch100.xml", GetType())); responses.Add("https://www.nuget.org/api/v2/Search?searchTerm='azure'&targetFramework='net40-client'&includePrerelease=false&$filter=IsLatestVersion&$skiptoken='Haven.ServiceBus.Azure.ServiceBus.Publisher','1.0.5835.19676',100", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.AzureSearchNext100.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var searchFilter = new SearchFilter() { IncludePrerelease = false, SupportedFrameworks = new string[] { "net40-Client" } }; // Act var packages = await parser.Search("azure", searchFilter, 0, 100, NullLogger.Instance, CancellationToken.None); // Assert Assert.Equal(100, packages.Count()); }
public async Task V2FeedParser_Search_MultipleSupportedFramework() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Search()?$filter=IsLatestVersion&searchTerm='azure%20%2B''%20b%20'&targetFramework='portable45-net45%2Bwin8%2Bwpa81%7Cwpa81%7Cmonoandroid60'&includePrerelease=false&$skip=0&$top=1", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.AzureSearch.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var searchFilter = new SearchFilter() { IncludePrerelease = false, SupportedFrameworks = new string[] { ".NetPortable,Version=v4.5,Profile=Profile111", "WindowsPhoneApp,Version=v8.1", "MonoAndroid,Version=v6.0" } }; // Act var packages = await parser.Search("azure +' b ", searchFilter, 0, 1, NullLogger.Instance, CancellationToken.None); var package = packages.FirstOrDefault(); // Assert Assert.NotNull((package)); Assert.Equal("WindowsAzure.Storage", package.Id); }
public async Task V2FeedParser_FindPackagesById_InternalServerError() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='xunit'", null); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses, TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.500Error.xml", GetType())); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act & Assert var exception = await Assert.ThrowsAsync <FatalProtocolException>(() => parser.FindPackagesByIdAsync( "xunit", NullLogger.Instance, CancellationToken.None)); Assert.Equal( "The V2 feed at '" + serviceAddress + "FindPackagesById()?id='xunit'' " + "returned an unexpected status code '500 Internal Server Error'.", exception.Message); }
public async Task RawSearchResource_CancelledToken_ThrowsOperationCancelledException() { // Arrange var serviceAddress = ProtocolUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add( serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false" + "&supportedFramework=.NETFramework,Version=v4.5&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.V3Search.json", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); httpSource.StreamWrapper = (stream) => new NoSyncReadStream(stream); var searchResource = new RawSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) }); var searchFilter = new SearchFilter(includePrerelease: false) { SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" } }; var tokenSource = new CancellationTokenSource(); tokenSource.Cancel(); // Act/Assert await Assert.ThrowsAsync <TaskCanceledException> (() => searchResource.Search("Sentry", searchFilter, 0, 1, NullLogger.Instance, tokenSource.Token)); }
public async Task V2FeedParser_DownloadFromIdentityInvalidId() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Packages(Id='xunit',Version='1.0.0-notfound')", string.Empty); responses.Add(serviceAddress + "FindPackagesById()?id='xunit'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.XunitFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses, TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.500Error.xml", GetType())); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act var actual = await parser.DownloadFromIdentity(new PackageIdentity("xunit", new NuGetVersion("1.0.0-notfound")), NullSettings.Instance, NullLogger.Instance, CancellationToken.None); // Assert Assert.NotNull(actual); Assert.Equal(DownloadResourceResultStatus.NotFound, actual.Status); }
public async Task GetDownloadResultUtility_WithTwoOfTheSameDownloads_DoesNotCollide() { // Arrange var uri = new Uri("http://fake/content.nupkg"); var expectedContent = "TestContent"; var identity = new PackageIdentity("PackageA", NuGetVersion.Parse("1.0.0-Beta")); var testHttpSource = new TestHttpSource( new PackageSource("http://fake"), new Dictionary <string, string> { { uri.ToString(), expectedContent } }); var logger = new TestLogger(); var token = CancellationToken.None; using (var cacheContext = new SourceCacheContext()) using (var downloadDirectory = TestDirectory.Create()) using (var globalPackagesFolder = TestDirectory.Create()) { var downloadContext = new PackageDownloadContext( cacheContext, downloadDirectory, directDownload: true); // Act using (var resultA = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) using (var resultB = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) { // Assert var files = Directory.EnumerateFileSystemEntries(downloadDirectory).ToArray(); Assert.Equal(2, files.Length); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[0])); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[1])); var actualContentA = new StreamReader(resultA.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContentA); var actualContentB = new StreamReader(resultB.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContentB); } Assert.Equal(0, Directory.EnumerateFileSystemEntries(downloadDirectory).Count()); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); } }
public async Task GetDownloadResultUtility_WithSingleDirectDownload_ReturnsTemporaryDownloadResult() { // Arrange var uri = new Uri("http://fake/content.nupkg"); var expectedContent = "TestContent"; var identity = new PackageIdentity("PackageA", NuGetVersion.Parse("1.0.0-Beta")); var testHttpSource = new TestHttpSource( new PackageSource("http://fake"), new Dictionary <string, string> { { uri.ToString(), expectedContent } }); var logger = new TestLogger(); var token = CancellationToken.None; using (var cacheContext = new SourceCacheContext()) using (var downloadDirectory = TestDirectory.Create()) using (var globalPackagesFolder = TestDirectory.Create()) { var downloadContext = new PackageDownloadContext( cacheContext, downloadDirectory, directDownload: true); // Act using (var result = await GetDownloadResultUtility.GetDownloadResultAsync( testHttpSource, identity, uri, downloadContext, globalPackagesFolder, logger, token)) { // Assert Assert.Null(result.PackageReader); Assert.Equal(DownloadResourceResultStatus.Available, result.Status); Assert.NotNull(result.PackageStream); Assert.True(result.PackageStream.CanSeek); Assert.True(result.PackageStream.CanRead); Assert.Equal(0, result.PackageStream.Position); var files = Directory.EnumerateFileSystemEntries(downloadDirectory).ToArray(); Assert.Equal(1, files.Length); Assert.EndsWith(".nugetdirectdownload", Path.GetFileName(files[0])); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); var actualContent = new StreamReader(result.PackageStream).ReadToEnd(); Assert.Equal(expectedContent, actualContent); } Assert.Equal(0, Directory.EnumerateFileSystemEntries(downloadDirectory).Count()); Assert.Equal(0, Directory.EnumerateFileSystemEntries(globalPackagesFolder).Count()); } }
internal static async Task <HttpFileSystemBasedFindPackageByIdResourceTest> CreateAsync() { var packageIdentity = new PackageIdentity(id: "DeepEqual", version: NuGetVersion.Parse("1.4.0")); var testDirectory = TestDirectory.Create(); var packageSource = new PackageSource("http://unit.test/v3-flatcontainer"); var package = await SimpleTestPackageUtility.CreateFullPackageAsync( testDirectory.Path, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var packageBytes = File.ReadAllBytes(package.FullName); var responses = new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > > { { $"{packageSource.Source}/deepequal/index.json", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new TestContent(JsonData.DeepEqualFlatContainerIndex) }) }, { $"{packageSource.Source}/deepequal/1.4.0/deepequal.1.4.0.nupkg", _ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(packageBytes) }) }, { $"{packageSource.Source}/a/index.json", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)) } }; var baseUris = new List <Uri>() { packageSource.SourceUri }; var httpSource = new TestHttpSource(packageSource, responses); var resource = new HttpFileSystemBasedFindPackageByIdResource( baseUris, httpSource); return(new HttpFileSystemBasedFindPackageByIdResourceTest( resource, package, packageIdentity, new SourceCacheContext(), httpSource, testDirectory)); }
public async Task TestListDelistedPrereleaseAllVersions() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress() + "api/v2"; var responses = new Dictionary <string, string>(); responses.Add( serviceAddress + "/Search()?$orderby=Id&searchTerm='Windows.AzureStorage'&targetFramework=''" + "&includePrerelease=true&$skip=0&$top=30&semVerLevel=2.0.0", TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.WindowsAzureStorageSearchPackage30Entries.xml", GetType())); responses.Add( serviceAddress + "/Search()?$orderby=Id&searchTerm='Windows.AzureStorage'&targetFramework=''" + "&includePrerelease=true&$skip=30&$top=30&semVerLevel=2.0.0", TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.WindowsAzureStorageSearchPackage17Entries.xml", GetType())); responses.Add(serviceAddress, string.Empty); responses.Add(serviceAddress + "/$metadata", TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.MetadataTT.xml", GetType())); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); var parser = new V2FeedParser(httpSource, serviceAddress); var legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress); var resource = new V2FeedListResource(parser, legacyResource, serviceAddress); var enumerable = await resource.ListAsync(searchTerm : "Windows.AzureStorage", prerelease : true, allVersions : true, includeDelisted : true, logger : NullLogger.Instance, token : CancellationToken.None); //Only 2 packages are listed in this resource int ExpectedCount = 47; int ActualCount = 0; var enumerator = enumerable.GetEnumeratorAsync(); while (await enumerator.MoveNextAsync()) { if (enumerator.Current != null) { ActualCount++; Assert.True(ExpectedCount >= ActualCount, "Too many results"); } else { Assert.False(false, "Null Value, this shouldn't happen."); } } Assert.Equal(ExpectedCount, ActualCount); }
private HttpFileSystemBasedFindPackageByIdResourceTest( HttpFileSystemBasedFindPackageByIdResource resource, FileInfo package, PackageIdentity packageIdentity, SourceCacheContext sourceCacheContext, TestHttpSource httpSource, TestDirectory testDirectory) { Resource = resource; Package = package; PackageIdentity = packageIdentity; SourceCacheContext = sourceCacheContext; _httpSource = httpSource; TestDirectory = testDirectory; }
public async Task TestUsesReferenceCache() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress() + "api/v2"; var responses = new Dictionary <string, string>(); responses.Add( serviceAddress + "/Search()?$orderby=Id&searchTerm='afine'" + "&targetFramework=''&includePrerelease=false&$skip=0&$top=30&semVerLevel=2.0.0", TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.SearchV2WithDuplicateBesidesVersion.xml", GetType())); responses.Add(serviceAddress, string.Empty); responses.Add(serviceAddress + "/$metadata", TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.MetadataTT.xml", GetType())); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); var parser = new V2FeedParser(httpSource, serviceAddress); var legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress); var resource = new V2FeedListResource(parser, legacyResource, serviceAddress); var enumerable = await resource.ListAsync(searchTerm : "afine", prerelease : false, allVersions : true, includeDelisted : true, logger : NullLogger.Instance, token : CancellationToken.None); int ExpectedCount = 2; int ActualCount = 0; var enumerator = enumerable.GetEnumeratorAsync(); var packages = new List <PackageSearchMetadataBuilder.ClonedPackageSearchMetadata>(); while (await enumerator.MoveNextAsync()) { if (enumerator.Current != null) { ActualCount++; Assert.True(ExpectedCount >= ActualCount, "Too many results"); packages.Add((PackageSearchMetadataBuilder.ClonedPackageSearchMetadata)enumerator.Current); } else { Assert.False(false, "Null Value, this shouldn't happen."); } } Assert.Equal(ExpectedCount, ActualCount); MetadataReferenceCacheTestUtility.AssertPackagesHaveSameReferences(packages[0], packages[1]); }
public async Task V2FeedParser_Search() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Search()?$filter=IsLatestVersion&searchTerm='azure'&targetFramework='net40-client'&includePrerelease=false&$skip=0&$top=1", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.AzureSearch.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var searchFilter = new SearchFilter() { IncludePrerelease = false, SupportedFrameworks = new string[] { "net40-Client" } }; // Act var packages = await parser.Search("azure", searchFilter, 0, 1, NullLogger.Instance, CancellationToken.None); var package = packages.FirstOrDefault(); // Assert Assert.Equal("WindowsAzure.Storage", package.Id); Assert.Equal("6.2.0", package.Version.ToNormalizedString()); Assert.Equal("WindowsAzure.Storage", package.Title); Assert.Equal("Microsoft", String.Join(",", package.Authors)); Assert.Equal("", String.Join(",", package.Owners)); Assert.True(package.Description.StartsWith("This client library enables")); Assert.Equal(3957668, package.DownloadCountAsInt); Assert.Equal("https://www.nuget.org/api/v2/package/WindowsAzure.Storage/6.2.0", package.DownloadUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkID=288890", package.IconUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=331471", package.LicenseUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=235168", package.ProjectUrl); Assert.Equal(DateTimeOffset.Parse("2015-12-10T22:39:05.103"), package.Published.Value); Assert.Equal("https://www.nuget.org/package/ReportAbuse/WindowsAzure.Storage/6.2.0", package.ReportAbuseUrl); Assert.True(package.RequireLicenseAcceptance); Assert.Equal("A client library for working with Microsoft Azure storage services including blobs, files, tables, and queues.", package.Summary); Assert.Equal("Microsoft Azure Storage Table Blob File Queue Scalable windowsazureofficial", package.Tags); Assert.Equal("Microsoft.Data.OData:5.6.4:net40-Client|Newtonsoft.Json:6.0.8:net40-Client|Microsoft.Data.Services.Client:5.6.4:net40-Client|Microsoft.Azure.KeyVault.Core:1.0.0:net40-Client|Microsoft.Data.OData:5.6.4:win80|Newtonsoft.Json:6.0.8:win80|Microsoft.Data.OData:5.6.4:wpa|Newtonsoft.Json:6.0.8:wpa|Microsoft.Data.OData:5.6.4:wp80|Newtonsoft.Json:6.0.8:wp80|Microsoft.Azure.KeyVault.Core:1.0.0:wp80", package.Dependencies); Assert.Equal(4, package.DependencySets.Count()); Assert.Equal("net40-client", package.DependencySets.First().TargetFramework.GetShortFolderName()); Assert.Equal("release notes", package.ReleaseNotes); }
private RemoteV2FindPackageByIdResourceTest( RemoteV2FindPackageByIdResource resource, PackageSource packageSource, FileInfo package, PackageIdentity packageIdentity, SourceCacheContext sourceCacheContext, TestHttpSource httpSource, TestDirectory testDirectory) { Resource = resource; PackageSource = packageSource; Package = package; PackageIdentity = packageIdentity; SourceCacheContext = sourceCacheContext; _httpSource = httpSource; TestDirectory = testDirectory; }
public async Task RawSearchResource_SearchEncoding() { // Arrange var serviceAddress = ProtocolUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add( serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false" + "&supportedFramework=.NETFramework,Version=v4.5&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.V3Search.json", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); #pragma warning disable CS0618 var searchResource = new RawSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) }); #pragma warning restore CS0618 var searchFilter = new SearchFilter(includePrerelease: false) { SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" } }; var skip = 0; var take = 1; // Act #pragma warning disable CS0618 var packages = await searchResource.Search( #pragma warning restore CS0618 "azure b", searchFilter, skip, take, NullLogger.Instance, CancellationToken.None); var packagesArray = packages.ToArray(); // Assert // Verify that the url matches the one in the response dictionary Assert.True(packagesArray.Length > 0); }
public async Task V2FeedParser_FindPackagesByIdAsync() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='WindowsAzure.Storage'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.WindowsAzureStorageFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act var packages = await parser.FindPackagesByIdAsync("WindowsAzure.Storage", NullLogger.Instance, CancellationToken.None); var latest = packages.OrderByDescending(e => e.Version, VersionComparer.VersionRelease).FirstOrDefault(); // Assert Assert.Equal("WindowsAzure.Storage", latest.Id); Assert.Equal("6.2.2-preview", latest.Version.ToNormalizedString()); Assert.Equal("WindowsAzure.Storage", latest.Title); Assert.Equal("Microsoft", String.Join(",", latest.Authors)); Assert.Equal("", String.Join(",", latest.Owners)); Assert.True(latest.Description.StartsWith("This client library enables")); Assert.Equal(3957668, latest.DownloadCountAsInt); Assert.Equal("https://www.nuget.org/api/v2/package/WindowsAzure.Storage/6.2.2-preview", latest.DownloadUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkID=288890", latest.IconUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=331471", latest.LicenseUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=235168", latest.ProjectUrl); Assert.Equal(DateTimeOffset.Parse("2015-12-11T01:25:11.37"), latest.Published.Value); Assert.Equal("https://www.nuget.org/package/ReportAbuse/WindowsAzure.Storage/6.2.2-preview", latest.ReportAbuseUrl); Assert.True(latest.RequireLicenseAcceptance); Assert.Equal("A client library for working with Microsoft Azure storage services including blobs, files, tables, and queues.", latest.Summary); Assert.Equal("Microsoft Azure Storage Table Blob File Queue Scalable windowsazureofficial", latest.Tags); Assert.Equal("Microsoft.Data.OData:5.6.4:dotnet54|Microsoft.Data.Services.Client:5.6.4:dotnet54|System.Spatial:5.6.4:dotnet54|Newtonsoft.Json:6.0.8:dotnet54|System.Collections:4.0.11-beta-23225:dotnet54|System.Collections.Concurrent:4.0.11-beta-23225:dotnet54|System.Collections.Specialized:4.0.0-beta-23109:dotnet54|System.Diagnostics.Debug:4.0.11-beta-23225:dotnet54|System.Diagnostics.Tools:4.0.1-beta-23225:dotnet54|System.Diagnostics.TraceSource:4.0.0-beta-23225:dotnet54|System.Diagnostics.Tracing:4.0.21-beta-23225:dotnet54|System.Dynamic.Runtime:4.0.11-beta-23225:dotnet54|System.Globalization:4.0.11-beta-23225:dotnet54|System.IO:4.0.11-beta-23225:dotnet54|System.IO.FileSystem:4.0.1-beta-23225:dotnet54|System.IO.FileSystem.Primitives:4.0.1-beta-23225:dotnet54|System.Linq:4.0.1-beta-23225:dotnet54|System.Linq.Expressions:4.0.11-beta-23225:dotnet54|System.Linq.Queryable:4.0.0-beta-23109:dotnet54|System.Net.Http:4.0.1-beta-23225:dotnet54|System.Net.Primitives:4.0.11-beta-23225:dotnet54|System.Reflection:4.1.0-beta-23225:dotnet54|System.Reflection.Extensions:4.0.1-beta-23225:dotnet54|System.Reflection.TypeExtensions:4.0.1-beta-23225:dotnet54|System.Runtime:4.0.20-beta-23109:dotnet54|System.Runtime.Extensions:4.0.11-beta-23225:dotnet54|System.Runtime.InteropServices:4.0.21-beta-23225:dotnet54|System.Runtime.Serialization.Primitives:4.0.0-beta-23109:dotnet54|System.Runtime.Serialization.Xml:4.0.10-beta-23109:dotnet54|System.Security.Cryptography.Encoding:4.0.0-beta-23225:dotnet54|System.Security.Cryptography.Primitives:4.0.0-beta-23225:dotnet54|System.Security.Cryptography.Algorithms:4.0.0-beta-23225:dotnet54|System.Text.Encoding:4.0.11-beta-23225:dotnet54|System.Text.Encoding.Extensions:4.0.11-beta-23225:dotnet54|System.Text.RegularExpressions:4.0.11-beta-23225:dotnet54|System.Threading:4.0.11-beta-23225:dotnet54|System.Threading.Tasks:4.0.11-beta-23225:dotnet54|System.Threading.Thread:4.0.0-beta-23225:dotnet54|System.Threading.ThreadPool:4.0.10-beta-23225:dotnet54|System.Threading.Timer:4.0.1-beta-23225:dotnet54|System.Xml.ReaderWriter:4.0.11-beta-23225:dotnet54|System.Xml.XDocument:4.0.11-beta-23225:dotnet54|System.Xml.XmlSerializer:4.0.0-beta-23109:dotnet54|Microsoft.Data.OData:5.6.4:net40-Client|Newtonsoft.Json:6.0.8:net40-Client|Microsoft.Data.Services.Client:5.6.4:net40-Client|Microsoft.Azure.KeyVault.Core:1.0.0:net40-Client|Microsoft.Data.OData:5.6.4:win80|Newtonsoft.Json:6.0.8:win80|Microsoft.Data.OData:5.6.4:wpa|Newtonsoft.Json:6.0.8:wpa|Microsoft.Data.OData:5.6.4:wp80|Newtonsoft.Json:6.0.8:wp80|Microsoft.Azure.KeyVault.Core:1.0.0:wp80|Microsoft.Data.OData:5.6.4:portable-net45+win+wpa81+MonoAndroid10+MonoTouch10|Newtonsoft.Json:6.0.8:portable-net45+win+wpa81+MonoAndroid10+MonoTouch10", latest.Dependencies); Assert.Equal(6, latest.DependencySets.Count()); Assert.Equal("dotnet5.4", latest.DependencySets.First().TargetFramework.GetShortFolderName()); Assert.Equal("release notes", latest.ReleaseNotes); }
public async Task V2FeedParser_GetPackage_NotFoundOnPackagesFoundOnFindPackagesById() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "Packages(Id='WindowsAzure.Storage',Version='4.3.2-preview')", string.Empty); responses.Add(serviceAddress + "FindPackagesById()?id='WindowsAzure.Storage'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.WindowsAzureStorageFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); var packageIdentity = new PackageIdentity("WindowsAzure.Storage", new NuGetVersion("4.3.2-preview")); // Act var package = await parser.GetPackage(packageIdentity, NullLogger.Instance, CancellationToken.None); // Assert Assert.Equal("WindowsAzure.Storage", package.Id); Assert.Equal("4.3.2-preview", package.Version.ToNormalizedString()); Assert.Equal("WindowsAzure.Storage", package.Title); Assert.Equal("Microsoft", String.Join(",", package.Authors)); Assert.Equal("", String.Join(",", package.Owners)); Assert.True(package.Description.StartsWith("This client library enables")); Assert.Equal(3957668, package.DownloadCountAsInt); Assert.Equal("https://www.nuget.org/api/v2/package/WindowsAzure.Storage/4.3.2-preview", package.DownloadUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkID=288890", package.IconUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=331471", package.LicenseUrl); Assert.Equal("http://go.microsoft.com/fwlink/?LinkId=235168", package.ProjectUrl); Assert.Equal(DateTimeOffset.Parse("2014-11-12T22:19:16.297"), package.Published.Value); Assert.Equal("https://www.nuget.org/package/ReportAbuse/WindowsAzure.Storage/4.3.2-preview", package.ReportAbuseUrl); Assert.True(package.RequireLicenseAcceptance); Assert.Equal("A client library for working with Microsoft Azure storage services including blobs, files, tables, and queues.", package.Summary); Assert.Equal("Microsoft Azure Storage Table Blob File Queue Scalable windowsazureofficial", package.Tags); Assert.Equal("Microsoft.Data.OData:5.6.3:aspnetcore50|Microsoft.Data.Services.Client:5.6.3:aspnetcore50|System.Spatial:5.6.3:aspnetcore50|System.Collections:4.0.10-beta-22231:aspnetcore50|System.Collections.Concurrent:4.0.0-beta-22231:aspnetcore50|System.Collections.Specialized:4.0.0-beta-22231:aspnetcore50|System.Diagnostics.Debug:4.0.10-beta-22231:aspnetcore50|System.Diagnostics.Tools:4.0.0-beta-22231:aspnetcore50|System.Diagnostics.TraceSource:4.0.0-beta-22231:aspnetcore50|System.Diagnostics.Tracing:4.0.10-beta-22231:aspnetcore50|System.Dynamic.Runtime:4.0.0-beta-22231:aspnetcore50|System.Globalization:4.0.10-beta-22231:aspnetcore50|System.IO:4.0.10-beta-22231:aspnetcore50|System.IO.FileSystem:4.0.0-beta-22231:aspnetcore50|System.IO.FileSystem.Primitives:4.0.0-beta-22231:aspnetcore50|System.Linq:4.0.0-beta-22231:aspnetcore50|System.Linq.Expressions:4.0.0-beta-22231:aspnetcore50|System.Linq.Queryable:4.0.0-beta-22231:aspnetcore50|System.Net.Http:4.0.0-beta-22231:aspnetcore50|System.Net.Primitives:4.0.10-beta-22231:aspnetcore50|System.Reflection:4.0.10-beta-22231:aspnetcore50|System.Reflection.Extensions:4.0.0-beta-22231:aspnetcore50|System.Reflection.TypeExtensions:4.0.0-beta-22231:aspnetcore50|System.Runtime:4.0.20-beta-22231:aspnetcore50|System.Runtime.Extensions:4.0.10-beta-22231:aspnetcore50|System.Runtime.InteropServices:4.0.20-beta-22231:aspnetcore50|System.Runtime.Serialization.Primitives:4.0.0-beta-22231:aspnetcore50|System.Runtime.Serialization.Xml:4.0.10-beta-22231:aspnetcore50|System.Security.Cryptography.Encoding:4.0.0-beta-22231:aspnetcore50|System.Security.Cryptography.Encryption:4.0.0-beta-22231:aspnetcore50|System.Security.Cryptography.Hashing:4.0.0-beta-22231:aspnetcore50|System.Security.Cryptography.Hashing.Algorithms:4.0.0-beta-22231:aspnetcore50|System.Text.Encoding:4.0.10-beta-22231:aspnetcore50|System.Text.Encoding.Extensions:4.0.10-beta-22231:aspnetcore50|System.Text.RegularExpressions:4.0.10-beta-22231:aspnetcore50|System.Threading:4.0.0-beta-22231:aspnetcore50|System.Threading.Tasks:4.0.10-beta-22231:aspnetcore50|System.Threading.Thread:4.0.0-beta-22231:aspnetcore50|System.Threading.ThreadPool:4.0.10-beta-22231:aspnetcore50|System.Threading.Timer:4.0.0-beta-22231:aspnetcore50|System.Xml.ReaderWriter:4.0.10-beta-22231:aspnetcore50|System.Xml.XDocument:4.0.0-beta-22231:aspnetcore50|System.Xml.XmlSerializer:4.0.0-beta-22231:aspnetcore50|Microsoft.Data.OData:5.6.3:aspnet50|Microsoft.Data.Services.Client:5.6.3:aspnet50|System.Spatial:5.6.3:aspnet50|Microsoft.Data.OData:5.6.2:net40-Client|Newtonsoft.Json:5.0.8:net40-Client|Microsoft.Data.Services.Client:5.6.2:net40-Client|Microsoft.WindowsAzure.ConfigurationManager:1.8.0.0:net40-Client|Microsoft.Data.OData:5.6.2:win80|Microsoft.Data.OData:5.6.2:wpa|Microsoft.Data.OData:5.6.2:wp80|Newtonsoft.Json:5.0.8:wp80", package.Dependencies); Assert.Equal(6, package.DependencySets.Count()); Assert.Equal("aspnetcore50", package.DependencySets.First().TargetFramework.GetShortFolderName()); Assert.Equal("release notes", package.ReleaseNotes); }
public async Task LegacyResourceNoSearchNoAbsoluteLatestVersion() { // Arrange var serviceAddress = ProtocolUtility.CreateServiceAddress() + "api/v2"; var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "/$metadata", ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.MetadataFF.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); LegacyFeedCapabilityResourceV2Feed legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress); Assert.False(await legacyResource.SupportsSearchAsync(NullLogger.Instance, CancellationToken.None)); Assert.False(await legacyResource.SupportsIsAbsoluteLatestVersionAsync(NullLogger.Instance, CancellationToken.None)); }
public async Task V2FeedParser_DuplicateNextUrl() { // Arrange var dupUrl = "https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','1.2.2067-Unstable'"; var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='ravendb.client'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependency.xml", GetType())); responses.Add(serviceAddress, string.Empty); responses.Add(dupUrl, TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependencyPage1.xml", GetType())); responses.Add("https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','2.0.2183-Unstable'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependencyPage2.xml", GetType())); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); FatalProtocolException duplicateUrlException = null; try { // Act var packages = await parser.FindPackagesByIdAsync("ravendb.client", NullLogger.Instance, CancellationToken.None); } catch (FatalProtocolException ex) { duplicateUrlException = ex; } // Assert Assert.NotNull(duplicateUrlException); Assert.Equal(string.Format(CultureInfo.CurrentCulture, Strings.Protocol_duplicateUri, dupUrl), duplicateUrlException.Message); }
public async Task V2FeedParser_Basic() { // Arrange var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='WindowsAzure.Storage'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.WindowsAzureStorageFindPackagesById.xml", GetType())); responses.Add(serviceAddress, string.Empty); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); // Act var packages = await parser.FindPackagesByIdAsync( "WindowsAzure.Storage", NullLogger.Instance, CancellationToken.None); // Assert Assert.Equal(47, packages.Count()); }
public async Task EmitsSearchTelemetryEvents() { // Arrange var solutionManager = Mock.Of <IVsSolutionManager>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManager) .Returns(solutionManager); var telemetryService = new Mock <INuGetTelemetryService>(); var eventsQueue = new ConcurrentQueue <TelemetryEvent>(); telemetryService .Setup(x => x.EmitTelemetryEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(e => eventsQueue.Enqueue(e)); // Mock all the remote calls our test will try to make. var source = NuGetConstants.V3FeedUrl; var query = "https://api-v2v3search-0.nuget.org/query"; var responses = new Dictionary <string, string> { { source, ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.index.json", typeof(PackageItemLoaderTests)) }, { query + "?q=nuget&skip=0&take=26&prerelease=true&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.nugetSearchPage1.json", typeof(PackageItemLoaderTests)) }, { query + "?q=nuget&skip=25&take=26&prerelease=true&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.nugetSearchPage2.json", typeof(PackageItemLoaderTests)) }, }; using (var httpSource = new TestHttpSource(new PackageSource(source), responses)) { var injectedHttpSources = new Dictionary <string, HttpSource>(); injectedHttpSources.Add(source, httpSource); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { new PackageSource(source) }, new Lazy <INuGetResourceProvider>[] { new Lazy <INuGetResourceProvider>(() => new TestHttpSourceResourceProvider(injectedHttpSources)) }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: telemetryService.Object); // Act var loader = new PackageItemLoader(context, packageFeed, searchText: "nuget", includePrerelease: true); await loader.LoadNextAsync(null, CancellationToken.None); await loader.LoadNextAsync(null, CancellationToken.None); // Assert var events = eventsQueue.ToArray(); Assert.True(4 == events.Length, string.Join(Environment.NewLine, events.Select(e => e.Name))); var search = Assert.Single(events, e => e.Name == "Search"); Assert.Equal(true, search["IncludePrerelease"]); Assert.Equal("nuget", search.GetPiiData().First(p => p.Key == "Query").Value); var operationId = Assert.IsType <string>(search["OperationId"]); var parsedOperationId = Guid.ParseExact(operationId, "D"); var sources = Assert.Single(events, e => e.Name == "SearchPackageSourceSummary"); Assert.Equal(1, sources["NumHTTPv3Feeds"]); Assert.Equal("YesV3", sources["NuGetOrg"]); Assert.Equal(operationId, sources["ParentId"]); var page0 = Assert.Single(events, e => e.Name == "SearchPage" && e["PageIndex"] is int && (int)e["PageIndex"] == 0); Assert.Equal("Ready", page0["LoadingStatus"]); Assert.Equal(operationId, page0["ParentId"]); Assert.IsType <int>(page0["ResultCount"]); Assert.IsType <double>(page0["Duration"]); Assert.IsType <double>(page0["ResultsAggregationDuration"]); Assert.IsType <string>(page0["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page0["IndividualSourceDurations"])).Values <double>().Count()); var page1 = Assert.Single(events, e => e.Name == "SearchPage" && e["PageIndex"] is int && (int)e["PageIndex"] == 1); Assert.Equal("Ready", page1["LoadingStatus"]); Assert.Equal(operationId, page1["ParentId"]); Assert.IsType <int>(page1["ResultCount"]); Assert.IsType <double>(page1["Duration"]); Assert.IsType <double>(page1["ResultsAggregationDuration"]); Assert.IsType <string>(page1["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page1["IndividualSourceDurations"])).Values <double>().Count()); Assert.Equal(parsedOperationId, loader.State.OperationId); } }
internal static RemoteV2FindPackageByIdResourceTest Create() { var serviceAddress = ProtocolUtility.CreateServiceAddress(); var packageIdentity = new PackageIdentity( id: "xunit", version: NuGetVersion.Parse("2.2.0-beta1-build3239")); var testDirectory = TestDirectory.Create(); var packageSource = new PackageSource(serviceAddress); var package = SimpleTestPackageUtility.CreateFullPackage( testDirectory.Path, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var packageBytes = File.ReadAllBytes(package.FullName); var responses = new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > > { { serviceAddress, request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new TestContent(string.Empty) }) }, { serviceAddress + $"FindPackagesById()?id='{packageIdentity.Id}'", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new TestContent( ProtocolUtility.GetResource( "NuGet.Protocol.Tests.compiler.resources.XunitFindPackagesById.xml", typeof(RemoteV2FindPackageByIdResourceTest))) }) }, { serviceAddress + $"FindPackagesById()?id='{packageIdentity.Id.ToUpper()}'", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new TestContent( ProtocolUtility.GetResource( "NuGet.Protocol.Tests.compiler.resources.XunitFindPackagesById.xml", typeof(RemoteV2FindPackageByIdResourceTest))) }) }, { "https://www.nuget.org/api/v2/package/xunit/2.2.0-beta1-build3239", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(packageBytes) }) }, { serviceAddress + $"FindPackagesById()?id='a'", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.NoContent)) } }; var httpSource = new TestHttpSource(packageSource, responses); var resource = new RemoteV2FindPackageByIdResource( packageSource, httpSource); return(new RemoteV2FindPackageByIdResourceTest( resource, packageSource, package, packageIdentity, new SourceCacheContext(), httpSource, testDirectory)); }