當前位置: 首頁>>代碼示例>>C#>>正文


C# TestableApiController.VerifyPackageKey方法代碼示例

本文整理匯總了C#中NuGetGallery.TestableApiController.VerifyPackageKey方法的典型用法代碼示例。如果您正苦於以下問題:C# TestableApiController.VerifyPackageKey方法的具體用法?C# TestableApiController.VerifyPackageKey怎麽用?C# TestableApiController.VerifyPackageKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NuGetGallery.TestableApiController的用法示例。


在下文中一共展示了TestableApiController.VerifyPackageKey方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: VerifyPackageKeyReturns403IfUserIsNotAnOwner

            public void VerifyPackageKeyReturns403IfUserIsNotAnOwner()
            {
                // Arrange
                var controller = new TestableApiController();
                var owner = new User();
                var nonOwner = new User();
                controller.SetCurrentUser(nonOwner);
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(
                    new Package { PackageRegistration = new PackageRegistration() });

                // Act
                var result = controller.VerifyPackageKey("foo", "1.0.0");

                // Assert
                ResultAssert.IsStatusCode(
                    result,
                    HttpStatusCode.Forbidden, 
                    Strings.ApiKeyNotAuthorized);
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:19,代碼來源:ApiControllerFacts.cs

示例2: VerifyPackageKeyReturns200IfUserIsAnOwner

            public void VerifyPackageKeyReturns200IfUserIsAnOwner()
            {
                // Arrange
                var apiKey = Guid.NewGuid();
                var user = new User();
                var package = new Package { PackageRegistration = new PackageRegistration() };
                package.PackageRegistration.Owners.Add(user);
                var controller = new TestableApiController();
                controller.SetCurrentUser(user);
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(package);

                // Act
                var result = controller.VerifyPackageKey("foo", "1.0.0");

                // Assert
                ResultAssert.IsEmpty(result);
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:17,代碼來源:ApiControllerFacts.cs

示例3: VerifyPackageKeyReturns200IfUserHasCredentialRecordAndIsAnOwner

            public void VerifyPackageKeyReturns200IfUserHasCredentialRecordAndIsAnOwner()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var user = new User();
                var package = new Package { PackageRegistration = new PackageRegistration() };
                package.PackageRegistration.Owners.Add(user);
                var controller = new TestableApiController();
                controller.MockUserService
                    .Setup(s => s.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        guid.ToString().ToLowerInvariant()))
                    .Returns(new Credential() { User = user });
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).ReturnsNull();
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(package);

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                // Assert
                ResultAssert.IsEmpty(result);
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:22,代碼來源:ApiControllerFacts.cs

示例4: VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsButIdAndVersionAreEmpty

            public void VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsButIdAndVersionAreEmpty()
            {
                // Arrange
                var controller = new TestableApiController();
                controller.SetCurrentUser(new User());
                
                // Act
                var result = controller.VerifyPackageKey(null, null);

                // Assert
                ResultAssert.IsEmpty(result);
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:12,代碼來源:ApiControllerFacts.cs

示例5: VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsInCredentialsAndIdAndVersionAreEmpty

            public void VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsInCredentialsAndIdAndVersionAreEmpty()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService
                    .Setup(s => s.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        guid.ToString().ToLowerInvariant()))
                    .Returns(new Credential() { User = new User() });

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), null, null);

                // Assert
                ResultAssert.IsEmpty(result);
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:17,代碼來源:ApiControllerFacts.cs

示例6: VerifyPackageKeyReturns403IfUserInCredentialsTableIsNotAnOwner

            public void VerifyPackageKeyReturns403IfUserInCredentialsTableIsNotAnOwner()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                var owner = new User();
                var nonOwner = new User();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns(owner);
                controller.MockUserService
                    .Setup(s => s.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        guid.ToString().ToLowerInvariant()))
                    .Returns(new Credential() { User = nonOwner });
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(
                    new Package { PackageRegistration = new PackageRegistration() });

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                // Assert
                ResultAssert.IsStatusCode(
                    result,
                    HttpStatusCode.Forbidden, 
                    "The specified API key does not provide the authority to push packages.");
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:25,代碼來源:ApiControllerFacts.cs

示例7: VerifyPackageKeyReturns200IfUserIsAnOwner

            public void VerifyPackageKeyReturns200IfUserIsAnOwner()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var user = new User { EmailAddress = "[email protected]" };
                var package = new Package { PackageRegistration = new PackageRegistration() };
                package.PackageRegistration.Owners.Add(user);
                var controller = new TestableApiController();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns(user);
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(package);

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");
                ResultAssert.IsStatusCode(result, 200);
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:15,代碼來源:ApiControllerFacts.cs

示例8: VerifyPackageKeyReturns403IfUserDoesNotExistByFindByApiKeyOrAuthorizeCredential

            public void VerifyPackageKeyReturns403IfUserDoesNotExistByFindByApiKeyOrAuthorizeCredential()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns<User>(null);
                controller.MockUserService
                    .Setup(s => s.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        guid.ToString().ToLowerInvariant()))
                    .ReturnsNull();
                controller.MockPackageService
                    .Setup(p => p.FindPackageByIdAndVersion("foo", "1.0.0", true))
                    .Returns(new Package());

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                // Assert
                ResultAssert.IsStatusCode(
                    result,
                    HttpStatusCode.Forbidden, 
                    "The specified API key does not provide the authority to push packages.");
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:24,代碼來源:ApiControllerFacts.cs

示例9: VerifyPackageKeyReturns403IfUserIsNotAnOwner

            public void VerifyPackageKeyReturns403IfUserIsNotAnOwner()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                var user = new User { EmailAddress = "[email protected]" };
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns(user);
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(
                    new Package { PackageRegistration = new PackageRegistration() });

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                ResultAssert.IsStatusCode(result, 403, "The specified API key does not provide the authority to push packages.");
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:15,代碼來源:ApiControllerFacts.cs

示例10: VerifyPackageKeyReturns404IfPackageDoesNotExist

            public void VerifyPackageKeyReturns404IfPackageDoesNotExist()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns(new User());
                controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns<Package>(null);

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                // Assert
                AssertStatusCodeResult(result, 404, "A package with id 'foo' and version '1.0.0' does not exist.");
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:14,代碼來源:ApiControllerFacts.cs

示例11: VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsAndIdAndVersionAreEmpty

            public void VerifyPackageKeyReturnsEmptyResultIfApiKeyExistsAndIdAndVersionAreEmpty()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns(new User());

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), null, null);

                // Assert
                Assert.IsType<EmptyResult>(result);
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:13,代碼來源:ApiControllerFacts.cs

示例12: VerifyPackageKeyReturns403IfUserDoesNotExist

            public void VerifyPackageKeyReturns403IfUserDoesNotExist()
            {
                // Arrange
                var guid = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService.Setup(s => s.FindByApiKey(guid)).Returns<User>(null);

                // Act
                var result = controller.VerifyPackageKey(guid.ToString(), "foo", "1.0.0");

                // Assert
                AssertStatusCodeResult(result, 403, "The specified API key does not provide the authority to push packages.");
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:13,代碼來源:ApiControllerFacts.cs

示例13: VerifyPackageKeyReturns403IfApiKeyIsInvalidGuid

            public void VerifyPackageKeyReturns403IfApiKeyIsInvalidGuid()
            {
                // Arrange
                var controller = new TestableApiController();
                
                // Act
                var result = controller.VerifyPackageKey("bad-guid", "foo", "1.0.0");

                // Assert
                AssertStatusCodeResult(result, 400, "The API key 'bad-guid' is invalid.");
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:11,代碼來源:ApiControllerFacts.cs


注:本文中的NuGetGallery.TestableApiController.VerifyPackageKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。