public async Task UpdateSavesNewStatus() { // Arrange var feedPackageIdentity = new FeedPackageIdentity("howdy", "3.4.6"); var packageValidationResult = new PackageValidationResult( new PackageIdentity(feedPackageIdentity.Id, new NuGetVersion(feedPackageIdentity.Version)), null, null, Enumerable.Empty <AggregateValidationResult>()); var status = new PackageMonitoringStatus(packageValidationResult); var storageFactory = new MemoryStorageFactory(); var statusService = new PackageMonitoringStatusService( storageFactory, new Mock <ILogger <PackageMonitoringStatusService> >().Object); // Act await statusService.UpdateAsync(status, CancellationToken.None); // Assert Assert.True( storageFactory.Create( PackageState.Valid.ToString().ToLowerInvariant()) .Exists(GetPackageFileName(feedPackageIdentity.Id, feedPackageIdentity.Version))); }
public async Task GetByPackageDeserializationException() { // Arrange var desiredPackageId = "brokenpackage"; var desiredPackageVersion = "99.9.99"; var storageFactory = new MemoryStorageFactory(); var storage = storageFactory.Create(PackageState.Valid.ToString().ToLowerInvariant()); await storage.SaveAsync( storage.ResolveUri($"{desiredPackageId}/{desiredPackageId}.{desiredPackageVersion}.json"), new StringStorageContent("this isn't json"), CancellationToken.None); var statusService = new PackageMonitoringStatusService( storageFactory, new Mock <ILogger <PackageMonitoringStatusService> >().Object); // Act var status = await statusService.GetAsync(new FeedPackageIdentity(desiredPackageId, desiredPackageVersion), CancellationToken.None); // Assert Assert.Equal(desiredPackageId, status.Package.Id); Assert.Equal(desiredPackageVersion, status.Package.Version); Assert.IsType <StatusDeserializationException>(status.ValidationException); }
private async Task <MemoryStorage> ProcessAsync( IReadOnlyDictionary <string, IGraph> newItems, string packageId, int partitionSize, int packageCountThreshold = _defaultPackageCountThreshold, bool filterOutDeprecation = false) { var registrationKey = new RegistrationKey(packageId?.ToLowerInvariant() ?? string.Empty); await RegistrationMaker.ProcessAsync( registrationKey, newItems, (g, u, k) => true, _storageFactory, filterOutDeprecation?RegistrationCollector.FilterOutDeprecationInformation : g => g, _contentBaseAddress, _galleryBaseAddress, partitionSize, packageCountThreshold, forcePackagePathProviderForIcons : false, telemetryService : _telemetryService.Object, cancellationToken : CancellationToken.None); return((MemoryStorage)_storageFactory.Create(registrationKey.ToString())); }
public async Task UpdateDeletesOldStatuses() { // Arrange var feedPackageIdentity = new FeedPackageIdentity("howdy", "3.4.6"); var packageFileName = GetPackageFileName(feedPackageIdentity.Id, feedPackageIdentity.Version); var packageValidationResult = new PackageValidationResult( new PackageIdentity(feedPackageIdentity.Id, new NuGetVersion(feedPackageIdentity.Version)), null, null, Enumerable.Empty <AggregateValidationResult>()); var status = new PackageMonitoringStatus(packageValidationResult); var storageFactory = new MemoryStorageFactory(); var statusService = new PackageMonitoringStatusService( storageFactory, new Mock <ILogger <PackageMonitoringStatusService> >().Object); foreach (var state in Enum.GetNames(typeof(PackageState))) { var storage = storageFactory.Create(state.ToLowerInvariant()); await storage.SaveAsync(storage.ResolveUri(packageFileName), new StringStorageContent("{}"), CancellationToken.None); Assert.True(storage.Exists(packageFileName)); } // Act await statusService.UpdateAsync(status, CancellationToken.None); // Assert foreach (var state in Enum.GetNames(typeof(PackageState))) { var storage = storageFactory.Create(state.ToLowerInvariant()); if ((PackageState)Enum.Parse(typeof(PackageState), state) == status.State) { Assert.True(storage.Exists(packageFileName)); } else { Assert.False(storage.Exists(packageFileName)); } } AssertStatus(status, await statusService.GetAsync(feedPackageIdentity, CancellationToken.None)); }
private bool DoesPackageExists(MemoryStorageFactory storageFactory, PackageState state, FeedPackageIdentity package) { var stateName = Enum.GetName(typeof(PackageState), state); var storage = storageFactory.Create(stateName.ToLowerInvariant()); var packageFileName = GetPackageFileName(package.Id, package.Version); return(storage.Exists(packageFileName)); }
private Task SaveToStorage(MemoryStorageFactory storageFactory, PackageState state, FeedPackageIdentity package, StorageContent content) { var stateName = Enum.GetName(typeof(PackageState), state); var storage = storageFactory.Create(stateName.ToLowerInvariant()); var packageFileName = GetPackageFileName(package.Id, package.Version); return(storage.SaveAsync(storage.ResolveUri(packageFileName), content, CancellationToken.None)); }
private async Task <MemoryStorage> ProcessAsync( IReadOnlyDictionary <string, IGraph> newItems, string packageId, int partitionSize, int packageCountThreshold = _defaultPackageCountThreshold) { var registrationKey = new RegistrationKey(packageId?.ToLowerInvariant() ?? string.Empty); await RegistrationMaker.ProcessAsync( registrationKey, newItems, _storageFactory, _contentBaseAddress, partitionSize, packageCountThreshold, _telemetryService.Object, CancellationToken.None); return((MemoryStorage)_storageFactory.Create(registrationKey.ToString())); }