protected virtual void AssertRequest(CallInfo callInfo, IEndpointClient client, string pathAndQuery) { // Format the URI to how it's supposed to be var uri = new Uri(Gw2WebApiV2Client.UrlBase, $"{client.EndpointPath}{pathAndQuery}"); var parameterProperties = client.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.GetCustomAttribute <EndpointQueryParameterAttribute>() != null); if (parameterProperties.Any()) { var builder = new UriBuilder(uri); foreach (var parameter in parameterProperties) { var attr = parameter.GetCustomAttribute <EndpointQueryParameterAttribute>(); var value = parameter.GetValue(client); if (value == null) { continue; } string toAppend = $"{attr.ParameterName}={value}"; builder.Query = builder.Query != null && builder.Query.Length > 1 ? $"{builder.Query.Substring(1)}&{toAppend}" : toAppend; } uri = builder.Uri; } Assert.Equal(uri.AbsoluteUri, callInfo.ArgAt <IWebApiRequest>(0).Options.Url.AbsoluteUri); var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders; Assert.Contains(new KeyValuePair <string, string>("Accept", "application/json"), requestHeaders); Assert.Contains(new KeyValuePair <string, string>("User-Agent", ((Gw2WebApiBaseClient)client).Connection.UserAgent), requestHeaders); }
private string GetRelativePath(CallInfo callInfo, CalamariPhysicalFileSystem realFileSystem) { //nsubstitute calls the first return when you setup a second one. odd. if (callInfo.ArgAt <string>(0) == null) { return(null); } return(realFileSystem.GetRelativePath(callInfo.ArgAt <string>(0), callInfo.ArgAt <string>(1))); }
public void Get_value_of_argument() { var sut = new CallInfo(new[] { CreateArg(1), CreateArg("ABC") }); var value = sut.ArgAt <string>(1); Assert.That(value, Is.EqualTo("ABC")); }
private bool FilesMatch(CallInfo callInfo, string file) { var filePatterns = callInfo.ArgAt <string[]>(1); return(filePatterns.Any(pattern => { //bit of a naive regex, but it works enough for our tests //"foo.*.config" becomes "foo\..*\.config" var regex = new Regex(pattern.Replace(".", @"\.").Replace("*", ".*")); return regex.IsMatch(file); })); }
protected virtual void AssertSchemaVersionRequest(CallInfo callInfo, IEndpointClient client) { var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders; if (!string.IsNullOrWhiteSpace(client.SchemaVersion)) { Assert.Contains(new KeyValuePair <string, string>("X-Schema-Version", client.SchemaVersion), requestHeaders); } else { Assert.DoesNotContain(requestHeaders, h => h.Key == "X-Schema-Version"); } }
protected virtual void AssertLocalizedRequest(CallInfo callInfo, IEndpointClient client) { var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders; if (client.IsLocalized) { Assert.Contains(new KeyValuePair <string, string>("Accept-Language", ((Gw2WebApiBaseClient)client).Connection.LocaleString), requestHeaders); } else { Assert.DoesNotContain(requestHeaders, h => h.Key == "Accept-Language"); } }
protected virtual void AssertAuthenticatedRequest(CallInfo callInfo, IEndpointClient client) { var requestHeaders = callInfo.ArgAt <IWebApiRequest>(0).Options.RequestHeaders; if (client.IsAuthenticated) { Assert.Contains(new KeyValuePair <string, string>("Authorization", $"Bearer {((Gw2WebApiBaseClient)client).Connection.AccessToken}"), requestHeaders); } else { Assert.DoesNotContain(requestHeaders, h => h.Key == "Authorization"); } }
public void Throw_invalid_cast_exception() { var sut = new CallInfo(new[] { CreateArg("It's not an int!") }); Assert.Throws <InvalidCastException>(() => sut.ArgAt <int>(0)); }
public void Throw_argument_out_of_range() { var sut = new CallInfo(new[] { CreateArg(1) }); Assert.Throws <ArgumentOutOfRangeException>(() => sut.ArgAt <int>(22)); }
protected virtual void AssertLocalizedRequest(CallInfo callInfo, IEndpointClient client) { var requestHeaders = callInfo.ArgAt <IHttpRequest>(0).RequestHeaders; Assert.Contains(new KeyValuePair <string, string>("Accept-Language", ((IClientInternal)client).Connection.LocaleString), requestHeaders); }
// use this on .Returns when you want to return the first argument // passed to the calling function for example on Saves or Creates generally public static Task <T> FirstArgument <T>(this CallInfo args) { return(args.ArgAt <T>(0).ToTask()); }
private void StoreCallInfo(CallInfo callInfo) { _storedEnvironmentStates.Add(callInfo.ArgAt <EnvironmentState>(0)); }