public ValidatePackageHashHandlerFacts() { var messageHandler = new MockServerHttpClientHandler(); messageHandler.SetAction( "/packages/testunsigned.1.0.0.nupkg", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(File.OpenRead("Packages\\TestUnsigned.1.0.0.nupkg")) } )); _packageEntry = new CatalogIndexEntry( new Uri("http://localhost/catalog/entry.json"), "nuget:PackageDetails", "123", DateTime.UtcNow, PackageIdentity); _blob = new Mock <ICloudBlockBlob>(); _blob.Setup(b => b.Uri).Returns(new Uri("http://localhost/packages/testunsigned.1.0.0.nupkg")); _telemetryService = new Mock <ITelemetryService>(); _target = new ValidatePackageHashHandler( new HttpClient(messageHandler), _telemetryService.Object, Mock.Of <ILogger <ValidatePackageHashHandler> >()); }
public static async Task <PackageTimestampMetadata> FromCatalogEntry( CollectorHttpClient client, CatalogIndexEntry catalogEntry) { var catalogLeaf = await client.GetJObjectAsync(catalogEntry.Uri); try { if (catalogEntry.IsDelete) { // On the catalog page for a delete, the published value is the timestamp the package was deleted from the audit records. var deleted = catalogLeaf.GetValue("published").Value <DateTimeOffset>(); return(CreateForPackageMissingFromFeed(deleted.DateTime)); } else { var created = catalogLeaf.GetValue("created").Value <DateTimeOffset>(); var lastEdited = catalogLeaf.GetValue("lastEdited").Value <DateTimeOffset>(); return(CreateForPackageExistingOnFeed(created.DateTime, lastEdited.DateTime)); } } catch (Exception e) { throw new ArgumentException("Failed to create PackageTimestampMetadata from CatalogIndexEntry!", e); } }
public async Task FromCatalogEntry_HandlesDeleted_NotNull() { // Arrange var catalogStorage = Catalogs.CreateTestCatalogWithThreePackagesAndDelete(); var client = await CreateDummyClient(catalogStorage); var expectedTimestamp = DateTime.Parse("2015-01-01T01:01:01.0748028"); var uri = new Uri(catalogStorage.BaseAddress, "data/2015.10.13.06.40.07/otherpackage.1.0.0.json"); var catalogIndexEntry = new CatalogIndexEntry( uri, CatalogConstants.NuGetPackageDelete, "afc8c1f4-486e-4142-b3ec-cf5841eb8883", DateTime.ParseExact( "2015-10-13T06:40:07.7850657Z", CatalogConstants.CommitTimeStampFormat, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal), new PackageIdentity("OtherPackage", new NuGetVersion("1.0.0"))); // Act var entry = await PackageTimestampMetadata.FromCatalogEntry(client, catalogIndexEntry); // Assert Assert.False(entry.Exists); Assert.Null(entry.Created); Assert.Null(entry.LastEdited); Assert.Equal(expectedTimestamp.Ticks, entry.Deleted.Value.Ticks); Assert.Equal(expectedTimestamp.Ticks, entry.Last.Value.Ticks); }
public void IsDelete_WhenTypeIsPackageDelete_ReturnsTrue() { var entry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDelete, _commitId, _commitTimeStamp, _packageIdentity); Assert.True(entry.IsDelete); }
public void CompareTo_WhenOtherIsNull_Throws() { var entry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDetails, _commitId, _commitTimeStamp, _packageIdentity); var exception = Assert.Throws <ArgumentNullException>(() => entry.CompareTo(other: null)); Assert.Equal("other", exception.ParamName); }
public void Entries_ReturnsCorrectValue() { var entry = new CatalogIndexEntry( new Uri("https://nuget.test"), CatalogConstants.NuGetPackageDetails, Guid.NewGuid().ToString(), DateTime.UtcNow, _packageIdentity); var entries = new[] { entry }; var context = CreateContext(entries: entries); Assert.Equal(entries.Length, context.Entries.Count); Assert.Same(entry, context.Entries[0]); }
public void Create_WhenArgumentIsValid_ReturnsInstance() { var contextJObject = TestUtility.CreateCatalogContextJObject(); var commitItemJObject = TestUtility.CreateCatalogCommitItemJObject(_commitTimeStamp, _packageIdentity); var commitItem = CatalogCommitItem.Create(contextJObject, commitItemJObject); var entry = CatalogIndexEntry.Create(commitItem); Assert.Equal(_uri.AbsoluteUri, entry.Uri.AbsoluteUri); Assert.Equal(CatalogConstants.NuGetPackageDetails, entry.Types.Single()); Assert.Equal(commitItemJObject[CatalogConstants.CommitId].ToString(), entry.CommitId); Assert.Equal(_commitTimeStamp, entry.CommitTimeStamp.ToUniversalTime()); Assert.Equal(_packageId, entry.Id); Assert.Equal(_packageVersion, entry.Version); }
public void JsonSerialization_ReturnsCorrectJson() { var entry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDetails, _commitId, _commitTimeStamp, _packageIdentity); var jObject = CreateCatalogIndexJObject(CatalogConstants.NuGetPackageDetails); var expectedResult = jObject.ToString(Formatting.None, _settings.Converters.ToArray()); var actualResult = JsonConvert.SerializeObject(entry, Formatting.None, _settings); Assert.Equal(expectedResult, actualResult); }
public void Constructor_WhenArgumentsAreValid_ReturnsInstance() { var entry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDetails, _commitId, _commitTimeStamp, _packageIdentity); Assert.Equal(_uri.AbsoluteUri, entry.Uri.AbsoluteUri); Assert.Equal(CatalogConstants.NuGetPackageDetails, entry.Types.Single()); Assert.Equal(_commitId, entry.CommitId); Assert.Equal(_commitTimeStamp, entry.CommitTimeStamp); Assert.Equal(_packageId, entry.Id); Assert.Equal(_packageVersion, entry.Version); }
public static void AssertCatalogIndexEntry(CatalogIndexEntry expected, CatalogIndexEntry actual) { if (expected == null) { Assert.Null(actual); return; } AssertFieldEqual(expected, actual, i => i.Uri); AssertFieldEqual(expected, actual, i => i.Types); AssertFieldEqual(expected, actual, i => i.Id); AssertFieldEqual(expected, actual, i => i.Version); AssertFieldEqual(expected, actual, i => i.CommitId); AssertFieldEqual(expected, actual, i => i.CommitTimeStamp); }
public void CompareTo_WhenCommitTimeStampsAreEqual_ReturnsZero() { var entry0 = new CatalogIndexEntry( new Uri("https://nuget.test/a"), CatalogConstants.NuGetPackageDetails, _commitId, _commitTimeStamp, _packageIdentity); var entry1 = new CatalogIndexEntry( new Uri("https://nuget.test/b"), CatalogConstants.NuGetPackageDelete, Guid.NewGuid().ToString(), _commitTimeStamp, new PackageIdentity(id: "b", version: new NuGetVersion("4.5.6"))); Assert.Equal(0, entry0.CompareTo(entry0)); Assert.Equal(0, entry0.CompareTo(entry1)); Assert.Equal(0, entry1.CompareTo(entry0)); }
public void CompareTo_WhenCommitTimeStampsAreNotEqual_ReturnsNonZero() { var now = DateTime.UtcNow; var olderEntry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDetails, _commitId, now.AddHours(-1), _packageIdentity); var newerEntry = new CatalogIndexEntry( _uri, CatalogConstants.NuGetPackageDetails, _commitId, now, _packageIdentity); Assert.Equal(-1, olderEntry.CompareTo(newerEntry)); Assert.Equal(1, newerEntry.CompareTo(olderEntry)); }
public static async Task <PackageTimestampMetadata> FromCatalogEntry( CollectorHttpClient client, CatalogIndexEntry catalogEntry) { var uri = catalogEntry.Uri; if (_catalogEntryUriHostMap.TryGetValue(catalogEntry.Uri.Host, out var replacementHost)) { var builder = new UriBuilder(uri) { Host = replacementHost }; uri = builder.Uri; } var catalogLeaf = await client.GetJObjectAsync(uri); try { if (catalogEntry.IsDelete) { // On the catalog page for a delete, the published value is the timestamp the package was deleted from the audit records. var deleted = catalogLeaf.GetValue("published").Value <DateTimeOffset>(); return(CreateForMissingPackage(deleted.DateTime)); } else { var created = catalogLeaf.GetValue("created").Value <DateTimeOffset>(); var lastEdited = catalogLeaf.GetValue("lastEdited").Value <DateTimeOffset>(); return(CreateForExistingPackage(created.DateTime, lastEdited.DateTime)); } } catch (Exception e) { throw new ArgumentException("Failed to create PackageTimestampMetadata from CatalogIndexEntry!", e); } }
public PackagesContainerCatalogProcessorFacts() { _rawBlob = new Mock <CloudBlockBlob>(MockBehavior.Strict, new Uri("http://localhost/packages/testpackage.1.0.0.nupkg")); var container = new Mock <CloudBlobContainer>(MockBehavior.Strict, new Uri("http://localhost/packages/")); container.Setup(c => c.GetBlockBlobReference("testpackage.1.0.0.nupkg")).Returns(_rawBlob.Object); _catalogEntry = new CatalogIndexEntry( new Uri("http://localhost/catalog/entry.json"), "nuget:PackageDetails", "123", DateTime.UtcNow, PackageIdentity); _handler = new Mock <IPackagesContainerHandler>(); _telemetryService = new Mock <ITelemetryService>(); _target = new PackagesContainerCatalogProcessor( container.Object, _handler.Object, _telemetryService.Object, Mock.Of <ILogger <PackagesContainerCatalogProcessor> >()); }
public void Create_WhenCommitItemIsNull_Throws() { var exception = Assert.Throws <ArgumentNullException>(() => CatalogIndexEntry.Create(commitItem: null)); Assert.Equal("commitItem", exception.ParamName); }
private ConcurrentBag<CatalogIndexEntry> GetEntries(IEnumerable<Uri> pageUris) { ConcurrentBag<CatalogIndexEntry> entries = new ConcurrentBag<CatalogIndexEntry>(); ParallelOptions options = new ParallelOptions(); options.MaxDegreeOfParallelism = 8; Parallel.ForEach(pageUris.ToArray(), options, uri => { var task = _httpClient.GetJObjectAsync(uri); task.Wait(); JObject json = task.Result; foreach (var item in json["items"]) { var entry = new CatalogIndexEntry(new Uri(item["@id"].ToString()), item["@type"].ToString(), item["commitId"].ToString(), DateTime.Parse(item["commitTimeStamp"].ToString()), item["nuget:id"].ToString(), NuGetVersion.Parse(item["nuget:version"].ToString())); entries.Add(entry); } }); return entries; }