public void ResolvePathIsCorrect(string action, Func <UrlHelper, IPackageVersionModel, string> caller)
            {
                // Arrange
                var packageId = "TestPackageId";
                var package   = new Package
                {
                    PackageRegistration = new PackageRegistration
                    {
                        Id = packageId
                    },
                    Version = "1.0.0"
                };

                var urlHelper = TestUtility.MockUrlHelper();

                var idModel      = new TrivialPackageVersionModel(packageId, version: null);
                var versionModel = new ListPackageItemViewModel(package, currentUser: null);

                // Act
                var idResult      = urlHelper.PackageVersionAction(action, idModel);
                var versionResult = urlHelper.PackageVersionAction(action, versionModel);

                // Assert
                // Id
                Assert.Equal("/packages/" + packageId + "/" + action, idResult);
                Assert.Equal(urlHelper.PackageVersionAction(action, packageId, version: null), idResult);
                Assert.Equal(caller(urlHelper, idModel), idResult);

                // Id and version
                Assert.Equal("/packages/" + packageId + "/" + package.Version + "/" + action, versionResult);
                Assert.Equal(urlHelper.PackageVersionAction(action, packageId, package.Version), versionResult);
                Assert.Equal(urlHelper.PackageVersionActionTemplate(action).Resolve(versionModel), versionResult);
                Assert.Equal(caller(urlHelper, versionModel), versionResult);
            }
Beispiel #2
0
        private ListPackageItemViewModel SetupInternal(ListPackageItemViewModel viewModel, Package package, User currentUser)
        {
            viewModel.Tags = package.Tags?
                             .Split(' ')
                             .Where(t => !string.IsNullOrEmpty(t))
                             .Select(t => t.Trim())
                             .ToArray();

            viewModel.Authors          = package.FlattenedAuthors;
            viewModel.MinClientVersion = package.MinClientVersion;
            viewModel.Owners           = package.PackageRegistration?.Owners?.Select(GetBasicUserViewModel).ToList();
            viewModel.IsVerified       = package.PackageRegistration?.IsVerified;

            viewModel.CanDisplayPrivateMetadata = CanPerformAction(currentUser, package, ActionsRequiringPermissions.DisplayPrivatePackageMetadata);
            viewModel.CanEdit                     = CanPerformAction(currentUser, package, ActionsRequiringPermissions.EditPackage);
            viewModel.CanUnlistOrRelist           = CanPerformAction(currentUser, package, ActionsRequiringPermissions.UnlistOrRelistPackage);
            viewModel.CanManageOwners             = CanPerformAction(currentUser, package, ActionsRequiringPermissions.ManagePackageOwnership);
            viewModel.CanReportAsOwner            = CanPerformAction(currentUser, package, ActionsRequiringPermissions.ReportPackageAsOwner);
            viewModel.CanSeeBreadcrumbWithProfile = CanPerformAction(currentUser, package, ActionsRequiringPermissions.ShowProfileBreadcrumb);
            viewModel.CanDeleteSymbolsPackage     = CanPerformAction(currentUser, package, ActionsRequiringPermissions.DeleteSymbolPackage);
            viewModel.CanDeprecate                = CanPerformAction(currentUser, package, ActionsRequiringPermissions.DeprecatePackage);

            viewModel.SetShortDescriptionFrom(viewModel.Description);

            if (package.Certificate != null)
            {
                var owners          = package.PackageRegistration?.Owners ?? Enumerable.Empty <User>();
                var signerUsernames = owners.Where(owner => owner.UserCertificates.Any(uc => uc.CertificateKey == package.CertificateKey)).Select(owner => owner.Username).ToList();
                viewModel.UpdateSignatureInformation(signerUsernames, package.Certificate.Sha1Thumbprint);
            }

            return(viewModel);
        }
Beispiel #3
0
        public OwnerRequestsListItemViewModel(PackageOwnerRequest request, IPackageService packageService, User currentUser)
        {
            Request = request;

            var package = packageService.FindPackageByIdAndVersion(request.PackageRegistration.Id, version: null, semVerLevelKey: SemVerLevelKey.SemVer2, allowPrerelease: true);

            Package = new ListPackageItemViewModel(package, currentUser);

            CanAccept = ActionsRequiringPermissions.HandlePackageOwnershipRequest.CheckPermissions(currentUser, Request.NewOwner) == PermissionsCheckResult.Allowed;
            CanCancel = Package.CanManageOwners;
        }
            public void ResolvePathIsCorrect()
            {
                // Arrange
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration
                    {
                        Id = "TestPackageId"
                    },
                    Version = "1.0.0"
                };

                var urlHelper = TestUtility.MockUrlHelper();
                var packageVM = new ListPackageItemViewModel(package, currentUser: null);

                // Act
                var result = urlHelper.ManagePackageOwnersTemplate().Resolve(packageVM);

                // Assert
                Assert.Equal(urlHelper.ManagePackageOwners(packageVM), result);
            }
            public void ResolvePathIsCorrect()
            {
                // Arrange
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration
                    {
                        Id = "TestPackageId"
                    },
                    Version = "1.0.0"
                };

                var urlHelper = TestUtility.MockUrlHelper();
                var packageVM = new ListPackageItemViewModel(package);

                // Act
                var result = urlHelper.EditPackageTemplate().Resolve(packageVM);

                // Assert
                Assert.Equal(urlHelper.EditPackage(packageVM.Id, packageVM.Version), result);
            }
Beispiel #6
0
 public PackageHeadingModel(ListPackageItemViewModel packageViewModel, string pageHeading, bool linkIdOnly = false)
     : this(packageViewModel.Id, packageViewModel.Version, pageHeading, linkIdOnly)
 {
     ShowProfileBreadcrumb = packageViewModel.CanSeeBreadcrumbWithProfile;
 }
Beispiel #7
0
 public ListPackageItemViewModel Setup(ListPackageItemViewModel viewModel, Package package, User currentUser)
 {
     _packageViewModelFactory.Setup(viewModel, package);
     return(SetupInternal(viewModel, package, currentUser));
 }
Beispiel #8
0
        public ListPackageItemViewModel Create(Package package, User currentUser)
        {
            var viewModel = new ListPackageItemViewModel();

            return(Setup(viewModel, package, currentUser));
        }
 public DeletePackageViewModel(Package package, IEnumerable<Package> dependentPackages)
 {
     Package = new ListPackageItemViewModel(package);
     DependentPackages = dependentPackages.Select(p => new PackageViewModel(p));
     MayDelete = (!DependentPackages.Any() && package.DownloadCount < 5);
 }
Beispiel #10
0
 private static bool IsCakeRecipe(ListPackageItemViewModel model) =>
 model.Tags?.Contains("cake-recipe", StringComparer.OrdinalIgnoreCase) ?? false;