Esempio n. 1
0
        public CouchDbTests()
        {
            _dbRequester = HttpRequester.Create(DbUrlWithCredentials);
            var head = _dbRequester.HeadAsync().Result;

            if (head.IsSuccess)
            {
                _dbRequester.DeleteAsync().Wait();
            }
        }
Esempio n. 2
0
        public async void Flow_tests()
        {
            var person = new Person
            {
                Id        = Guid.NewGuid(),
                FirstName = "Daniel",
                LastName  = "Wertheim",
                Age       = 35
            };

            using (var requester = HttpRequester.Create($"{_server.BaseAddress}api/persons/", _server.CreateHandler()))
            {
                var forTheCreatingPut = await requester.PutEntityAsJsonAsync(person);

                forTheCreatingPut.TheResponse(should => should
                                              .BeSuccessful()
                                              .HaveStatus(HttpStatusCode.Created));

                var forTheGet = await requester.GetAsync(person.Id.ToString());

                forTheGet.TheResponse(should => should
                                      .BeSuccessful()
                                      .BeJsonResponse()
                                      .HaveSpecificValueFor("firstName", "Daniel"));

                person.Age = 42;
                var forTheUpdatingPut = await requester.PutEntityAsJsonAsync(person);

                forTheUpdatingPut.TheResponse(should => should
                                              .BeSuccessful()
                                              .HaveStatus(HttpStatusCode.OK));

                var forTheDelete = await requester.DeleteAsync(person.Id.ToString());

                forTheDelete.TheResponse(should => should
                                         .BeSuccessful()
                                         .HaveStatus(HttpStatusCode.OK));

                var forTheCreatingPost = await requester.PostEntityAsJsonAsync(person);

                forTheCreatingPost.TheResponse(should => should
                                               .BeSuccessful()
                                               .HaveStatus(HttpStatusCode.Created)
                                               .BeJsonResponse()
                                               .NotHavingSpecificValueFor("id", person.Id));
            }
        }
Esempio n. 3
0
        public async void Can_use_basic_auth_on_HttpRequester()
        {
            using (var requester = HttpRequester.Create(DbUrl).Configure(cfg => cfg.WithBasicAuthorization(U, P)))
            {
                var db = await requester.PutAsync();

                db.TheResponse(should => should.BeSuccessful());

                var docId  = Guid.NewGuid().ToString("N");
                var newDoc = await requester.PutJsonAsync("{\"value\":\"can_use_basic_auth_on_HttpRequester\"}", docId);

                newDoc.TheResponse(should => should.BeSuccessful());

                var deleteDoc = await requester.DeleteAsync(docId + "?rev=" + newDoc.ETag);

                deleteDoc.TheResponse(should => should.BeSuccessful());
            }
        }
Esempio n. 4
0
        public async void Can_retrieve_empty_content()
        {
            using (var requester = HttpRequester.Create($"{_server.BaseAddress}api/test/empty", _server.CreateHandler()))
            {
                var request = new HttpRequest(HttpMethod.Get);
                request.WithAccept(ct => ct.ApplicationJson);

                var textResponse = await requester.SendAsync(request);

                textResponse.TheResponse(should => should
                                         .BeSuccessful());

                var entityResponse = await requester.GetAsync <Person>();

                entityResponse.TheResponse(should => should
                                           .BeSuccessful());
                entityResponse.Content.Should().BeNull();
            }
        }
Esempio n. 5
0
        public async void Can_have_resulting_entity_with_Post_HttpRequester()
        {
            using (var requester = HttpRequester.Create(DbUrl).Configure(cfg => cfg.WithBasicAuthorization(U, P)))
            {
                var db = await requester.PutAsync();

                db.TheResponse(should => should.BeSuccessful());

                var newDoc = await requester.PostJsonAsync <dynamic>("{\"value\":\"one\"}");

                newDoc.TheResponse(should => should.BeSuccessful());

                string id  = newDoc.Content.id;
                string rev = newDoc.Content.rev;

                var putDoc = await requester.PutJsonAsync <dynamic>("{\"value\":\"two\"}", $"{id}?rev={rev}");

                putDoc.TheResponse(should => should.BeSuccessful());
            }
        }
Esempio n. 6
0
        public async void Can_PUT_form_url_encoded_content()
        {
            using (var requester = HttpRequester.Create($"{_server.BaseAddress}api/relay/", _server.CreateHandler()))
            {
                var request = new HttpRequest(HttpMethod.Put);
                request.WithContent(new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    { "key", "test" },
                    { "value", "42" }
                }));

                var response = await requester.SendAsync(request);

                response.TheResponse(should => should
                                     .BeSuccessful()
                                     .BeJsonResponse()
                                     .HaveSpecificValueFor("key", "test")
                                     .HaveSpecificValueFor("value", "42"));
            }
        }