public async Task Given_Validation_Result_With_CancellationToken_When_PatchAsync_Invoked_Then_It_Should_Return_Result(HttpStatusCode statusCode)
        {
            var requestUri = "http://localhost";
            var payload    = "{ \"hello\": \"world\" }";

            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true);

            var path = "default.json";

            using (var response = this._fixture.CreateHttpResponseMessage(statusCode, payload))
                using (var handler = this._fixture.CreateFakeHttpMessageHandler(response))
                    using (var httpClient = this._fixture.CreateHttpClient(handler))
                        using (var content = this._fixture.CreateHttpContent())
                            using (var source = this._fixture.CreateCancellationTokenSource())
                            {
                                var result = await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, validator.Object, path, source.Token).ConfigureAwait(false);

                                result.Should().Be(response);
                            }

            using (var response = this._fixture.CreateHttpResponseMessage(statusCode, payload))
                using (var handler = this._fixture.CreateFakeHttpMessageHandler(response))
                    using (var httpClient = this._fixture.CreateHttpClient(handler))
                        using (var content = this._fixture.CreateHttpContent())
                            using (var source = this._fixture.CreateCancellationTokenSource())
                            {
                                var result = await HttpClientExtensions.PatchAsync(httpClient, new Uri(requestUri), content, validator.Object, path, source.Token).ConfigureAwait(false);

                                result.Should().Be(response);
                            }
        }
Пример #2
0
        public async Task <Course> UpdateObject(Course updateCourse)
        {
            Course course = new Course();

            try
            {
                var json = JsonConvert.SerializeObject(updateCourse);
                var body = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await HttpClientExtensions.PatchAsync(client, Constants.HOSTNAME + Constants.COURSE_PATH + "/externalId:" + Constants.COURSE_ID, body);


                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				Course successfully updated.");
                    var content = await response.Content.ReadAsStringAsync();

                    course = JsonConvert.DeserializeObject <Course>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(course);
        }
        public void Given_Error_Response_With_CancellationToken_When_PatchAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode)
        {
            var requestUri = "http://localhost";
            var validator  = new Mock <ISchemaValidator>();
            var path       = "default.json";

            var func = default(Func <Task>);

            using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode))
                using (var httpClient = this._fixture.CreateHttpClient(handler))
                    using (var content = this._fixture.CreateHttpContent())
                        using (var source = this._fixture.CreateCancellationTokenSource())
                        {
                            func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, validator.Object, path, source.Token).ConfigureAwait(false);

                            func.Should().Throw <HttpRequestException>();
                        }

            using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode))
                using (var httpClient = this._fixture.CreateHttpClient(handler))
                    using (var content = this._fixture.CreateHttpContent())
                        using (var source = this._fixture.CreateCancellationTokenSource())
                        {
                            func = async() => await HttpClientExtensions.PatchAsync(httpClient, new Uri(requestUri), content, validator.Object, path, source.Token).ConfigureAwait(false);

                            func.Should().Throw <HttpRequestException>();
                        }
        }
        public void Given_Validation_Error_With_CancellationToken_When_PatchAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode)
        {
            var requestUri = "http://localhost";
            var payload    = "{ \"hello\": \"world\" }";

            var exception = new SchemaValidationException();
            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(exception);

            var path = "default.json";

            var func = default(Func <Task>);

            using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode, payload))
                using (var httpClient = this._fixture.CreateHttpClient(handler))
                    using (var content = this._fixture.CreateHttpContent())
                        using (var source = this._fixture.CreateCancellationTokenSource())
                        {
                            func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, validator.Object, path, source.Token).ConfigureAwait(false);

                            func.Should().Throw <SchemaValidationException>();

                            func = async() => await HttpClientExtensions.PatchAsync(httpClient, new Uri(requestUri), content, validator.Object, path, source.Token).ConfigureAwait(false);

                            func.Should().Throw <SchemaValidationException>();
                        }
        }
        public async Task <Membership> UpdateObject(Membership updateMembership)
        {
            Membership membership = new Membership();

            try
            {
                var json = JsonConvert.SerializeObject(updateMembership);
                var body = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await HttpClientExtensions.PatchAsync(client, Constants.HOSTNAME + Constants.COURSE_PATH + "/externalId:" + Constants.COURSE_ID + "users/externalId:" + Constants.USER_ID, body);


                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				Membership successfully updated.");
                    var content = await response.Content.ReadAsStringAsync();

                    membership = JsonConvert.DeserializeObject <Membership>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(membership);
        }
Пример #6
0
        public async Task <Term> UpdateObject(Term updateTerm)
        {
            Term term = new Term();

            try
            {
                var json = JsonConvert.SerializeObject(updateTerm);
                var body = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await HttpClientExtensions.PatchAsync(client, Constants.HOSTNAME + Constants.TERM_PATH + "/externalId:" + Constants.TERM_ID, body);

                Constants.RESPONSERESULT = "Fail";
                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				Term successfully updated.");
                    var content = await response.Content.ReadAsStringAsync();

                    term = JsonConvert.DeserializeObject <Term>(content);
                    Constants.RESPONSERESULT = "Update";
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(term);
        }
Пример #7
0
        public async Task <User> UpdateObject(User updateuser)
        {
            User user = new User();

            try
            {
                #region "Set Updateuser User"

                UpdateUser upuser = new UpdateUser();
                upuser.externalId = updateuser.externalId;
                upuser.password   = updateuser.password;
                upuser.userName   = updateuser.userName;
                upuser.studentId  = updateuser.studentId;
                //user.educationLevel = string.Empty;
                //user.gender = string.Empty;
                //user.birthDate = string.Empty;


                upuser.systemRoleIds = updateuser.systemRoleIds;
                upuser.availability  = updateuser.availability;
                upuser.name          = updateuser.name;

                //job.title = string.Empty;
                //job.department = string.Empty;
                //job.company = string.Empty;
                upuser.job = updateuser.job;

                upuser.contact = updateuser.contact;

                upuser.address = updateuser.address;
                upuser.locale  = updateuser.locale;

                #endregion

                var json = JsonConvert.SerializeObject(upuser);
                var body = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await HttpClientExtensions.PatchAsync(client, Constants.HOSTNAME + Constants.USER_PATH + "/externalId:" + Constants.USER_ID, body);

                Constants.RESPONSERESULT = "Fail";

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				User successfully updated.");
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        user = JsonConvert.DeserializeObject <User>(content);
                        Constants.RESPONSERESULT = "Update";
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(user);
        }
        public void Given_Null_Parameters_When_PatchAsync_Invoked_Then_It_Should_Throw_Exception()
        {
            var requestUri = "http://localhost";
            var validator  = new Mock <ISchemaValidator>();

            var func = default(Func <Task>);

            using (var httpClient = this._fixture.CreateHttpClient())
                using (var content = this._fixture.CreateHttpContent())
                {
                    func = async() => await HttpClientExtensions.PatchAsync(null, (string)null, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, (string)null, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, validator.Object, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(null, (Uri)null, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, (Uri)null, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, null, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, null, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();

                    func = async() => await HttpClientExtensions.PatchAsync(httpClient, requestUri, content, validator.Object, null).ConfigureAwait(false);

                    func.Should().Throw <ArgumentNullException>();
                }
        }