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


C# TestableApiController.DeletePackage方法代碼示例

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


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

示例1: WillUnlistThePackageIfApiKeyBelongsToAnOwner

            public void WillUnlistThePackageIfApiKeyBelongsToAnOwner()
            {
                var owner = new User { Key = 1 };
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
                    };
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.SetCurrentUser(owner);
                
                ResultAssert.IsEmpty(controller.DeletePackage("theId", "1.0.42"));

                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true));
                controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:16,代碼來源:ApiControllerFacts.cs

示例2: WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist

            public void WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist()
            {
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns((Package)null);
                controller.SetCurrentUser(new User());
                
                var result = controller.DeletePackage("theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(404, statusCodeResult.StatusCode);
                Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"), statusCodeResult.StatusDescription);
                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(It.IsAny<Package>(), true), Times.Never());
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:14,代碼來源:ApiControllerFacts.cs

示例3: WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner

            public void WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner()
            {
                var notOwner = new User { Key = 1 };
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Owners = new[] { new User() } }
                    };
                var apiKey = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.SetCurrentUser(notOwner);
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns(package);
                
                var result = controller.DeletePackage("theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(String.Format(Strings.ApiKeyNotAuthorized, "delete"), statusCodeResult.StatusDescription);
                
                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true), Times.Never());
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:20,代碼來源:ApiControllerFacts.cs

示例4: WillUseUserFromAuthenticateCredentialOverFindByApiKey

            public void WillUseUserFromAuthenticateCredentialOverFindByApiKey()
            {
                var apiKey = Guid.NewGuid();
                var owner = new Credential() { User = new User { Key = 1 } };
                var nonOwner = new User() { ApiKey = apiKey };
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner.User } }
                };
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.MockUserService.Setup(x => x.FindByApiKey(apiKey)).Returns(nonOwner);
                controller.MockUserService
                    .Setup(x => x.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        apiKey.ToString().ToLowerInvariant()))
                    .Returns(owner);

                ResultAssert.IsEmpty(controller.DeletePackage(apiKey.ToString(), "theId", "1.0.42"));

                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true));
                controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:23,代碼來源:ApiControllerFacts.cs

示例5: WillFailIfUserFromAuthenticateCredentialIsNotOwner

            public void WillFailIfUserFromAuthenticateCredentialIsNotOwner()
            {
                // Arrange
                var apiKey = Guid.NewGuid();
                var nonOwner = new Credential() { User = new User { Key = 1 } };
                var owner = new User() { ApiKey = apiKey };
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
                };
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.MockUserService.Setup(x => x.FindByApiKey(apiKey)).Returns(owner);
                controller.MockUserService
                    .Setup(x => x.AuthenticateCredential(
                        CredentialTypes.ApiKeyV1,
                        apiKey.ToString().ToLowerInvariant()))
                    .Returns(nonOwner);

                // Act
                var result = controller.DeletePackage(apiKey.ToString(), "theId", "1.0.42");

                // Assert
                ResultAssert.IsStatusCode(
                    result,
                    HttpStatusCode.Forbidden,
                    String.Format(Strings.ApiKeyNotAuthorized, "delete"));

                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true), Times.Never());
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:30,代碼來源:ApiControllerFacts.cs

示例6: WillUnlistThePackageIfApiKeyBelongsToAnOwner

            public void WillUnlistThePackageIfApiKeyBelongsToAnOwner()
            {
                var owner = new User { Key = 1 };
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
                    };
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);
                var apiKey = Guid.NewGuid();

                controller.DeletePackage(apiKey.ToString(), "theId", "1.0.42");

                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true));
                controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:17,代碼來源:ApiControllerFacts.cs

示例7: WillThrowIfTheApiKeyDoesNotExist

            public void WillThrowIfTheApiKeyDoesNotExist()
            {
                var controller = new TestableApiController();
                controller.MockPackageService
                    .Setup(p => p.FindPackageByIdAndVersion("theId", "1.0.42", true))
                    .Returns(new Package());

                var result = controller.DeletePackage(Guid.NewGuid().ToString(), "theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(403, statusCodeResult.StatusCode);
                Assert.Equal(String.Format(Strings.ApiKeyNotAuthorized, "delete"), statusCodeResult.StatusDescription);
                controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(It.IsAny<Package>(), true), Times.Never());
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:15,代碼來源:ApiControllerFacts.cs

示例8: WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner

            public void WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner()
            {
                var owner = new User { Key = 1 };
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Owners = new[] { new User() } }
                    };
                var apiKey = Guid.NewGuid();
                var controller = new TestableApiController();
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.MockPackageService
                    .Setup(svc => svc.MarkPackageUnlisted(It.IsAny<Package>(), true))
                    .Throws(new InvalidOperationException("Should not have unlisted the package!"));

                var result = controller.DeletePackage(apiKey.ToString(), "theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(Strings.ApiKeyNotAuthorized, statusCodeResult.StatusDescription);
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:21,代碼來源:ApiControllerFacts.cs

示例9: WillFindTheUserThatMatchesTheApiKey

            public void WillFindTheUserThatMatchesTheApiKey()
            {
                var owner = new User { Key = 1, ApiKey = Guid.NewGuid() };
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
                    };

                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);

                controller.DeletePackage(owner.ApiKey.ToString(), "theId", "1.0.42");

                controller.MockUserService.Verify(x => x.FindByApiKey(owner.ApiKey));
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:16,代碼來源:ApiControllerFacts.cs

示例10: WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist

            public void WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist()
            {
                var controller = new TestableApiController();
                controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns((Package)null);
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(new User());

                var result = controller.DeletePackage(Guid.NewGuid().ToString(), "theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(404, statusCodeResult.StatusCode);
                Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"), statusCodeResult.StatusDescription);
            }
開發者ID:projectkudu,項目名稱:NuGetGallery,代碼行數:13,代碼來源:ApiControllerFacts.cs

示例11: WillThrowIfTheApiKeyDoesNotExist

            public void WillThrowIfTheApiKeyDoesNotExist()
            {
                var controller = new TestableApiController();
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns((User)null);

                var result = controller.DeletePackage(Guid.NewGuid().ToString(), "theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
                Assert.Equal(403, statusCodeResult.StatusCode);
                Assert.Equal(String.Format(Strings.ApiKeyNotAuthorized, "delete"), statusCodeResult.StatusDescription);
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:12,代碼來源:ApiControllerFacts.cs

示例12: WillThrowIfTheApiKeyIsAnInvalidGuid

            public void WillThrowIfTheApiKeyIsAnInvalidGuid(string guidValue)
            {
                var controller = new TestableApiController();
                controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns((User)null);

                var result = controller.DeletePackage(guidValue, "theId", "1.0.42");

                Assert.IsType<HttpStatusCodeWithBodyResult>(result);
                AssertStatusCodeResult(result, 400, String.Format("The API key '{0}' is invalid.", guidValue));
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:10,代碼來源:ApiControllerFacts.cs


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