Example #1
0
        public void TestUpdateAsync_ValidSurveyResponseCode_ReturnsModifiedResponseCode()
        {
            // Arrange
            const string surveyId = "surveyId";
            const int    code     = 10;
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            var responseCodeToUpdate = new SurveyResponseCode
            {
                ResponseCode     = code,
                Description      = "Description",
                IsDefinite       = true,
                AllowAppointment = false
            };

            mockedHttpClient.Setup(client => client.PatchAsJsonAsync(It.IsAny <string>(), It.IsAny <UpdateSurveyResponseCode>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(responseCodeToUpdate))));
            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            var result = target.UpdateAsync(surveyId, responseCodeToUpdate).Result;

            // Assert
            Assert.Equal(responseCodeToUpdate.ResponseCode, result.ResponseCode);
            Assert.Equal(responseCodeToUpdate.Description, result.Description);
            Assert.Equal(responseCodeToUpdate.IsDefinite, result.IsDefinite);
            Assert.Equal(responseCodeToUpdate.AllowAppointment, result.AllowAppointment);
            Assert.Equal(responseCodeToUpdate.IsSelectable, result.IsSelectable);
        }
Example #2
0
        public void TestUpdateAsync_ValidSurveyResponseCode_CallsCorrectUrl()
        {
            // Arrange
            const string surveyId = "surveyId";
            const int    code     = 10;
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            var responseCodeToUpdate = new SurveyResponseCode
            {
                ResponseCode     = code,
                Description      = "Description",
                IsDefinite       = true,
                AllowAppointment = false
            };

            mockedHttpClient.Setup(client => client.PatchAsJsonAsync(It.IsAny <string>(), It.IsAny <UpdateSurveyResponseCode>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(new SurveyResponseCode()))));
            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            target.UpdateAsync(surveyId, responseCodeToUpdate).Wait();

            // Assert
            mockedHttpClient.Verify(hc =>
                                    hc.PatchAsJsonAsync(
                                        It.Is <string>(
                                            url => url.EndsWith(string.Format("Surveys/{0}/ResponseCodes/{1}", surveyId, code))),
                                        It.IsAny <UpdateSurveyResponseCode>()),
                                    Times.Once());
        }
        public void TestAddAsync_ValidSurveyResponseCode_CallsCorrectUrl()
        {
            // Arrange
            const string surveyId = "surveyId";
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            var responseCodeToAdd = new SurveyResponseCode
            {
                ResponseCode     = 15,
                Description      = "Description",
                IsDefinite       = true,
                AllowAppointment = false
            };

            mockedHttpClient.Setup(client => client.PostAsJsonAsync(It.IsAny <Uri>(), It.IsAny <SurveyResponseCode>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(new SurveyResponseCode()))));
            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            target.AddAsync(surveyId, responseCodeToAdd).Wait();

            // Assert
            mockedHttpClient.Verify(hc =>
                                    hc.PostAsJsonAsync(It.Is <Uri>(url => url.AbsolutePath.EndsWith("Surveys/" + surveyId + "/ResponseCodes/")), responseCodeToAdd),
                                    Times.Once());
        }
Example #4
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());
        }
Example #5
0
        public void TestRemoveAsync_ValidSurveyResponseCode_CallsCorrectUrl()
        {
            // Arrange
            const string surveyId = "surveyId";
            const int    code     = 10;
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.DeleteAsync(It.IsAny <string>()))
            .Returns(CreateTask(HttpStatusCode.OK));
            var target = new NfieldSurveyResponseCodesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

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

            // Assert
            mockedHttpClient.Verify(hc =>
                                    hc.DeleteAsync(It.Is <string>(
                                                       url => url.EndsWith(string.Format("Surveys/{0}/ResponseCodes/{1}", surveyId, code)))),
                                    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());
        }