public void EncryptXmlAsyncThrowsWhenCryptoIsNull() { var xml = "<foo bar=\"123\"><baz>456</baz><baz>789</baz><qux><garply grault=\"abc\" /></qux></foo>"; var keyIdentifier = new object(); ICrypto crypto = null; Assert.That(async() => await crypto.EncryptXmlAsync(xml, new[] { "/foo/@bar", "/foo/baz", "/foo/qux" }, keyIdentifier), Throws.ArgumentNullException); }
/// <summary> /// Asynchronously encrypts the fields, specified by XPath, that are contained in the given xml document string. /// </summary> /// <param name="crypto"> /// The instance of <see cref="ICrypto"/> that ultimately responsible for performing encryption operations /// on field values. /// </param> /// <param name="xmlString">A string containing an xml document.</param> /// <param name="xpathToEncrypt">The XPath of the field to encrypt.</param> /// <param name="credentialName"> /// The name of the credential to use for this encryption operation, /// or null to use the default credential. /// </param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>A task that will contain the same xml document, except with the specified fields encrypted.</returns> public static Task <string> EncryptXmlAsync(this ICrypto crypto, string xmlString, string xpathToEncrypt, string credentialName = null, CancellationToken cancellationToken = default(CancellationToken)) => crypto.EncryptXmlAsync(xmlString, new[] { xpathToEncrypt }, credentialName, cancellationToken);