public void Should_Throw_Null_On_CommonParameters() { //arrange CommonParameters p = null; //act //assert Assert.Throws <ArgumentNullException>(() => Trashcan.IsNull(nameof(p), p)); }
public void Should_Throw_Null_On_String() { //arrange string n = null; //act //assert Assert.Throws <ArgumentNullException>(() => Trashcan.IsNull(nameof(n), n)); }
public void Should_Not_Throw_Null_On_String() { //arrange string n = "hello"; //act var act = Record.Exception(() => Trashcan.IsNull(nameof(n), n)); //assert Assert.Null(act); }
//TODO: baseUrl needs to be an optional parameter /// /// <summary> /// Simple GET Method to obtain a JSON payload. /// </summary> /// <param name="queryStringParameters"></param> /// <param name="urlOverride"></param> /// <typeparam name="TResponse"></typeparam> /// <returns>JSON response.</returns> public async virtual Task <dynamic> GetAsync(IHachetteCommonParameters queryStringParameters, string urlOverride = null) { Trashcan.AllAreNull($"both {nameof(urlOverride)} & {this.Endpoint.BaseUrl} are null", urlOverride, this.Endpoint.BaseUrl); Trashcan.IsNull(nameof(queryStringParameters), queryStringParameters); //baseUrl is basically an override and should be treated as such. string urlToUse = string.Empty; if (string.IsNullOrEmpty(urlOverride)) { Trashcan.IsNull(nameof(this.Endpoint.BaseUrl), this.Endpoint.BaseUrl); urlToUse = this.Endpoint.BaseUrl; } else { urlToUse = urlOverride; } using (var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"{urlToUse}{queryStringParameters.BuildQueryString()}"))) { request.Headers.Add("x-apikey", new[] { this.Security.DeveloperKey }); request.Headers.Add("x-sdk", $"dotnet-{this.assemblyVersion}"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full }; var s = await response.Content.ReadAsStringAsync(); dynamic json = JObject.Parse(s); return(json); } } return(default(dynamic)); }