当前位置: 首页>>代码示例>>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;未经允许,请勿转载。