Ejemplo n.º 1
0
        public void ShouldReturnAllUnfinishedPackagesOfTheRequestedIds()
        {
            const string requestedId1 = "MySuperPackageId";
            const string requestedId2 = "MyOtherPackageId";
            const string requestedId3 = "AnotherPackage";
            var expectedPackage1 = new Package { Id = requestedId1, Version = "5.88.8" };
            var expectedPackage2 = new Package { Id = requestedId2, Version = "1.5.35" };
            var unexpectedPackage1 = new Package { Id = requestedId3, Version = "7.8.9" };
            var unexpectedPackage2 = new Package { Id = requestedId2, Version = "66.88.8" };

            var packages = new[]
            {
                expectedPackage2,
                new Package { Id = "SomePackage", Version = "3.4.5" },
                expectedPackage1,
                unexpectedPackage2,
                unexpectedPackage1,
            };
            var publishedPackages = new[]
            {
                new PublishedPackage { Id = unexpectedPackage2.Id, Version = unexpectedPackage2.Version },
                new PublishedPackage { Id = unexpectedPackage1.Id, Version = unexpectedPackage1.Version },
            };
            _mockedPackageRepository.SetupGet(pr => pr.Collection).Returns(packages.AsQueryable());
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages.AsQueryable());

            var unfinishedPackages = _unfinishedPackageGetter.GetUnfinishedPackages(Guid.NewGuid().ToString(), new[] { requestedId1, requestedId2, requestedId3 });

            CollectionAssert.Contains(unfinishedPackages, expectedPackage1, "Expected Package should have been returned.");
            CollectionAssert.Contains(unfinishedPackages, expectedPackage2, "Expected Package should have been returned.");
            CollectionAssert.DoesNotContain(unfinishedPackages, unexpectedPackage1, "Package should not have been returned since it was in the Feed.");
            CollectionAssert.DoesNotContain(unfinishedPackages, unexpectedPackage2, "Package should not have been returned since it was in the Feed.");
        }
Ejemplo n.º 2
0
 private void UnsetRecommendedVersion(Package package, PublishedPackage publishedPackage)
 {
     package.IsLatestVersion = false;
     publishedPackage.IsLatestVersion = false;
     _packageRepository.Update(package);
     _publishedPackageRepository.Update(publishedPackage);
 }
        public void PrimaryCategoryShouldBeEmptyStringWhenCategoriesIsNullOrEmpty(string categories) {
            Package packageToMapFrom = new Package {Categories = categories};

            PackageViewModel packageViewModel = _packageViewModelMapper.MapPackageToViewModel(packageToMapFrom, false);

            Assert.IsEmpty(packageViewModel.PrimaryCategory, "PrimaryCategory should be empty.");
        }
Ejemplo n.º 4
0
 private static void VerifyPackageIsInPublishedState(Package package, PublishedPackage publishedPackage)
 {
     if (package.Published == Constants.UnpublishedDate || publishedPackage == null || publishedPackage.Published == Constants.UnpublishedDate)
     {
         throw new InvalidOperationException("Cannot Unpublish a Package that is not currently Published.");
     }
 }
        public void TagsShouldBeSetToGivenTagsWhenTheyAreNullEmptyOrWhiteSpace(string tags) {
            Package packageToMapTo = new Package();

            _packageViewModelMapper.MapViewModelToPackage(new PackageViewModel { Tags = tags}, packageToMapTo);

            Assert.AreEqual(tags, packageToMapTo.Tags, "Tags should have been equal to each other.");
        }
Ejemplo n.º 6
0
 private void Unpublish(Package package, PublishedPackage publishedPackage)
 {
     package.Published = Constants.UnpublishedDate;
     publishedPackage.Published = Constants.UnpublishedDate;
     _packageRepository.Update(package);
     _publishedPackageRepository.Update(publishedPackage);
 }
        public void IsExternalPackageShouldBeTrueWhenExternalPackageUrlHasValue()
        {
            Package packageToMapFrom = new Package { ExternalPackageUrl = "http://google.com" };

            PackageViewModel packageViewModel = _packageViewModelMapper.MapPackageToViewModel(packageToMapFrom, false);

            Assert.IsTrue(packageViewModel.IsExternalPackage, "IsExternalPackage should be true when ExternalPackageUrl is present.");
        }
        public void IsExternalPackageShouldBeFalseWhenExternalPackageUrlIsNullEmptyOrWhiteSpace(string externalPackageUrl)
        {
            Package packageToMapFrom = new Package { ExternalPackageUrl = externalPackageUrl };

            PackageViewModel packageViewModel = _packageViewModelMapper.MapPackageToViewModel(packageToMapFrom, false);

            Assert.IsFalse(packageViewModel.IsExternalPackage, "IsExternalPackage should be false when ExternalPackageUrl is not present.");
        }
        public void PrimaryCategoryShouldBeFirstCategoryInListOfCategories() {
            const string expectedCategory = "Fish";
            Package packageToMapFrom = new Package { Categories = string.Format("{0},Chips,Meat", expectedCategory) };

            PackageViewModel packageViewModel = _packageViewModelMapper.MapPackageToViewModel(packageToMapFrom, false);

            Assert.AreEqual(expectedCategory, packageViewModel.PrimaryCategory, "PrimaryCategory was not mapped correctly.");
        }
Ejemplo n.º 10
0
        public void ShouldCreateLogEntryForGivenVersionWhenToldTo()
        {
            Package packageToRecommend = new Package { Id = "Foo", Version = "1.1", IsLatestVersion = false };

            _setter.SetAsRecommendedVersion(packageToRecommend, true);

            _mockedPackageLogEntryCreator.Verify(plec => plec.Create(packageToRecommend.Id, packageToRecommend.Version, PackageLogAction.Update), Times.Once());
        }
Ejemplo n.º 11
0
        public void ShouldCallVersionRepositoryToGetCollection()
        {
            Package package = new Package {Id = "Foo", Version = "1.0"};

            _setter.SetAsRecommendedVersion(package, true);

            _mockedPackageRepository.VerifyGet(pr => pr.Collection, Times.Once());
        }
Ejemplo n.º 12
0
        public void ShouldNotMapScreenshotsProperty()
        {
            Package package = new Package {Screenshots = new[] {new Screenshot(), new Screenshot()}};

            Package mappedPackage = Mapper.Map<Package, Package>(package);

            Assert.IsNull(mappedPackage.Screenshots, "Screenshots property should be null (i.e. should not have been mapped).");
        }
Ejemplo n.º 13
0
        public void ShouldNotMapRatingsCount()
        {
            Package package = new Package { RatingsCount = 99 };

            Package mappedPackage = Mapper.Map<Package, Package>(package);

            Assert.AreNotEqual(package.RatingsCount, mappedPackage.RatingsCount, "RatingsCount should not have been mapped.");
        }
Ejemplo n.º 14
0
        public void ShouldNotMapDownloadCount()
        {
            Package package = new Package {DownloadCount = 45};

            Package mappedPackage = Mapper.Map<Package, Package>(package);

            Assert.AreNotEqual(package.DownloadCount, mappedPackage.DownloadCount, "DownloadCount should not have been mapped.");
        }
Ejemplo n.º 15
0
        public void ShouldValidatePackageUrisWithPackageUriValidator()
        {
            var packageToUpdate = new Package();

            _packageUpdater.UpdateExistingPackage(packageToUpdate);

            _mockedPackageUriValidator.Verify(puv => puv.ValidatePackageUris(packageToUpdate), Times.Once());
        }
Ejemplo n.º 16
0
        public void DescriptionShouldBeNullWhenEmptyOrWhitespaceStringGiven(string description)
        {
            Package packageToMapFrom = new Package { Description = description };

            PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(packageToMapFrom);

            Assert.IsNull(publishedPackage.Description, "Description should have been null.");
        }
Ejemplo n.º 17
0
        public void CategoriesShouldBeNullWhenEmptyOrWhitespaceStringGiven(string categories)
        {
            Package packageToMapFrom = new Package { Categories = categories };

            PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(packageToMapFrom);

            Assert.IsNull(publishedPackage.Categories, "Categories should have been null.");
        }
Ejemplo n.º 18
0
        public void CopyrightShouldBeNullWhenEmptyOrWhitespaceStringGiven(string copyright)
        {
            Package packageToMapFrom = new Package { Copyright = copyright };

            PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(packageToMapFrom);

            Assert.IsNull(publishedPackage.Copyright, "Copyright should have been null.");
        }
Ejemplo n.º 19
0
        public void CategoriesShouldBeDirectlyMapped()
        {
            Package packageToMapFrom = new Package {Categories = "Foo, Bar"};

            PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(packageToMapFrom);

            Assert.AreEqual(packageToMapFrom.Categories, publishedPackage.Categories, "Categories were not mapped from Package to PublishedPackage correctly.");
        }
Ejemplo n.º 20
0
        public void AuthorsShouldBeNullWhenEmptyOrWhitespaceStringGiven(string authors)
        {
            Package packageToMapFrom = new Package { Authors = authors };

            PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(packageToMapFrom);

            Assert.IsNull(publishedPackage.Authors, "Authors should have been null.");
        }
Ejemplo n.º 21
0
        public void ShouldNotMapRatingAverage()
        {
            Package package = new Package { RatingAverage = 919 };

            Package mappedPackage = Mapper.Map<Package, Package>(package);

            Assert.AreNotEqual(package.RatingAverage, mappedPackage.RatingAverage, "RatingAverage should not have been mapped.");
        }
        public void ShouldReplaceCommasWithSpacesInTags() {
            const string tags = "one,two,three";
            const string expectedTags = "one two three";
            Package packageToMapTo = new Package();

            _packageViewModelMapper.MapViewModelToPackage(new PackageViewModel { Tags = tags }, packageToMapTo);

            Assert.AreEqual(expectedTags, packageToMapTo.Tags, "Tags were not formatted correctly.");
        }
        public void ShouldSetLastUpdatedToUtcNow() {
            DateTime expectedLastUpdatedDate = new DateTime(2003, 3, 3);
            _mockedClock.SetupGet(c => c.UtcNow).Returns(expectedLastUpdatedDate);
            Package packageToMapTo = new Package();

            _packageViewModelMapper.MapViewModelToPackage(new PackageViewModel(), packageToMapTo);

            Assert.AreEqual(expectedLastUpdatedDate, packageToMapTo.LastUpdated, "LastUpdated should be set to the current time UTC.");
        }
Ejemplo n.º 24
0
        public void ShouldCallUpdateOnPackageRepository()
        {
            var packageToUpdate = new Package();

            _packageUpdater.UpdateExistingPackage(packageToUpdate);

            _mockedPackageRepository.Verify(pr => pr.Update(packageToUpdate), Times.Once(),
                "PackageRepository's Update() should have been called exactly once with the expected Package.");
        }
Ejemplo n.º 25
0
        public void ShouldCallLatestVersionUpdater()
        {
            var packageToUpdate = new Package();

            _packageUpdater.UpdateExistingPackage(packageToUpdate);

            _mockedLatestVersionUpdater.Verify(pr => pr.SetLatestVersionFlagsOfOtherVersionablesWithSameId(packageToUpdate), Times.Once(),
                "Should have updated the LatestVersion information for Packages sharing the same ID.");
        }
        public void ShouldNotInvokeRepositoryWhenGivenPackageIsNotLatestVersion()
        {
            Package package = new Package {IsLatestVersion = false};

            _latestVersionUpdater.SetLatestVersionFlagsOfOtherVersionablesWithSameId(package);

            _mockedPackageRepository.VerifyGet(pr => pr.Collection, Times.Never(), "PackageRepository should not have been invoked.");
            _mockedPackageRepository.Verify(pr => pr.Update(It.IsAny<IEnumerable<Package>>()), Times.Never(), "No Update calls should have been made.");
        }
        public void CallsPackageRecommendedVersionSetter()
        {
            Package latestVersion = new Package();
            const bool shouldLogPackageAction = true;
            _mockedPackageLatestVersionGetter.Setup(plvg => plvg.GetLatestVersion(It.IsAny<string>())).Returns(latestVersion);

            _manager.SetLatestVersionAsRecommended("foo", shouldLogPackageAction);

            _mockedPackageRecommendedVersionSetter.Verify(prvs => prvs.SetAsRecommendedVersion(latestVersion, shouldLogPackageAction), Times.Once());
        }
Ejemplo n.º 28
0
 public void ValidatePackageUris(Package package)
 {
     if (package == null)
     {
         throw new ArgumentNullException("package");
     }
     ValidatePackageUri(package.ExternalPackageUrl, UriKind.Absolute);
     ValidatePackageUri(package.LicenseUrl, UriKind.Absolute);
     ValidatePackageUri(package.ProjectUrl, UriKind.Absolute);
     ValidatePackageUri(package.IconUrl, UriKind.RelativeOrAbsolute);
 }
Ejemplo n.º 29
0
 public void ValidateKeysMatchInstance(string packageId, string packageVersion, Package packageInstance)
 {
     if (packageId != packageInstance.Id)
     {
         throw new InvalidPackageIdException(packageInstance.Id);
     }
     if (packageVersion != packageInstance.Version)
     {
         throw new InvalidPackageVersionException(packageInstance.Version);
     }
 }
Ejemplo n.º 30
0
        public void ShouldCallLatestVersionUpdater()
        {
            const string packageId = "PackageId";
            Package createdPackage = new Package { Id = packageId };
            _mockedPackageFactory.Setup(pf => pf.CreateNewFromFile(It.IsAny<string>())).Returns(createdPackage);
            _mockedPackageIdValidator.Setup(piv => piv.IsValidPackageId(packageId)).Returns(true);

            _packageCreator.CreatePackage("key", Stream.Null, "fileExtension", false);

            _mockedLatestVersionUpdater.Verify(lvu => lvu.SetLatestVersionFlagsOfOtherVersionablesWithSameId(createdPackage), Times.Once(),
                "LatestVersionUpdater was not called.");
        }