Merge pull request #73 from engenb/WithOauthBearerToken

convenience methods to pair with those provided by ClientConfigExtensions
This commit is contained in:
Todd Menier 2016-06-25 17:14:43 -05:00 committed by GitHub
commit a8c2001d79

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
@ -83,6 +84,30 @@ 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>