Exemplo n.º 1
0
        public void ApiResponseWithExceptionExtension()
        {
            // Setup
            IApiResponse apiResponse = new ApiResponse(new Status(200));
            IApiObjectResponse <string> objectResponse = new ApiObjectResponse <string>(200, data: "Beatrice");
            PaginationCursor            cursor         = new PaginationCursor(1, 10);
            IApiEnumResponse <string>   enumResponse   = new ApiEnumResponse <string>(200, cursor, true, new List <string> {
                "Nausicaa", "Beatrice"
            });

            var ex1 = new InvalidCastException("ExceptionMessage");

            // Act
            apiResponse.SetException(ex1);
            objectResponse.SetException(ex1);
            enumResponse.SetException(ex1);

            // Assert
            Assert.NotNull(apiResponse.Exception);
            Assert.NotNull(objectResponse.Exception);
            Assert.NotNull(enumResponse.Exception);

            Assert.Equal("ExceptionMessage", apiResponse.Exception.Message);
            Assert.Equal("ExceptionMessage", objectResponse.Exception.Message);
            Assert.Equal("ExceptionMessage", enumResponse.Exception.Message);
        }
Exemplo n.º 2
0
        public async void CheckPaginationMissingPageCursor()
        {
            // Act
            var url      = string.Format("/Pagination/CheckPaginationCursor");
            var response = await Client.GetAsync(url);

            var json = await ReadAsJObjectAsync(response.Content);

            Output.WriteLine(json.ToString());

            var statusCode       = json.SelectToken("status.code").Value <string>();
            var paginationCursor = new PaginationCursor
            {
                PageIndex           = 1,
                PageSize            = 0, // default page size for setupTwo
                IsPageSizeBounded   = false,
                IsPageSizeUnbounded = true
            };

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("OK", statusCode);
            Assert.Equal(paginationCursor, ExtractPaginationCursor(json));
        }
Exemplo n.º 3
0
        public async void CheckPaginationCursorFetch(int pageIndex, int pageSize)
        {
            // Act
            var url      = string.Format("/Pagination/CheckPaginationCursor?pageSize={0}&pageIndex={1}", pageSize, pageIndex);
            var response = await Client.GetAsync(url);

            var json = await ReadAsJObjectAsync(response.Content);

            Output.WriteLine(json.ToString());

            var statusCode       = json.SelectToken("status.code").Value <string>();
            var paginationCursor = new PaginationCursor
            {
                PageIndex           = pageIndex,
                PageSize            = pageSize,
                IsPageSizeBounded   = true,
                IsPageSizeUnbounded = false
            };

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode); // HTTP400
            Assert.Equal("OK", statusCode);
            Assert.Equal(paginationCursor, ExtractPaginationCursor(json));
        }
Exemplo n.º 4
0
        public async void CheckPaginationCursorPageSizeOverrides77OK()
        {
            // Act
            var url      = string.Format("/Pagination/CheckPaginationCursorOverrides?p_sz=77");
            var response = await Client.GetAsync(url);

            var json = await ReadAsJObjectAsync(response.Content);

            Output.WriteLine(json.ToString());

            var statusCode       = json.SelectToken("status.code").Value <string>();
            var paginationCursor = new PaginationCursor
            {
                PageIndex           = 1,
                PageSize            = 77, // custom page size for ther action method
                IsPageSizeBounded   = true,
                IsPageSizeUnbounded = false
            };

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("OK", statusCode);
            Assert.Equal(paginationCursor, ExtractPaginationCursor(json));
        }