本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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.");
}
示例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);
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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);
}
示例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.");
}
示例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.");
}