예제 #1
0
        public void SetUp()
        {
            packageServiceMock
            .Setup(packageService => packageService.GetAllAsync())
            .ReturnsAsync(packages);

            packageServiceMock
            .Setup(packageService => packageService.GetNewlyAddedPackagesAsync())
            .ReturnsAsync(packages);

            nugetApiServiceMock
            .Setup(nugetApiService => nugetApiService.GetLatestPackageVersionAsync(nUnitPackage.Name))
            .ReturnsAsync(nUnitVersion);

            nugetApiServiceMock
            .Setup(nugetApiService => nugetApiService.GetLatestPackageVersionAsync(moqPackage.Name))
            .ReturnsAsync(moqVersion);

            nugetApiServiceMock
            .Setup(nugetApiService => nugetApiService.GetPackagePublishedDateByVersionAsync(
                       nUnitPackage.Name,
                       nUnitVersion
                       .GetVersion()
                       .ToString()))
            .ReturnsAsync(nUnitVersion.PublishedDate);

            nugetApiServiceMock
            .Setup(nugetApiService => nugetApiService.GetPackagePublishedDateByVersionAsync(
                       moqPackage.Name,
                       moqVersion
                       .GetVersion()
                       .ToString()))
            .ReturnsAsync(moqVersion.PublishedDate);
        }
        private async Task AddOrUpdateLatestVersionsAsync(IEnumerable <PackageVersion> versions, IReadOnlyCollection <PackageVersion> latestVersions)
        {
            foreach (PackageVersion packageVersion in versions)
            {
                PackageVersion latestVersion = latestVersions.First(latestPackageVersion => latestPackageVersion.PackageId == packageVersion.PackageId);

                Package package = latestVersion.Package;
                package.LastUpdateTime = dateTimeProvider.CurrentUtcDateTime;
                PackageRepository.Update(package);

                if (latestVersion.GetVersion() == packageVersion.GetVersion())
                {
                    latestVersion.PublishedDate = packageVersion.PublishedDate;
                    PackageVersionsRepository.Update(latestVersion);
                }
                else
                {
                    PackageVersionsRepository.Add(packageVersion);
                }
            }

            await uow.SaveChangesAsync();
        }
예제 #3
0
        private async Task <PackageVersion> GetLatestVersionOfPackageAsync(Package package)
        {
            PackageVersion version = null;

            try
            {
                version = await nugetApiService.GetLatestPackageVersionAsync(package.Name);

                version.PublishedDate = await nugetApiService
                                        .GetPackagePublishedDateByVersionAsync(package.Name, version.GetVersion().ToString());
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(null);
            }

            version.PackageId = package.Id;
            return(version);
        }