Esempio n. 1
0
        public async Task AsRawJsonObject_Dynamic(string content)
        {
            // arrange
            IResponse response = this.ConstructResponse(new Model <string>(content));

            // act
            dynamic json = await response
                           .AsRawJsonObject()
                           .VerifyTaskResultAsync();

            // assert
            Assert.That((string)json.Value, Is.EqualTo(content));
        }
Esempio n. 2
0
        public async Task <string> GetTokenAsync(string userName, string password)
        {
            Guard.NotNullOrEmpty(userName, nameof(userName), "Username is required field");
            Guard.NotNullOrEmpty(password, nameof(password), "Password is required field");

            var requestData = new
            {
                username = userName, password
            };

            IResponse response = await _client.PostAsync("v1/tokens")
                                 .WithBody(b => b.Model(requestData, new JsonMediaTypeFormatter()))
                                 .WithOptions(true);

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(response.Message.ReasonPhrase);
            }

            var jObject = await response.AsRawJsonObject().ConfigureAwait(false);

            return(jObject["token"].ToString());
        }
Esempio n. 3
0
        /// <summary>Get a raw JSON object representation of the response, which can also be accessed as a <c>dynamic</c> value.</summary>
        public async Task <JObject> AsRawJsonObject()
        {
            IResponse response = await this.AsResponse().ConfigureAwait(false);

            return(await response.AsRawJsonObject().ConfigureAwait(false));
        }