本文整理汇总了C#中NuGetGallery.TestableApiController.PublishPackage方法的典型用法代码示例。如果您正苦于以下问题:C# TestableApiController.PublishPackage方法的具体用法?C# TestableApiController.PublishPackage怎么用?C# TestableApiController.PublishPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.TestableApiController
的用法示例。
在下文中一共展示了TestableApiController.PublishPackage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WillListThePackageIfUserIsAnOwner
public void WillListThePackageIfUserIsAnOwner()
{
// Arrange
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);
// Act
var result = controller.PublishPackage("theId", "1.0.42");
// Assert
ResultAssert.IsEmpty(result);
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()));
controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
}
示例2: WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist
public void WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist()
{
// Arrange
var controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns((Package)null);
controller.SetCurrentUser(new User());
// Act
var result = controller.PublishPackage("theId", "1.0.42");
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.NotFound,
String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"));
controller.MockPackageService.Verify(x => x.MarkPackageListed(It.IsAny<Package>(), It.IsAny<bool>()), Times.Never());
}
示例3: WillNotListThePackageIfApiKeyDoesNotBelongToAnOwner
public void WillNotListThePackageIfApiKeyDoesNotBelongToAnOwner()
{
// Arrange
var owner = new User { Key = 1 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User() } }
};
var controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns(package);
controller.SetCurrentUser(owner);
// Act
var result = controller.PublishPackage("theId", "1.0.42");
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Forbidden,
String.Format(Strings.ApiKeyNotAuthorized, "publish"));
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()), Times.Never());
}
示例4: WillListThePackageIfApiKeyBelongsToAnOwnerUsingAuthorizeCredential
public void WillListThePackageIfApiKeyBelongsToAnOwnerUsingAuthorizeCredential()
{
// Arrange
var apiKey = Guid.NewGuid();
var owner = new Credential { User = new User { Key = 1 } };
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.AuthenticateCredential(
CredentialTypes.ApiKeyV1,
apiKey.ToString().ToLowerInvariant()))
.Returns(owner);
// Act
var result = controller.PublishPackage(apiKey.ToString(), "theId", "1.0.42");
// Assert
ResultAssert.IsEmpty(result);
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()));
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();
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.PublishPackage(apiKey.ToString(), "theId", "1.0.42");
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Forbidden,
String.Format(Strings.ApiKeyNotAuthorized, "publish"));
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()), Times.Never());
}
示例6: WillListThePackageIfApiKeyBelongsToAnOwner
public void WillListThePackageIfApiKeyBelongsToAnOwner()
{
var owner = new User { Key = 1 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
};
var apiKey = Guid.NewGuid();
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.PublishPackage(apiKey.ToString(), "theId", "1.0.42");
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()));
controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
}
示例7: WillThrowIfTheApiKeyDoesNotExist
public void WillThrowIfTheApiKeyDoesNotExist()
{
// Arrange
var controller = new TestableApiController();
var apiKey = Guid.NewGuid();
controller.MockUserService.Setup(x => x.FindByApiKey(apiKey)).ReturnsNull();
controller.MockPackageService
.Setup(p => p.FindPackageByIdAndVersion("theId", "1.0.42", true))
.Returns(new Package());
// Act
var result = controller.PublishPackage(apiKey.ToString(), "theId", "1.0.42");
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Forbidden,
String.Format(Strings.ApiKeyNotAuthorized, "publish"));
controller.MockPackageService.Verify(x => x.MarkPackageListed(It.IsAny<Package>(), It.IsAny<bool>()), Times.Never());
}
示例8: WillNotListThePackageIfApiKeyDoesNotBelongToAnOwner
public void WillNotListThePackageIfApiKeyDoesNotBelongToAnOwner()
{
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.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
controller.MockPackageService.Setup(svc => svc.MarkPackageListed(It.IsAny<Package>(), It.IsAny<bool>()))
.Throws(new InvalidOperationException("Should not have listed the package!"));
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);
var result = controller.PublishPackage(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 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
};
var apiKey = Guid.NewGuid();
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.PublishPackage(apiKey.ToString(), "theId", "1.0.42");
controller.MockUserService.Verify(x => x.FindByApiKey(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.PublishPackage(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.PublishPackage(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, "publish"), 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.PublishPackage(guidValue, "theId", "1.0.42");
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
AssertStatusCodeResult(result, 400, String.Format("The API key '{0}' is invalid.", guidValue));
}