public void GetReportAbuseUrlFallsBackToDefaultForInvalidUriTemplate(string uriTemplate) { const string expectedResult = "https://www.nuget.org/packages/TestPackage/1.0.0/ReportAbuse"; var resource = new ReportAbuseResourceV3(uriTemplate); var actual = resource.GetReportAbuseUrl("TestPackage", NuGetVersion.Parse("1.0.0")); Assert.Equal(expectedResult, actual.ToString()); }
public void GetReportAbuseUrlReplacesIdAndVersionTokensInUriTemplateWhenAvailable() { const string uriTemplate = "https://test.nuget.org/ReportAbuse/{id}/{version}"; const string expectedResult = "https://test.nuget.org/ReportAbuse/TestPackage/1.0.0"; var resource = new ReportAbuseResourceV3(uriTemplate); var actual = resource.GetReportAbuseUrl("TestPackage", NuGetVersion.Parse("1.0.0")); Assert.Equal(expectedResult, actual.ToString()); }
public UIPackageMetadata ParseMetadata(JObject metadata) { NuGetVersion version = NuGetVersion.Parse(metadata.Value <string>(Properties.Version)); DateTimeOffset?published = null; var publishedToken = metadata[Properties.Published]; if (publishedToken != null) { published = publishedToken.ToObject <DateTimeOffset>(); } string id = metadata.Value <string>(Properties.PackageId); string title = metadata.Value <string>(Properties.Title); string summary = metadata.Value <string>(Properties.Summary); string description = metadata.Value <string>(Properties.Description); string authors = GetField(metadata, Properties.Authors); string owners = GetField(metadata, Properties.Owners); Uri iconUrl = GetUri(metadata, Properties.IconUrl); Uri licenseUrl = GetUri(metadata, Properties.LicenseUrl); Uri projectUrl = GetUri(metadata, Properties.ProjectUrl); string tags = GetField(metadata, Properties.Tags); IEnumerable <PackageDependencyGroup> dependencySets = (metadata.Value <JArray>(Properties.DependencyGroups) ?? Enumerable.Empty <JToken>()).Select(obj => LoadDependencySet((JObject)obj)); bool requireLicenseAcceptance = metadata[Properties.RequireLicenseAcceptance] == null ? false : metadata[Properties.RequireLicenseAcceptance].ToObject <bool>(); Uri reportAbuseUrl = _reportAbuseResource != null? _reportAbuseResource.GetReportAbuseUrl(id, version) : null; if (String.IsNullOrEmpty(title)) { // If no title exists, use the Id title = id; } return(new UIPackageMetadata( new PackageIdentity(id, version), title, summary, description, authors, owners, iconUrl, licenseUrl, projectUrl, reportAbuseUrl, tags, published, dependencySets, requireLicenseAcceptance)); }
public UIPackageMetadata ParseMetadata(JObject metadata) { var version = NuGetVersion.Parse(metadata.Value <string>(Properties.Version)); DateTimeOffset?published = null; var publishedToken = metadata[Properties.Published]; if (publishedToken != null) { published = publishedToken.ToObject <DateTimeOffset>(); } var downloadCountString = metadata.Value <string>(Properties.DownloadCount); int?downloadCountValue; int downloadCount; if (int.TryParse( downloadCountString, NumberStyles.None, CultureInfo.InvariantCulture, out downloadCount)) { downloadCountValue = downloadCount; } else { downloadCountValue = null; } var id = metadata.Value <string>(Properties.PackageId); var title = metadata.Value <string>(Properties.Title); var summary = metadata.Value <string>(Properties.Summary); var description = metadata.Value <string>(Properties.Description); var authors = GetField(metadata, Properties.Authors); var owners = GetField(metadata, Properties.Owners); var iconUrl = GetUri(metadata, Properties.IconUrl); var licenseUrl = GetUri(metadata, Properties.LicenseUrl); var projectUrl = GetUri(metadata, Properties.ProjectUrl); var tags = GetField(metadata, Properties.Tags); var dependencySets = (metadata.Value <JArray>(Properties.DependencyGroups) ?? Enumerable.Empty <JToken>()).Select(obj => LoadDependencySet((JObject)obj)); var requireLicenseAcceptance = metadata[Properties.RequireLicenseAcceptance] == null ? false : metadata[Properties.RequireLicenseAcceptance].ToObject <bool>(); var reportAbuseUrl = _reportAbuseResource != null? _reportAbuseResource.GetReportAbuseUrl(id, version) : null; if (String.IsNullOrEmpty(title)) { // If no title exists, use the Id title = id; } return(new UIPackageMetadata( new PackageIdentity(id, version), title, summary, description, authors, owners, iconUrl, licenseUrl, projectUrl, reportAbuseUrl, tags, published, dependencySets, requireLicenseAcceptance, downloadCountValue)); }