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