convenience methods to pair with those provided by ClientConfigExtensions

This commit is contained in:
Brian Engen 2016-04-16 22:14:43 -05:00
parent 3b4777fc09
commit bf9241a430

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
namespace Flurl.Http.Testing
@ -73,6 +74,29 @@ namespace Flurl.Http.Testing
return With(c => c.Request.Content.Headers.ContentType.MediaType == contentType);
}
/// <summary>
/// Asserts whether the Authorization header was set with OAuth.
/// </summary>
/// <param name="token">Expected token value</param>
/// <returns></returns>
public HttpCallAssertion WithOAuthBearerToken(string token) {
return With(c => c.Request.Headers.Authorization?.Scheme == "Bearer"
&& c.Request.Headers.Authorization?.Parameter == token);
}
/// <summary>
/// Asserts whether the Authorization header was set with basic auth.
/// </summary>
/// <param name="username">Expected username</param>
/// <param name="password">Expected password</param>
/// <returns></returns>
public HttpCallAssertion WithBasicAuth(string username, string password)
{
var value = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
return With(c => c.Request.Headers.Authorization?.Scheme == "Basic"
&& c.Request.Headers.Authorization?.Parameter == value);
}
/// <summary>
/// Asserts whether calls were made matching a given predicate function.
/// </summary>