Exemplo n.º 1
0
        public void Should_Throw_InvalidOperation_As_All_2_Are_Null()
        {
            //arrange
            string a = null;
            string b = null;

            //act
            //assert
            Assert.Throws <InvalidOperationException>(() => Trashcan.AllAreNull("All null", a, b));
        }
Exemplo n.º 2
0
        public void Should_Not_Throw_InvalidOperation_As_None_Are_Null()
        {
            //arrange
            string a = "null";
            string b = "null";
            string c = "null";

            //act
            var act = Record.Exception(() => Trashcan.AllAreNull("All null", a, b, c));

            //assert
            Assert.Null(act);
        }
Exemplo n.º 3
0
        //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));
        }