예제 #1
0
        public void TestQueryAsync_ValidSurveyId_CAllsCorrectUrl()
        {
            // Arrange
            const string surveyId = "surveyId";
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);
            mockedHttpClient.Setup(client => client.GetAsync(It.IsAny <string>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(new List <SurveyResponseCode>()))));

            // Act
            target.QueryAsync(surveyId).Wait();

            // Assert
            mockedHttpClient.Verify(
                hc => hc.GetAsync(It.Is <string>(url => url.EndsWith("Surveys/" + surveyId + "/ResponseCodes/"))), Times.Once());
        }
        public void TestQueryAsyncBasedOnCode_ValidSurveyId_CAllsCorrectUrl()
        {
            // Arrange
            const string surveyId = "surveyId";
            const int    code     = 20;
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);
            mockedHttpClient.Setup(client => client.GetAsync(It.IsAny <Uri>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(new SurveyResponseCode()))));

            // Act
            target.QueryAsync(surveyId, code).Wait();

            // Assert
            mockedHttpClient.Verify(hc =>
                                    hc.GetAsync(It.Is <Uri>(url =>
                                                            url.AbsolutePath.EndsWith($"Surveys/{surveyId}/ResponseCodes/{code}"))),
                                    Times.Once());
        }
예제 #3
0
        public void TestQueryAsyncBasedOnCode_SurveyIdIsEmptyString_Throws()
        {
            var target = new NfieldSurveyResponseCodesService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.QueryAsync(string.Empty, 20)));
        }
예제 #4
0
        public void TestQueryAsync_SurveyIdIsNull_Throws()
        {
            var target = new NfieldSurveyResponseCodesService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.QueryAsync(null)));
        }