Esempio n. 1
0
        public void given_httpClient_returns_Unauthorized_response_then_gateway_throws_an_CRMException_exception()
        {
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.Unauthorized
            }).Verifiable();

            HttpClient httpCLient = new HttpClient(mockHttpMessageHandler.Object)
            {
                BaseAddress = mockBaseUri
            };

            CRMGateway CRMGateway = new CRMGateway(_mockCRMTokenGateway, httpCLient);

            //assert
            Assert.Throws <CRMException>(delegate { CRMGateway.GetEntitiesByFetchXMLQuery("", ""); });
        }
Esempio n. 2
0
        public void given_that_httpClient_returns_valid_response_then_gateway_returns_correct_value()
        {
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(InteractionsHelper.GetExpectedCRMGatewayResponseForGetInteractions())
            }).Verifiable();

            HttpClient httpCLient = new HttpClient(mockHttpMessageHandler.Object)
            {
                BaseAddress = mockBaseUri
            };

            CRMGateway CRMGateway = new CRMGateway(_mockCRMTokenGateway, httpCLient);

            //act
            var result = CRMGateway.GetEntitiesByFetchXMLQuery("", "");

            //assert
            Assert.NotNull(result);
        }