InitializeNfieldConnection() public method

INfieldConnectionClientObject.InitializeNfieldConnection
public InitializeNfieldConnection ( INfieldConnectionClient connection ) : void
connection INfieldConnectionClient
return void
        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<string>(), 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<string>(url => url.EndsWith("Surveys/" + surveyId + "/ResponseCodes/")), responseCodeToAdd),
                    Times.Once());
        }
        public void TestAddAsync_ValidSurveyResponseCode_ReturnsAddedResponseCode()
        {
            // 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<string>(), It.IsAny<SurveyResponseCode>()))
                .Returns(CreateTask(HttpStatusCode.OK,
                    new StringContent(JsonConvert.SerializeObject(responseCodeToAdd))));
            var target = new NfieldSurveyResponseCodesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            var result = target.AddAsync(surveyId, responseCodeToAdd).Result;

            // Assert
            Assert.Equal(responseCodeToAdd.ResponseCode, result.ResponseCode);
            Assert.Equal(responseCodeToAdd.Description, result.Description);
            Assert.Equal(responseCodeToAdd.IsDefinite, result.IsDefinite);
            Assert.Equal(responseCodeToAdd.AllowAppointment, result.AllowAppointment);
            Assert.Equal(responseCodeToAdd.IsSelectable, result.IsSelectable);
        }
        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 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());
        }