public async Task SuccessfullyUpdatesPackages(PackageLatestState latestState, bool listed) { var packages = GetPackagesForTest(latestState, listed); await SetupAndInvokeMethod(packages, true); _mockDatabase.Verify(); }
public async Task SuccessfullyUpdatesPackagesWithMultipleRegistrations(PackageLatestState latestState, bool listed) { var firstPackages = GetPackagesForTest(latestState, listed, 0); var secondPackages = GetPackagesForTest(latestState, listed, 1); var allPackages = firstPackages.Concat(secondPackages).ToList(); await SetupAndInvokeMethod(allPackages, true); _mockDatabase.Verify(); _mockIndexingService.Verify(); }
public async Task ThrowsWhenPackageIsLatest(PackageLatestState latestState) { var packageRegistration = new PackageRegistration { Id = "theId" }; var package = new Package { Version = "1.0", PackageRegistration = packageRegistration, Listed = false }; SetLatestOfPackage(package, latestState); var service = Get <PackageUpdateService>(); await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.MarkPackageListedAsync(package)); }
private static void SetLatestOfPackage(Package package, PackageLatestState latestState) { switch (latestState) { case PackageLatestState.Latest: package.IsLatest = true; break; case PackageLatestState.LatestStable: package.IsLatestStable = true; break; case PackageLatestState.LatestSemVer2: package.IsLatestSemVer2 = true; break; case PackageLatestState.LatestStableSemVer2: package.IsLatestStableSemVer2 = true; break; } }
public async Task OnLatestPackageVersionSetsPreviousToLatestVersion(PackageLatestState packageLatestState) { var packageRegistration = new PackageRegistration { Id = "theId" }; var firstPackage = new Package { Version = "1.0.1", PackageRegistration = packageRegistration }; SetLatestOfPackage(firstPackage, packageLatestState); var secondPackage = new Package { Version = "1.0.0", PackageRegistration = packageRegistration }; var packages = new[] { firstPackage, secondPackage }.ToList(); packageRegistration.Packages = packages; var packageService = GetMock <IPackageService>(); if (packageLatestState != PackageLatestState.Not) { packageService .Setup(x => x.UpdateIsLatestAsync(packageRegistration, false)) .Returns(Task.CompletedTask) .Verifiable(); } var service = Get <PackageUpdateService>(); await service.MarkPackageUnlistedAsync(firstPackage); packageService.Verify(); }
private IReadOnlyList <Package> GetPackagesForTest(PackageLatestState latestState, bool listed, int number = 0) { var registration = new PackageRegistration { Id = "updatePackagesAsyncTest" + number }; Package unselectedPackage; if (latestState == PackageLatestState.Not) { unselectedPackage = new Package { Key = 1 + number * 100, Version = "3.0.0", PackageRegistration = registration, IsLatest = true, IsLatestStable = true, IsLatestSemVer2 = true, IsLatestStableSemVer2 = true, Listed = true }; } else { unselectedPackage = new Package { Key = 1 + number * 100, Version = "1.0.0", PackageRegistration = registration, IsLatest = false, IsLatestStable = false, IsLatestSemVer2 = false, IsLatestStableSemVer2 = false, Listed = true }; } registration.Packages.Add(unselectedPackage); var selectedListedPackage = new Package { Key = 2 + number * 100, Version = "2.0.0", PackageRegistration = registration, Listed = true }; registration.Packages.Add(selectedListedPackage); var selectedUnlistedPackage = new Package { Key = 3 + number * 100, Version = "2.1.0", PackageRegistration = registration, Listed = false }; registration.Packages.Add(selectedUnlistedPackage); var selectedMaybeLatestPackage = new Package { Key = 4 + number * 100, Version = "2.5.0", PackageRegistration = registration, Listed = listed }; registration.Packages.Add(selectedMaybeLatestPackage); SetLatestOfPackage(selectedMaybeLatestPackage, latestState); return(new[] { selectedListedPackage, selectedUnlistedPackage, selectedMaybeLatestPackage }); }
public Task ThrowsWhenSqlQueryFails(PackageLatestState latestState, bool listed) { var packages = GetPackagesForTest(latestState, listed); return(Assert.ThrowsAsync <InvalidOperationException>(() => SetupAndInvokeMethod(packages, false))); }