public static async Task<IQueryable<Package>> SearchCore(
            ISearchService searchService,
            HttpRequestBase request,
            IQueryable<Package> packages, 
            string searchTerm, 
            string targetFramework, 
            bool includePrerelease,
            CuratedFeed curatedFeed)
        {
            SearchFilter searchFilter;
            // We can only use Lucene if:
            //  a) We are looking for the latest version of a package OR the Index contains all versions of each package
            //  b) The sort order is something Lucene can handle
            if (TryReadSearchFilter(searchService.ContainsAllVersions, request.RawUrl, out searchFilter))
            {
                searchFilter.SearchTerm = searchTerm;
                searchFilter.IncludePrerelease = includePrerelease;
                searchFilter.CuratedFeed = curatedFeed;
                searchFilter.SupportedFramework = targetFramework;

                var results = await GetResultsFromSearchService(searchService, searchFilter);

                return results;
            }

            if (!includePrerelease)
            {
                packages = packages.Where(p => !p.IsPrerelease);
            }

            return packages.Search(searchTerm);
        }
示例#2
0
        public static async Task <IQueryable <Package> > FindByIdCore(
            ISearchService searchService,
            HttpRequestBase request,
            IQueryable <Package> packages,
            string id,
            CuratedFeed curatedFeed)
        {
            SearchFilter searchFilter;

            // We can only use Lucene if:
            //  a) We are looking for the latest version of a package OR the Index contains all versions of each package
            //  b) The sort order is something Lucene can handle
            if (TryReadSearchFilter(searchService.ContainsAllVersions, request.RawUrl, out searchFilter))
            {
                searchFilter.SearchTerm         = string.Format(CultureInfo.CurrentCulture, "Id:\"{0}\"", id);
                searchFilter.IncludePrerelease  = true;
                searchFilter.CuratedFeed        = curatedFeed;
                searchFilter.SupportedFramework = null;
                searchFilter.IncludeAllVersions = true;

                var results = await GetResultsFromSearchService(searchService, searchFilter).ConfigureAwait(false);

                return(results);
            }

            return(packages);
        }
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed,
            Package galleryPackage,
            INupkg nugetPackage)
        {
            return
                // Must have min client version of null or <= 2.2
                ((nugetPackage.Metadata.MinClientVersion == null || nugetPackage.Metadata.MinClientVersion <= new Version(2, 2)) &&

                 // Must be latest stable
                 galleryPackage.IsLatestStable &&

                 // Must support net40
                 SupportsNet40(galleryPackage) &&

                 // Dependencies on the gallery must be curated
                 DependenciesAreCurated(galleryPackage, curatedFeed) &&

                 (
                     // Must have AspNetWebPages tag
                     ContainsAspNetWebPagesTag(galleryPackage) ||

                     // OR: Must not contain powershell or T4
                     DoesNotContainUnsupportedFiles(nugetPackage)
                 ));
        }
示例#4
0
        public override void Curate(Package galleryPackage, INupkg nugetPackage, bool commitChanges)
        {
            // Make sure the target feed exists
            CuratedFeed feed = GetService <ICuratedFeedService>().GetFeedByName(CuratedFeedName, includePackages: true);

            if (feed != null && galleryPackage.Tags != null)
            {
                // Break the tags up so we can be sure we don't catch any partial matches (i.e. "foobar" when we're looking for "foo")
                string[] tags = galleryPackage.Tags.Split();

                // Check if this package should be curated
                if (tags.Any(tag => RequiredTags.Contains(tag, StringComparer.OrdinalIgnoreCase)))
                {
                    // It should!
                    // But now we need to ensure that the package's dependencies are also curated
                    if (DependenciesAreCurated(galleryPackage, feed))
                    {
                        GetService <ICuratedFeedService>().CreatedCuratedPackage(
                            feed,
                            galleryPackage.PackageRegistration,
                            automaticallyCurated: true,
                            commitChanges: commitChanges);
                    }
                }
            }
        }
        public CuratedPackage Execute(
            CuratedFeed curatedFeed, 
            PackageRegistration packageRegistration, 
            bool included = false, 
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = new CuratedPackage
            {
                PackageRegistrationKey = packageRegistration.Key,
                Included = included,
                AutomaticallyCurated = automaticallyCurated,
                Notes = notes,
            };

            curatedFeed.Packages.Add(curatedPackage);

            if (commitChanges)
            {
                Entities.SaveChanges();
            }

            return curatedPackage;
        }
示例#6
0
        public CuratedPackage Execute(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = new CuratedPackage
            {
                PackageRegistrationKey = packageRegistration.Key,
                Included             = included,
                AutomaticallyCurated = automaticallyCurated,
                Notes = notes,
            };

            curatedFeed.Packages.Add(curatedPackage);

            if (commitChanges)
            {
                Entities.SaveChanges();
            }

            return(curatedPackage);
        }
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed, 
            Package galleryPackage,
            INupkg nugetPackage)
        {
            if (!galleryPackage.IsLatestStable)
            {
                return false;
            }

            bool shouldBeIncluded = galleryPackage.Tags != null && 
                galleryPackage.Tags.ToLowerInvariant().Contains("aspnetwebpages");

            if (!shouldBeIncluded)
            {
                shouldBeIncluded = true;
                foreach (var filePath in nugetPackage.GetFiles())
                {
                    var fi = new FileInfo(filePath);
                    if (fi.Extension == ".ps1" || fi.Extension == ".t4")
                    {
                        return false;
                    }
                }
            }

            if (!shouldBeIncluded)
            {
                return false;
            }

            return DependenciesAreCurated(galleryPackage, curatedFeed);
        }
示例#8
0
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { new User {
                                                                                           Username = "******"
                                                                                       } })
                };
                StubIdentity            = new Mock <IIdentity>();
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);
            }
示例#9
0
        public static async Task <IQueryable <Package> > SearchCore(
            ISearchService searchService,
            HttpRequestBase request,
            IQueryable <Package> packages,
            string searchTerm,
            string targetFramework,
            bool includePrerelease,
            CuratedFeed curatedFeed)
        {
            SearchFilter searchFilter;

            // We can only use Lucene if:
            //  a) We are looking for the latest version of a package OR the Index contains all versions of each package
            //  b) The sort order is something Lucene can handle
            if (TryReadSearchFilter(searchService.ContainsAllVersions, request.RawUrl, out searchFilter))
            {
                searchFilter.SearchTerm         = searchTerm;
                searchFilter.IncludePrerelease  = includePrerelease;
                searchFilter.CuratedFeed        = curatedFeed;
                searchFilter.SupportedFramework = targetFramework;

                var results = await GetResultsFromSearchService(searchService, searchFilter).ConfigureAwait(false);

                return(results);
            }

            if (!includePrerelease)
            {
                packages = packages.Where(p => !p.IsPrerelease);
            }

            return(packages.Search(searchTerm));
        }
示例#10
0
            public TestableCuratedFeedsController()
            {
                Fakes = new Fakes();

                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubCuratedFeedService = new Mock <ICuratedFeedService>();

                SetOwinContextOverride(Fakes.CreateOwinContext());

                StubCuratedFeedService
                .Setup(stub => stub.GetFeedByName(It.IsAny <string>(), It.IsAny <bool>()))
                .Returns(StubCuratedFeed);

                CuratedFeedService = StubCuratedFeedService.Object;

                StubSearchService = new Mock <ISearchService>();
                SearchService     = StubSearchService.Object;

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);

                this.SetCurrentUser(Fakes.User);
            }
            public TestableCuratedPackagesController()
            {
                Fakes = new Fakes();

                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };

                SetOwinContextOverride(Fakes.CreateOwinContext());

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed, 
            Package galleryPackage,
            INupkg nugetPackage)
        {
            return 
                // Must have min client version of null or <= 2.2
                (nugetPackage.Metadata.MinClientVersion == null || nugetPackage.Metadata.MinClientVersion <= new Version(2, 2)) &&

                // Must be latest stable
                galleryPackage.IsLatestStable &&

                // Must support net40
                SupportsNet40(galleryPackage) &&

                // Dependencies on the gallery must be curated
                DependenciesAreCurated(galleryPackage, curatedFeed) &&

                (
                    // Must have AspNetWebPages tag
                    ContainsAspNetWebPagesTag(galleryPackage) ||

                    // OR: Must not contain powershell or T4
                    DoesNotContainUnsupportedFiles(nugetPackage)
                );
        }
            protected Facts()
            {
                _package     = new Package();
                _curatedFeed = new CuratedFeed
                {
                    Name     = "curated-feed",
                    Packages = new[]
                    {
                        new CuratedPackage
                        {
                            PackageRegistration = new PackageRegistration
                            {
                                Packages = new[]
                                {
                                    _package,
                                },
                            },
                        },
                    },
                };

                _entityRepository = new Mock <IEntityRepository <CuratedFeed> >();
                _config           = new Mock <IAppConfiguration>();

                _entityRepository
                .Setup(x => x.GetAll())
                .Returns(() => new[] { _curatedFeed }.AsQueryable());

                _target = new CuratedFeedService(
                    _entityRepository.Object,
                    _config.Object);
            }
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed,
            Package galleryPackage,
            PackageArchiveReader packageArchiveReader)
        {
            var nuspec = packageArchiveReader.GetNuspecReader();

            return
                // Must have min client version of null or <= 2.2
                (nuspec.GetMinClientVersion() == null || nuspec.GetMinClientVersion() <= new NuGetVersion(2, 2, 0)) &&

                // Must be latest stable
                galleryPackage.IsLatestStable &&

                // Must support net40
                SupportsNet40(galleryPackage) &&

                (
                    // Must have AspNetWebPages tag
                    ContainsAspNetWebPagesTag(galleryPackage) ||

                    // OR: Must not contain powershell or T4
                    DoesNotContainUnsupportedFiles(packageArchiveReader)
                ) &&

                // Dependencies on the gallery must be curated
                DependenciesAreCurated(galleryPackage, curatedFeed);
        }
            public TestableCuratedPackagesController()
            {
                Fakes = new Fakes();

                StubCuratedFeed = new CuratedFeed
                    { Key = 0, Name = "aFeedName", Managers = new HashSet<User>(new[] { Fakes.User }) };
                StubPackageRegistration = new PackageRegistration { Key = 0, Id = "anId" };

                OwinContext = Fakes.CreateOwinContext();

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository<CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository<CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock<HttpContextBase>();
                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
示例#16
0
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed,
            Package galleryPackage,
            INupkg nugetPackage)
        {
            if (!galleryPackage.IsLatestStable)
            {
                return(false);
            }

            bool shouldBeIncluded = galleryPackage.Tags != null &&
                                    galleryPackage.Tags.ToLowerInvariant().Contains("aspnetwebpages");

            if (!shouldBeIncluded)
            {
                shouldBeIncluded = true;
                foreach (var filePath in nugetPackage.GetFiles())
                {
                    var fi = new FileInfo(filePath);
                    if (fi.Extension == ".ps1" || fi.Extension == ".t4")
                    {
                        return(false);
                    }
                }
            }

            if (!shouldBeIncluded)
            {
                return(false);
            }

            return(DependenciesAreCurated(galleryPackage, curatedFeed));
        }
示例#17
0
        public static async Task<IQueryable<Package>> SearchCore(
            ISearchService searchService,
            HttpRequestBase request,
            IQueryable<Package> packages, 
            string searchTerm, 
            string targetFramework, 
            bool includePrerelease,
            CuratedFeed curatedFeed)
        {
            SearchFilter searchFilter;
            // We can only use Lucene if the client queries for the latest versions (IsLatest \ IsLatestStable) versions of a package
            // and specific sort orders that we have in the index.
            if (TryReadSearchFilter(request.RawUrl, out searchFilter))
            {
                searchFilter.SearchTerm = searchTerm;
                searchFilter.IncludePrerelease = includePrerelease;
                searchFilter.CuratedFeed = curatedFeed;

                Trace.WriteLine("TODO: use target framework parameter - see #856" + targetFramework);

                var results = await GetResultsFromSearchService(searchService, searchFilter);

                return results;
            }

            if (!includePrerelease)
            {
                packages = packages.Where(p => !p.IsPrerelease);
            }

            return packages.Search(searchTerm);
        }
        internal static bool ShouldCuratePackage(
            CuratedFeed curatedFeed,
            Package galleryPackage,
            PackageArchiveReader packageArchiveReader)
        {
            var nuspec = packageArchiveReader.GetNuspecReader();

            return
                // Must have min client version of null or <= 2.2
                ((nuspec.GetMinClientVersion() == null || nuspec.GetMinClientVersion() <= new NuGetVersion(2, 2, 0)) &&

                 // Must be latest stable
                 galleryPackage.IsLatestStable &&

                 // Must support net40
                 SupportsNet40(galleryPackage) &&

                 (
                     // Must have AspNetWebPages tag
                     ContainsAspNetWebPagesTag(galleryPackage) ||

                     // OR: Must not contain powershell or T4
                     DoesNotContainUnsupportedFiles(packageArchiveReader)
                 ) &&

                 // Dependencies on the gallery must be curated
                 DependenciesAreCurated(galleryPackage, curatedFeed));
        }
 public TestableCreateCuratedPackageCommand()
     : base(null)
 {
     StubCuratedFeed = new CuratedFeed { Key = 0, Name = "aName", };
     StubEntitiesContext = new Mock<IEntitiesContext>();
     StubPackageRegistration = new PackageRegistration { Key = 0, };
     Entities = StubEntitiesContext.Object;
 }
示例#20
0
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };
                StubPackage = new Package
                {
                    Key = 34,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "1.0.0"
                };
                StubLatestPackage = new Package
                {
                    Key = 42,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version      = "2.0.1-alpha",
                    IsLatest     = true,
                    IsPrerelease = true
                };
                StubLatestStablePackage = new Package
                {
                    Key = 41,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version        = "2.0.0",
                    IsLatestStable = true
                };

                OwinContext = Fakes.CreateOwinContext();

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                StubPackageRegistration.Packages.Add(StubPackage);
                StubPackageRegistration.Packages.Add(StubLatestPackage);
                StubPackageRegistration.Packages.Add(StubLatestStablePackage);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                    { Key = 0, Name = "aFeedName", Managers = new HashSet<User>(new[] { Fakes.User }) };
                StubPackageRegistration = new PackageRegistration { Key = 0, Id = "anId" };
                StubPackage = new Package
                {
                    Key = 34,
                    PackageRegistration = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "1.0.0"
                };
                StubLatestPackage = new Package
                {
                    Key = 42,
                    PackageRegistration = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "2.0.1-alpha",
                    IsLatest = true,
                    IsPrerelease = true
                };
                StubLatestStablePackage = new Package
                {
                    Key = 41,
                    PackageRegistration = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "2.0.0",
                    IsLatestStable = true
                };

                OwinContext = Fakes.CreateOwinContext();

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                StubPackageRegistration.Packages.Add(StubPackage);
                StubPackageRegistration.Packages.Add(StubLatestPackage);
                StubPackageRegistration.Packages.Add(StubLatestStablePackage);

                var curatedFeedRepository = new EntityRepository<CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository<CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock<HttpContextBase>();
                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
        protected static bool DependenciesAreCurated(Package galleryPackage, CuratedFeed curatedFeed)
        {
            if (!galleryPackage.Dependencies.AnySafe())
            {
                return true;
            }

            return galleryPackage.Dependencies.All(
                d => curatedFeed.Packages
                    .Where(p => p.Included)
                    .Any(p => p.PackageRegistration.Id.Equals(d.Id, StringComparison.OrdinalIgnoreCase)));
        }
示例#23
0
        protected static bool DependenciesAreCurated(Package galleryPackage, CuratedFeed curatedFeed)
        {
            if (galleryPackage.Dependencies.IsEmpty())
            {
                return(true);
            }

            return(galleryPackage.Dependencies.All(
                       d => curatedFeed.Packages
                       .Where(p => p.Included)
                       .Any(p => p.PackageRegistration.Id.Equals(d.Id, StringComparison.OrdinalIgnoreCase))));
        }
示例#24
0
 public TestableCreateCuratedPackageCommand()
     : base(null)
 {
     StubCuratedFeed = new CuratedFeed {
         Key = 0, Name = "aName",
     };
     StubEntitiesContext     = new Mock <IEntitiesContext>();
     StubPackageRegistration = new PackageRegistration {
         Key = 0,
     };
     Entities = StubEntitiesContext.Object;
 }
            public TestableCuratedFeedsController()
            {
                StubCuratedFeed = new CuratedFeed {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new [] { new User {
                                                                                        Username = "******"
                                                                                    } })
                };
                StubCuratedFeedByNameQry = new Mock <ICuratedFeedByNameQuery>();
                StubIdentity             = new Mock <IIdentity>();

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");
                StubCuratedFeedByNameQry
                .Setup(stub => stub.Execute(It.IsAny <string>(), It.IsAny <bool>()))
                .Returns(StubCuratedFeed);
            }
示例#26
0
        public override void Curate(Package galleryPackage, IPackage nugetPackage)
        {
            // Make sure the target feed exists
            CuratedFeed feed = GetService <ICuratedFeedByNameQuery>().Execute(CuratedFeedName, includePackages: false);

            if (feed != null && galleryPackage.Tags != null)
            {
                // Break the tags up so we can be sure we don't catch any partial matches (i.e. "foobar" when we're looking for "foo")
                string[] tags = galleryPackage.Tags.Split();

                // Check if this package should be curated
                if (tags.Any(tag => RequiredTags.Contains(tag, StringComparer.OrdinalIgnoreCase)))
                {
                    // It should! Add it to the curated feed
                    GetService <ICreateCuratedPackageCommand>().Execute(
                        feed.Key, galleryPackage.PackageRegistration.Key, automaticallyCurated: true);
                }
            }
        }
            protected TestableCuratedPackagesControllerBase()
            {
                StubCreatedCuratedPackageCmd = new Mock <ICreateCuratedPackageCommand>();
                StubCuratedFeed = new CuratedFeed {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new [] { new User {
                                                                                        Username = "******"
                                                                                    } })
                };
                StubCuratedFeedByNameQry    = new Mock <ICuratedFeedByNameQuery>();
                StubDeleteCuratedPackageCmd = new Mock <IDeleteCuratedPackageCommand>();
                StubIdentity = new Mock <IIdentity>();
                StubModifyCuratedPackageCmd = new Mock <IModifyCuratedPackageCommand>();
                StubPackageRegistration     = new PackageRegistration {
                    Key = 0, Id = "anId"
                };
                StubPackageRegistrationByIdQry = new Mock <IPackageRegistrationByIdQuery>();

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");
            }
            protected TestableCuratedPackagesControllerBase()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new[] { new User {
                                                                                       Username = "******"
                                                                                   } })
                };
                StubCuratedFeedService  = new Mock <ICuratedFeedService>();
                StubIdentity            = new Mock <IIdentity>();
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };
                StubPackageRegistrationByIdQry = new Mock <IPackageRegistrationByIdQuery>();

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");

                base.CuratedFeedService = StubCuratedFeedService.Object;
            }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included = false,
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException("packageRegistration");
            }

            var curatedPackage = curatedFeed.Packages
                .SingleOrDefault(cp => cp.PackageRegistrationKey == packageRegistration.Key);

            if (curatedPackage == null)
            {
                curatedPackage = new CuratedPackage
                {
                    PackageRegistration = packageRegistration,
                    Included = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackage);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return curatedPackage;
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            PackageRegistration packageRegistration,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException(nameof(curatedFeed));
            }

            if (packageRegistration == null)
            {
                throw new ArgumentNullException(nameof(packageRegistration));
            }

            var curatedPackage = curatedFeed.Packages
                                 .SingleOrDefault(cp => cp.PackageRegistrationKey == packageRegistration.Key);

            if (curatedPackage == null)
            {
                curatedPackage = new CuratedPackage
                {
                    PackageRegistration  = packageRegistration,
                    Included             = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackage);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return(curatedPackage);
        }
示例#31
0
            public TestableCreateCuratedPackageCommand()
                : base(null)
            {
                StubCuratedFeed = new CuratedFeed {
                    Key = 0, Name = "aName",
                };
                StubCuratedFeedByKeyQry = new Mock <ICuratedFeedByKeyQuery>();
                StubEntitiesContext     = new Mock <IEntitiesContext>();
                StubPackageRegistration = new PackageRegistration {
                    Key = 0,
                };
                StubPackageRegistrationByKeyQry = new Mock <IPackageRegistrationByKeyQuery>();

                StubCuratedFeedByKeyQry
                .Setup(stub => stub.Execute(It.IsAny <int>(), It.IsAny <bool>()))
                .Returns(StubCuratedFeed);
                StubPackageRegistrationByKeyQry
                .Setup(stub => stub.Execute(It.IsAny <int>(), It.IsAny <bool>()))
                .Returns(StubPackageRegistration);

                Entities = StubEntitiesContext.Object;
            }
示例#32
0
            public TestableCuratedFeedsController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new[] { new User {
                                                                                       Username = "******"
                                                                                   } })
                };
                StubCuratedFeedService = new Mock <ICuratedFeedService>();
                StubIdentity           = new Mock <IIdentity>();

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");
                StubCuratedFeedService
                .Setup(stub => stub.GetFeedByName(It.IsAny <string>(), It.IsAny <bool>()))
                .Returns(StubCuratedFeed);

                CuratedFeedService = StubCuratedFeedService.Object;

                StubSearchService = new Mock <ISearchService>();
                SearchService     = StubSearchService.Object;
            }
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                    { Key = 0, Name = "aFeedName", Managers = new HashSet<User>(new[] { new User { Username = "******" } }) };
                StubIdentity = new Mock<IIdentity>();
                StubPackageRegistration = new PackageRegistration { Key = 0, Id = "anId" };

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository<CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository<CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);
            }
示例#34
0
 protected static bool DependenciesAreCurated(Package galleryPackage, CuratedFeed curatedFeed)
 {
     return(DependenciesAreCurated(galleryPackage.Dependencies, curatedFeed));
 }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            Package package,
            bool included             = false,
            bool automaticallyCurated = false,
            string notes       = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var curatedPackageRegistration = curatedFeed.Packages
                                             .SingleOrDefault(cp => cp.PackageRegistrationKey == package.PackageRegistration.Key);

            var isFirstPackageInRegistration = false;

            if (curatedPackageRegistration == null)
            {
                curatedPackageRegistration = new CuratedPackage
                {
                    PackageRegistration    = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Included             = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackageRegistration);
                isFirstPackageInRegistration = true;
            }

            if (!curatedPackageRegistration.CuratedPackageVersions.Any(p => p.PackageKey == package.Key))
            {
                var curatedPackageVersion = new CuratedPackageVersion
                {
                    CuratedFeed            = curatedFeed,
                    CuratedFeedKey         = curatedFeed.Key,
                    PackageRegistration    = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Package    = package,
                    PackageKey = package.Key,
                };

                // Make sure we set IsLatest + IsLatestStable for the first package, because
                // UpdateIsLatest won't be able to see this registration if we don't commit.
                // If it's the first package in the registration, then it's definitely the
                // latest. It's the latest stable package only if it's not a pre-release.
                if (isFirstPackageInRegistration)
                {
                    curatedPackageVersion.IsLatest       = true;
                    curatedPackageVersion.IsLatestStable = !package.IsPrerelease;
                }

                curatedPackageRegistration.CuratedPackageVersions.Add(curatedPackageVersion);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return(curatedPackageRegistration);
        }
        public CuratedPackage CreatedCuratedPackage(
            CuratedFeed curatedFeed,
            Package package,
            bool included = false,
            bool automaticallyCurated = false,
            string notes = null,
            bool commitChanges = true)
        {
            if (curatedFeed == null)
            {
                throw new ArgumentNullException("curatedFeed");
            }

            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var curatedPackageRegistration = curatedFeed.Packages
                .SingleOrDefault(cp => cp.PackageRegistrationKey == package.PackageRegistration.Key);

            var isFirstPackageInRegistration = false;
            if (curatedPackageRegistration == null)
            {
                curatedPackageRegistration = new CuratedPackage
                {
                    PackageRegistration = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Included = included,
                    AutomaticallyCurated = automaticallyCurated,
                    Notes = notes,
                };

                curatedFeed.Packages.Add(curatedPackageRegistration);
                isFirstPackageInRegistration = true;
            }

            if (!curatedPackageRegistration.CuratedPackageVersions.Any(p => p.PackageKey == package.Key))
            {
                var curatedPackageVersion = new CuratedPackageVersion
                {
                    CuratedFeed = curatedFeed,
                    CuratedFeedKey = curatedFeed.Key,
                    PackageRegistration = package.PackageRegistration,
                    PackageRegistrationKey = package.PackageRegistrationKey,
                    Package = package,
                    PackageKey = package.Key,
                };

                // Make sure we set IsLatest + IsLatestStable for the first package, because
                // UpdateIsLatest won't be able to see this registration if we don't commit.
                // If it's the first package in the registration, then it's definitely the
                // latest. It's the latest stable package only if it's not a pre-release.
                if (isFirstPackageInRegistration)
                {
                    curatedPackageVersion.IsLatest = true;
                    curatedPackageVersion.IsLatestStable = !package.IsPrerelease;
                }

                curatedPackageRegistration.CuratedPackageVersions.Add(curatedPackageVersion);
            }

            if (commitChanges)
            {
                CuratedFeedRepository.CommitChanges();
            }

            return curatedPackageRegistration;
        }