コード例 #1
0
            public async Task JsonWithNoItemsDoNotHaveObjectsInTheResult()
            {
                const string response = "{'error':'OK','limit':1,'offset':900,'number_of_page_results':0,'number_of_total_results':717,'status_code':1,'results':[],'version':'1.0'}";

                // arrange
                var httpMessenger = Substitute.For <IHttpMessenger>();

                httpMessenger.GetAsync(Arg.Any <Uri>()).Returns(Task.FromResult(response));
                var httpConnection = new HttpConnection(httpMessenger, Settings.ApiKey);

                // act
                var result = await httpConnection.FilterAsync <TestModel>(new Uri("anything", UriKind.Relative), null);

                // assert
                Assert.Equal(StatusCode.Ok, result.StatusCode);
                Assert.Empty(result.Results);
            }
コード例 #2
0
            public async Task ThrowsWithMissingMember()
            {
                const string response = "{'error':'OK','limit':1,'offset':0,'number_of_page_results':1,'number_of_total_results':717,'status_code':1,'results':[{'id':1,rabbits:true}],'version':'1.0'}";

                // arrange
                var httpMessenger = Substitute.For <IHttpMessenger>();

                httpMessenger.GetAsync(Arg.Any <Uri>()).Returns(Task.FromResult(response));
                var httpConnection = new HttpConnection(httpMessenger, Settings.ApiKey);

                httpConnection.ThrowOnMissingProperties = true;

                // act & assert
                var ex = await Assert.ThrowsAsync <JsonSerializationException>(() => httpConnection.FilterAsync <TestModel>(new Uri("anything", UriKind.Relative), null));

                Assert.Contains("rabbits", ex.Message, StringComparison.OrdinalIgnoreCase);
            }
コード例 #3
0
            public async Task ParametersWithSpacesAreEscaped()
            {
                const string response = "{'error':'OK','limit':1,'offset':900,'number_of_page_results':0,'number_of_total_results':717,'status_code':1,'results':[],'version':'1.0'}";

                // arrange
                var httpMessenger = Substitute.For <IHttpMessenger>();

                httpMessenger.GetAsync(Arg.Any <Uri>()).Returns(Task.FromResult(response));
                var httpConnection = new HttpConnection(httpMessenger, Settings.ApiKey);
                var options        = new Dictionary <string, object>
                {
                    { "key", "option:value with space" }
                };

                // act
                var result = await httpConnection.FilterAsync <TestModel>(new Uri("anything", UriKind.Relative), options);

                // assert
                _ = httpMessenger.Received().GetAsync(
                    Arg.Is <Uri>(u => u.Query.Contains("key=option:value%20with%20space", StringComparison.OrdinalIgnoreCase)));
            }