public void NormalizesNavigationLinksWhenSet(string requestUri) { // Arrange var v2FeedPackage = new V2FeedPackage() { Id = "SomePackageId", Version = "1.0.0", Title = "Title", Authors = ".NET Foundation", LastUpdated = DateTime.UtcNow, Summary = "Summary" }; var annotationStrategy = new V2FeedPackageAnnotationStrategy(_contentType); var oDataEntry = new ODataEntry(); var dummyIdLink = new Uri("https://localhost"); oDataEntry.Id = dummyIdLink.ToString(); oDataEntry.EditLink = dummyIdLink; oDataEntry.ReadLink = dummyIdLink; var request = CreateHttpRequestMessage(requestUri); var expectedNormalizedLink = "https://localhost/api/v2/Packages(Id='SomePackageId',Version='1.0.0')"; // Act annotationStrategy.Annotate(request, oDataEntry, v2FeedPackage); // Assert Assert.Equal(expectedNormalizedLink, oDataEntry.ReadLink.ToString()); Assert.Equal(expectedNormalizedLink, oDataEntry.EditLink.ToString()); Assert.Equal(expectedNormalizedLink, oDataEntry.Id.ToString()); }
public List <Tuple <NuGetPackage, V2FeedPackage> > RetrieveInformationFromNuGet(List <NuGetPackage> packages) { List <Tuple <NuGetPackage, V2FeedPackage> > result = new List <Tuple <NuGetPackage, V2FeedPackage> >(); var context = new V2FeedContext(new Uri("https://www.nuget.org/api/v2")); foreach (var package in packages) { var packageExistsInRemoteLocation = context.Packages.Where(x => x.Id == package.Id).OrderByDescending(x => x.Version).Take(1).ToList().Any(); V2FeedPackage v2FeedPackage = null; if (packageExistsInRemoteLocation) { var nugetPackageInformations = context.Packages.Where(x => (x.Id == package.Id) && (x.Version == package.Version)).ToList(); v2FeedPackage = nugetPackageInformations.SingleOrDefault(); } result.Add(new Tuple <NuGetPackage, V2FeedPackage>(package, v2FeedPackage)); } return(result); }
public void CanNotAnnotateV2FeedPackage() { // Arrange var v2FeedPackage = new V2FeedPackage(); var annotationStrategy = new V1FeedPackageAnnotationStrategy(_contentType); // Act var canAnnotate = annotationStrategy.CanAnnotate(v2FeedPackage); // Assert Assert.False(canAnnotate); }
private static Result CreateUnistallResult(V2FeedPackage package, string icoPath) { return(new Result { Title = "Uninstall " + package.Title, IcoPath = icoPath, Action = (c) => { Uninstall(package.Id); return true; } }); }
public static Result CreatePackageListItem(V2FeedPackage package, Web.DownloadFileStatus downloadStatus = null) { var icoPath = downloadStatus == null || !downloadStatus.Status ? Parameters.DefaultIconPath : downloadStatus.FilePath; return(new Result { IcoPath = icoPath, Title = package.Title, SubTitle = string.Concat(package.Version, " - ", package.Description.Replace("\n", "")), ContextMenu = Lists.Of(CreateUnistallResult(package, icoPath)), Action = (c) => { Install(package.Id); return true; } }); }
public void RemoveVersionSortRemovesThenByOnVersion() { // Arrange var packageAb = new V2FeedPackage { Id = "A", Version = "B" }; var packageAa = new V2FeedPackage { Id = "A", Version = "A" }; var packageCa = new V2FeedPackage { Id = "C", Version = "A" }; var source = new[] { packageAb, packageCa, packageAa }.AsQueryable(); // Act var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Version); var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Version); // Assert Assert.Equal(new[] { packageAa, packageAb, packageCa }, resultA); Assert.Equal(new[] { packageAb, packageAa, packageCa }, resultB); }
public void RemoveVersionSortRemovesThenByWhenItIsNestedInsideAnotherThenBy() { // Arrange var packageAb = new V2FeedPackage { Id = "A", Version = "B" }; var packageAa = new V2FeedPackage { Id = "A", Version = "A" }; var packageAc = new V2FeedPackage { Id = "A", Version = "C" }; var source = new[] { packageAb, packageAc, packageAa }.AsQueryable(); // Act var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version); var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version); // Assert Assert.Equal(new[] { packageAc, packageAb, packageAa }, resultA); Assert.Equal(new[] { packageAb, packageAc, packageAa }, resultB); }
public static V2FeedPackage CreateV2FeedPackage(string ID, string version, global::System.DateTime created, int downloadCount, bool isLatestVersion, bool isAbsoluteLatestVersion, bool isPrerelease, global::System.DateTime lastUpdated, global::System.DateTime published, long packageSize, bool requireLicenseAcceptance, int versionDownloadCount) { V2FeedPackage v2FeedPackage = new V2FeedPackage(); v2FeedPackage.Id = ID; v2FeedPackage.Version = version; v2FeedPackage.Created = created; v2FeedPackage.DownloadCount = downloadCount; v2FeedPackage.IsLatestVersion = isLatestVersion; v2FeedPackage.IsAbsoluteLatestVersion = isAbsoluteLatestVersion; v2FeedPackage.IsPrerelease = isPrerelease; v2FeedPackage.LastUpdated = lastUpdated; v2FeedPackage.Published = published; v2FeedPackage.PackageSize = packageSize; v2FeedPackage.RequireLicenseAcceptance = requireLicenseAcceptance; v2FeedPackage.VersionDownloadCount = versionDownloadCount; return(v2FeedPackage); }
private static PackageMetadata Deserialize(V2FeedPackage package, ContextName context, RegistryKey contextKey, string nuGetSite) { return(new PackageMetadata { Authors = package.Authors, Description = package.Description, DownloadCount = package.DownloadCount, GalleryDetailsUrl = package.GalleryDetailsUrl, IconUrl = package.IconUrl, Id = package.Id, Published = package.Published, Tags = package.Tags, Title = package.Title, Version = package.Version, NuGetSite = nuGetSite, Dependencies = ParseDependencies(package.Dependencies), State = PackageRegistry.GetPackageState(contextKey, context, package.Id) }); }
public void SetsMediaResourceAnnotation() { // Arrange var v2FeedPackage = new V2FeedPackage() { Id = "SomePackageId", Version = "1.0.0", Title = "Title", Authors = ".NET Foundation", LastUpdated = DateTime.UtcNow, Summary = "Summary" }; var annotationStrategy = new V2FeedPackageAnnotationStrategy(_contentType); var oDataEntry = new ODataEntry(); var request = CreateHttpRequestMessage("https://localhost/api/v2/Packages"); // Act annotationStrategy.Annotate(request, oDataEntry, v2FeedPackage); // Assert Assert.Equal(_contentType, oDataEntry.MediaResource.ContentType); Assert.Equal("https://localhost/api/v2/package/SomePackageId/1.0.0", oDataEntry.MediaResource.ReadLink.ToString()); }
public void SetsAtomEntryMetadataAnnotation() { // Arrange var v2FeedPackage = new V2FeedPackage() { Id = "SomePackageId", Version = "1.0.0", Title = "Title", Authors = ".NET Foundation", LastUpdated = DateTime.UtcNow, Summary = "Summary" }; var annotationStrategy = new V2FeedPackageAnnotationStrategy(_contentType); var oDataEntry = new ODataEntry(); var request = CreateHttpRequestMessage("https://localhost/api/v2/Packages"); var expectedAtomEntryMetadataAnnotation = new AtomEntryMetadata() { Title = v2FeedPackage.Id, Authors = new[] { new AtomPersonMetadata { Name = v2FeedPackage.Authors } }, Updated = v2FeedPackage.LastUpdated, Summary = v2FeedPackage.Summary }; // Act annotationStrategy.Annotate(request, oDataEntry, v2FeedPackage); var actualAtomEntryMetadataAnnotation = oDataEntry.GetAnnotation <AtomEntryMetadata>(); // Assert Assert.Equal(expectedAtomEntryMetadataAnnotation.Title.Text, actualAtomEntryMetadataAnnotation.Title.Text); Assert.Equal(expectedAtomEntryMetadataAnnotation.Summary.Text, actualAtomEntryMetadataAnnotation.Summary.Text); Assert.Equal(expectedAtomEntryMetadataAnnotation.Authors.Single().Name, actualAtomEntryMetadataAnnotation.Authors.Single().Name); Assert.Equal(expectedAtomEntryMetadataAnnotation.Updated, actualAtomEntryMetadataAnnotation.Updated); }
public static V2FeedPackage CreateV2FeedPackage(string ID, string version, global::System.DateTime created, int downloadCount, bool isLatestVersion, bool isAbsoluteLatestVersion, bool isPrerelease, global::System.DateTime lastUpdated, global::System.DateTime published, long packageSize, bool requireLicenseAcceptance, int versionDownloadCount) { V2FeedPackage v2FeedPackage = new V2FeedPackage(); v2FeedPackage.Id = ID; v2FeedPackage.Version = version; v2FeedPackage.Created = created; v2FeedPackage.DownloadCount = downloadCount; v2FeedPackage.IsLatestVersion = isLatestVersion; v2FeedPackage.IsAbsoluteLatestVersion = isAbsoluteLatestVersion; v2FeedPackage.IsPrerelease = isPrerelease; v2FeedPackage.LastUpdated = lastUpdated; v2FeedPackage.Published = published; v2FeedPackage.PackageSize = packageSize; v2FeedPackage.RequireLicenseAcceptance = requireLicenseAcceptance; v2FeedPackage.VersionDownloadCount = versionDownloadCount; return v2FeedPackage; }
public void AddToPackages(V2FeedPackage v2FeedPackage) { base.AddObject("Packages", v2FeedPackage); }
private static void AssertPackage(dynamic expected, V2FeedPackage package) { Assert.Equal(expected.Id, package.Id); Assert.Equal(expected.Version, package.Version); }
public static Web.DownloadFileInformation ToDownloadFileInformation(this V2FeedPackage package) { return(new Web.DownloadFileInformation(package.Id, package.IconUrl)); }