本文整理汇总了C#中NuGetGallery.TestableApiController.GetPackage方法的典型用法代码示例。如果您正苦于以下问题:C# TestableApiController.GetPackage方法的具体用法?C# TestableApiController.GetPackage怎么用?C# TestableApiController.GetPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.TestableApiController
的用法示例。
在下文中一共展示了TestableApiController.GetPackage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPackageReturns503IfNoVersionIsProvidedAndDatabaseUnavailable
public async Task GetPackageReturns503IfNoVersionIsProvidedAndDatabaseUnavailable()
{
// Arrange
var package = new Package();
var actionResult = new EmptyResult();
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("Baz", "", false)).Throws(new DataException("Oh noes, database broked!"));
NameValueCollection headers = new NameValueCollection();
headers.Add("NuGet-Operation", "Install");
var httpRequest = new Mock<HttpRequestBase>(MockBehavior.Strict);
httpRequest.SetupGet(r => r.UserHostAddress).Returns("Foo");
httpRequest.SetupGet(r => r.UserAgent).Returns("Qux");
httpRequest.SetupGet(r => r.Headers).Returns(headers);
httpRequest.SetupGet(r => r.Url).Returns(HttpRequestUrl);
var httpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
httpContext.SetupGet(c => c.Request).Returns(httpRequest.Object);
var controllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), controller);
controller.ControllerContext = controllerContext;
// Act
var result = await controller.GetPackage("Baz", "");
// Assert
ResultAssert.IsStatusCode(result, HttpStatusCode.ServiceUnavailable, Strings.DatabaseUnavailable_TrySpecificVersion);
controller.MockPackageFileService.Verify();
controller.MockPackageService.Verify();
controller.MockUserService.Verify();
}
示例2: GetPackageReturnsSpecificPackageEvenIfDatabaseIsOffline
public async Task GetPackageReturnsSpecificPackageEvenIfDatabaseIsOffline()
{
// Arrange
var package = new Package();
var actionResult = new EmptyResult();
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("Baz", "1.0.0", false)).Throws(new DataException("Can't find the database")).Verifiable();
controller.MockPackageFileService.Setup(s => s.CreateDownloadPackageActionResultAsync(HttpRequestUrl, "Baz", "1.0.0"))
.Returns(Task.FromResult<ActionResult>(actionResult))
.Verifiable();
NameValueCollection headers = new NameValueCollection();
headers.Add("NuGet-Operation", "Install");
var httpRequest = new Mock<HttpRequestBase>(MockBehavior.Strict);
httpRequest.SetupGet(r => r.UserHostAddress).Returns("Foo");
httpRequest.SetupGet(r => r.UserAgent).Returns("Qux");
httpRequest.SetupGet(r => r.Headers).Returns(headers);
httpRequest.SetupGet(r => r.Url).Returns(HttpRequestUrl);
var httpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
httpContext.SetupGet(c => c.Request).Returns(httpRequest.Object);
var controllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), controller);
controller.ControllerContext = controllerContext;
// Act
var result = await controller.GetPackage("Baz", "1.0.0");
// Assert
Assert.Same(actionResult, result);
controller.MockPackageFileService.Verify();
controller.MockPackageService.Verify();
}
示例3: GetPackageReturnsLatestPackageIfNoVersionIsProvided
public async Task GetPackageReturnsLatestPackageIfNoVersionIsProvided()
{
// Arrange
const string PackageId = "Baz";
var package = new Package() { Version = "1.2.0408", NormalizedVersion = "1.2.408" };
var actionResult = new EmptyResult();
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(PackageId, "", false)).Returns(package);
controller.MockPackageService.Setup(x => x.AddDownloadStatistics(It.IsAny<PackageStatistics>())).Verifiable();
controller.MockPackageFileService.Setup(s => s.CreateDownloadPackageActionResultAsync(HttpRequestUrl, PackageId, package.NormalizedVersion))
.Returns(Task.FromResult<ActionResult>(actionResult))
.Verifiable();
NameValueCollection headers = new NameValueCollection();
headers.Add("NuGet-Operation", "Install");
var httpRequest = new Mock<HttpRequestBase>(MockBehavior.Strict);
httpRequest.SetupGet(r => r.UserHostAddress).Returns("Foo");
httpRequest.SetupGet(r => r.UserAgent).Returns("Qux");
httpRequest.SetupGet(r => r.Headers).Returns(headers);
httpRequest.SetupGet(r => r.Url).Returns(HttpRequestUrl);
var httpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
httpContext.SetupGet(c => c.Request).Returns(httpRequest.Object);
var controllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), controller);
controller.ControllerContext = controllerContext;
// Act
var result = await controller.GetPackage(PackageId, "");
// Assert
Assert.Same(actionResult, result);
controller.MockPackageFileService.Verify();
controller.MockPackageService.Verify();
controller.MockUserService.Verify();
}
示例4: GetPackageReturns404IfPackageIsNotFound
public async Task GetPackageReturns404IfPackageIsNotFound()
{
// Arrange
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("Baz", "1.0.1", false)).Returns((Package)null).Verifiable();
// Act
var result = await controller.GetPackage("Baz", "1.0.1");
// Assert
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var httpNotFoundResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, "Baz", "1.0.1"), httpNotFoundResult.StatusDescription);
controller.MockPackageService.Verify();
}
示例5: GetPackageReturns400ForEvilPackageVersion
public async Task GetPackageReturns400ForEvilPackageVersion()
{
var controller = new TestableApiController();
var result2 = await controller.GetPackage("Foo", "10../..1.0");
var badRequestResult2 = (HttpStatusCodeWithBodyResult)result2;
Assert.Equal(400, badRequestResult2.StatusCode);
}
示例6: GetPackageReturns400ForEvilPackageName
public async Task GetPackageReturns400ForEvilPackageName()
{
var controller = new TestableApiController();
var result = await controller.GetPackage("../..", "1.0.0.0");
var badRequestResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(400, badRequestResult.StatusCode);
}
示例7: GetPackageReturns404IfPackageIsNotFound
public async Task GetPackageReturns404IfPackageIsNotFound()
{
// Arrange
const string packageId = "Baz";
const string packageVersion = "1.0.1";
var actionResult = new RedirectResult("http://foo");
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(packageId, packageVersion, false)).Returns((Package)null).Verifiable();
controller.MockPackageFileService.Setup(s => s.CreateDownloadPackageActionResultAsync(It.IsAny<Uri>(), packageId, packageVersion))
.Returns(Task.FromResult<ActionResult>(actionResult))
.Verifiable();
// Act
var result = await controller.GetPackage(packageId, packageVersion);
// Assert
Assert.IsType<RedirectResult>(result); // all we want to check is that we're redirecting to storage
//var httpNotFoundResult = (RedirectResult)result;
//Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, packageId, packageVersion), httpNotFoundResult.StatusDescription);
//controller.MockPackageService.Verify();
}
示例8: GetPackageReturnsPackageIfItExists
public async Task GetPackageReturnsPackageIfItExists()
{
// Arrange
var guid = Guid.NewGuid();
var package = new Package();
var actionResult = new EmptyResult();
var controller = new TestableApiController(MockBehavior.Strict);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("Baz", "1.0.1", false)).Returns(package);
controller.MockPackageService.Setup(x => x.AddDownloadStatistics(It.IsAny<PackageStatistics>())).Verifiable();
controller.MockPackageFileService.Setup(s => s.CreateDownloadPackageActionResultAsync(HttpRequestUrl, package))
.Returns(Task.FromResult<ActionResult>(actionResult))
.Verifiable();
controller.MockUserService.Setup(x => x.FindByApiKey(guid)).Returns(new User());
NameValueCollection headers = new NameValueCollection();
headers.Add("NuGet-Operation", "Install");
var httpRequest = new Mock<HttpRequestBase>(MockBehavior.Strict);
httpRequest.SetupGet(r => r.UserHostAddress).Returns("Foo");
httpRequest.SetupGet(r => r.UserAgent).Returns("Qux");
httpRequest.SetupGet(r => r.Headers).Returns(headers);
httpRequest.SetupGet(r => r.Url).Returns(HttpRequestUrl);
var httpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
httpContext.SetupGet(c => c.Request).Returns(httpRequest.Object);
var controllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), controller);
controller.ControllerContext = controllerContext;
// Act
var result = await controller.GetPackage("Baz", "1.0.1");
// Assert
Assert.Same(actionResult, result);
controller.MockPackageFileService.Verify();
controller.MockPackageService.Verify();
controller.MockUserService.Verify();
}