Example #1
0
        public async Task CanAddABook()
        {
            // create a book to send
            var bookToAdd = new PostBookRequest
            {
                author        = "Smith",
                title         = "Effecient use of virual machines in the cloud",
                genre         = "fiction",
                numberOfPages = 3
            };

            // send to our api
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            // test response that it got created
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            // in response check the path for where the one book can be found
            var location = response.Headers.Location.LocalPath;

            // get the book by the path revieved and set it to Type Book Response
            var getItResponse = await Client.GetAsync(location);

            var responseData = await getItResponse.Content.ReadAsAsync <GetABookResponse>();

            // test that the data sent was the data recieved from the GET
            Assert.Equal(bookToAdd.title, responseData.title);
            Assert.Equal(bookToAdd.author, responseData.author);
        }
Example #2
0
        public async Task HasCorrectStatusCode()
        {
            var bookToAdd = new PostBookRequest
            {
                title         = "Walden",
                author        = "Thoreau",
                genre         = "Philosophy",
                numberOfPages = 223
            };
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
Example #3
0
        public async Task HasCorrectResponseBody()
        {
            var bookToAdd = new PostBookRequest
            {
                title         = "Walden",
                author        = "Thoreau",
                genre         = "Philosophy",
                numberOfPages = 223
            };
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            var content = await response.Content.ReadAsAsync <PostBookResponse>();

            Assert.Equal("Walden", content.title);
            // etc. etc.
        }
Example #4
0
        public async Task HasLocationHeader()
        {
            var bookToAdd = new PostBookRequest
            {
                title         = "Walden",
                author        = "Thoreau",
                genre         = "Philosophy",
                numberOfPages = 223
            };
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            var content = await response.Content.ReadAsAsync <PostBookResponse>();

            var id = content.id;

            var header = response.Headers.Location.AbsoluteUri;

            Assert.Equal($"http://localhost/books/{id}", header);
            Assert.Equal("http://localhost/books/" + id, header);
        }
        public async Task CanAddABook()
        {
            var bookToAdd = new PostBookRequest
            {
                author        = "Smith",
                title         = "Efficient Use of Virtual Machines in the Cloud",
                genre         = "fiction",
                numberOfPages = 3
            };
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            var location = response.Headers.Location.LocalPath;

            var getItReponse = await Client.GetAsync(location);

            var responseData = await getItReponse.Content.ReadAsAsync <GetABookResponse>();

            Assert.Equal(bookToAdd.title, responseData.title);
            Assert.Equal(bookToAdd.author, responseData.author);
        }
Example #6
0
        public async Task CanAddABook()
        {
            var bookToAdd = new PostBookRequest
            {
                title         = "Composing Electronic Music",
                author        = "Smihht",
                genre         = "Non-Fiction",
                numberOfPages = 322
            };
            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var location      = response.Headers.Location.LocalPath; // books/4
            var getItResponse = await Client.GetAsync(location);

            var responseData = await getItResponse.Content.ReadAsAsync <BookDetailsResponse>();

            Assert.Equal(bookToAdd.title, responseData.title);
            Assert.Equal(bookToAdd.author, responseData.author);
            //etc etc.
        }
Example #7
0
        public async Task CanAddABook()
        {
            var bookToAdd = new PostBookRequest
            {
                title         = "The Land Founding",
                author        = "Aleron Kong",
                genre         = "Lit RPG",
                numberOfPages = 294
            };

            var response = await Client.PostAsJsonAsync("/books", bookToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var location = response.Headers.Location.LocalPath;

            var getItResponse = await Client.GetAsync(location);

            var responseData = await getItResponse.Content.ReadAsAsync <BookDetailsResponse>();

            Assert.Equal(bookToAdd.title, responseData.title);
            Assert.Equal(bookToAdd.author, responseData.author);
        }
Example #8
0
        public async Task CanAddABook()
        {
            var bookToAdd = new PostBookRequest
            {
                author        = "James Patterson",
                genre         = "Suspense",
                numberOfPages = 450,
                title         = "Criss Cross"
            };

            var response = await _client.PostAsJsonAsync(@"/books", bookToAdd);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var location = response.Headers.Location.LocalPath;

            var getItResponse = await _client.GetAsync(location);

            var responseData = await getItResponse.Content.ReadAsAsync <BookDetailsResponse>();

            Assert.Equal(bookToAdd.title, responseData.title);
            Assert.Equal(bookToAdd.author, responseData.author);
        }