コード例 #1
0
        public async void GetMultipleItemsFromUri()
        {
            // Assert
            var content = "{" +
                          "\"@odata.context\": \"https://test.local/$metadata\"," +
                          "\"value\": [{" +
                          "\"aProperty\": 5" +
                          "}]" +
                          "}";
            var url         = "https://test.local/";
            var accessToken = "youHaveAccess";

            var mockHttp = new MockHttpMessageHandler();
            // returns the right response if the request is right
            var mockedResponse = mockHttp.When(url)
                                 .Respond("application/json", content)
                                 .WithHeaders("Authorization", "Bearer " + accessToken);

            IGraphSessionService graphService = new GraphSessionService(Guid.NewGuid().ToString(), mockHttp.ToHttpClient());
            var authResult = new AuthenticationResult(accessToken, true, string.Empty, DateTimeOffset.Now, DateTimeOffset.Now, string.Empty, null, string.Empty, null);

            // Act
            var responseContent = await graphService.GetListContent <SampleData>(url, authResult);

            // Arrange
            Assert.Equal(1, mockHttp.GetMatchCount(mockedResponse));
            Assert.Single(responseContent);
            Assert.Equal(5, responseContent.FirstOrDefault().aProperty);
        }
コード例 #2
0
        public async void GetMultipleItemsThrowsErrorIfTheResponseIsNotAList()
        {
            // Assert
            var content = "{" +
                          "\"@odata.context\": \"https://test.local/$metadata\"," +
                          "\"aProperty\": 5" +
                          "}";
            var url         = "https://test.local/";
            var accessToken = "youHaveAccess";

            var mockHttp = new MockHttpMessageHandler();
            // returns the right response if the request is right
            var mockedResponse = mockHttp.When(url)
                                 .Respond("application/json", content)
                                 .WithHeaders("Authorization", "Bearer " + accessToken);

            IGraphSessionService graphService = new GraphSessionService(Guid.NewGuid().ToString(), mockHttp.ToHttpClient());
            var authResult = new AuthenticationResult(accessToken, true, string.Empty, DateTimeOffset.Now, DateTimeOffset.Now, string.Empty, null, string.Empty, null);

            // Act & Arrange
            await Assert.ThrowsAsync <Exception>(async() => await graphService.GetListContent <SampleData>(url, authResult));
        }