コード例 #1
0
        public async Task Options_returns_allowed_methods()
        {
            var client   = _factory.CreateClientNoRedirects();
            var response = await client.OptionsAsync(_endpoint);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
コード例 #2
0
        public async Task Get_by_id_returns_result()
        {
            var client   = _factory.CreateClientNoRedirects();
            var response = await client.GetAsync($"{_endpoint}/{Id}");

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

            response.ShouldNotHaveHeader(ApiHeaderNames.PreferenceApplied);
            response.ShouldHaveHeader(HeaderNames.ETag);
            response.ShouldHaveContentHeader(HeaderNames.LastModified);

            var model = await response.Content.ReadFromJsonAsync <TModel>();

            Assert.NotNull(model ?? throw new NullReferenceException());
            Assert.Equal(Id, model.GetId());
        }
コード例 #3
0
        public async Task Ping_returns_response()
        {
            var client   = _factory.CreateClientNoRedirects();
            var response = await client.GetAsync("ping");

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

            response.ShouldHaveValidDateHeader();
            response.ShouldHaveHeader(HeaderNames.Server);
            response.ShouldHaveHeader(HeaderNames.Connection);
            response.ShouldHaveContentHeader(HeaderNames.ContentLength);

            var options = _factory.Services.GetRequiredService <IOptions <ApiOptions> >();

            Assert.Equal(options.Value.ApiServer, response.Headers.GetValues(HeaderNames.Server).FirstOrDefault());
        }
コード例 #4
0
        public async Task Can_get_cache_info()
        {
            var client   = _factory.CreateClientNoRedirects();
            var response = await client.OptionsAsync("cache");

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

            var body = await response.Content.ReadFromJsonAsync <CacheInfo>();

            Assert.Equal(0, body.KeyCount);
            Assert.Equal(0, body.SizeBytes);
        }
コード例 #5
0
        public async Task Get_without_order_by_returns_sorted_by_id_ascending()
        {
            var client   = _factory.CreateClientNoRedirects();
            var response = await client.GetAsync($"{_endpoint}");

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

            response.ShouldNotHaveHeader(ApiHeaderNames.PreferenceApplied);
            response.ShouldHaveHeader(HeaderNames.ETag);
            response.ShouldHaveContentHeader(HeaderNames.LastModified);

            var model = await response.Content.ReadFromJsonAsync <Many <TModel> >();

            Assert.NotNull(model ?? throw new NullReferenceException());

            var ordered = model.Value.ToList();

            Assert.Equal(2, ordered.Count);

            Assert.Equal(ordered[0]?.GetId(), IdLessThanInsertedSecond);
            Assert.Equal(ordered[1]?.GetId(), IdGreaterThanInsertedFirst);
        }