Exemple #1
0
        public async Task GetBook_ShouldReturnBook_IfProvidedValidBookId()
        {
            BookDetailDto expectedBook   = db.AddNewBookWithAllFields(DateTime.Now);
            int           expectedBookId = expectedBook.Id;

            for (int i = 0; i < 1000; i++)
            {
                using (var config = new HttpConfiguration())
                {
                    WebApiConfig.Register(config);
                    config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
                    using (var server = new HttpServer(config))
                    {
                        var client = new HttpClient(server);
                        client.BaseAddress = new Uri("http://localhost/api/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var resp = await client.GetAsync("books/" + expectedBookId);

                        resp.EnsureSuccessStatusCode();
                        var book = await resp.Content.ReadAsAsync <BookDto>();

                        Assert.AreEqual <BookDto>(BooksConverter.BookDetailToBook(expectedBook), book);
                    }
                }
            }
        }
        public async Task GetBook_ShouldReturnBook_IfProvidedValidBookId()
        {
            BookDetailDto expectedBook   = db.AddNewBookWithAllFields(DateTime.Now);
            int           expectedBookId = expectedBook.Id;

            using (var client = NewHttpClient())
            {
                var resp = await client.GetAsync("books/" + expectedBookId);

                resp.EnsureSuccessStatusCode();
                var book = await resp.Content.ReadAsAsync <BookDto>();

                Assert.AreEqual <BookDto>(BooksConverter.BookDetailToBook(expectedBook), book);
            }
        }