public void ShouldThrowWhenAuthenticatorThrows() { MockedPackageAuthenticator.Setup(pa => pa.EnsureKeyCanAccessPackage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Throws(new WebFaultException(HttpStatusCode.BadRequest)); TestDelegate methodThatShouldThrow = () => PackageService.Delete("key", "id", "version"); Assert.Throws <WebFaultException <string> >(methodThatShouldThrow, "Exception should have been thrown since PackageAuthenticator threw."); }
public void ShouldEnsureGivenKeyHasAccessToPackage() { string key = Guid.NewGuid().ToString(); const string id = "id"; const string version = "version"; PackageService.Delete(key, id, version); MockedPackageAuthenticator.Verify(pa => pa.EnsureKeyCanAccessPackage(key, id, version), Times.Once(), "PackageAuthenticator's EnsureKeyCanAccessPackage should have been invoked with the specified arguments."); }
public void ShouldThrowWhenAuthenticatorThrows() { string key = Guid.NewGuid().ToString(); const string id = "id"; const string version = "version"; var packageToUpdate = new Package(); MockedPackageAuthenticator.Setup(pa => pa.EnsureKeyCanAccessPackage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Throws(new WebFaultException(HttpStatusCode.BadRequest)); TestDelegate methodThatShouldThrow = () => PackageService.Update(key, id, version, packageToUpdate); Assert.Throws <WebFaultException <string> >(methodThatShouldThrow, "Exception should have been thrown since PackageAuthenticator threw."); }