Ejemplo n.º 1
0
        public void TestGetAsync_ReturnsCorrectResults()
        {
            var expectedInterviewers = new[]
            {
                new SurveyInterviewerAssignmentModel {
                    InterviewerId = "id1", IsActive = true, IsAssigned = true
                },
                new SurveyInterviewerAssignmentModel {
                    InterviewerId = "id2", IsActive = false, IsAssigned = false
                }
            };
            const string surveyId = "surveyId";
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.GetAsync(It.Is <string>(url => url.EndsWith("Surveys/" + surveyId + "/Interviewers/"))))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedInterviewers))));
            var target = new NfieldSurveyInterviewersService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            var actual = target.GetAsync(surveyId).Result.ToArray();

            // Assert
            Assert.Equal(expectedInterviewers.Length, actual.Length);
            Assert.Equal(expectedInterviewers[0].InterviewerId, actual[0].InterviewerId);
            Assert.Equal(expectedInterviewers[0].IsActive, actual[0].IsActive);
            Assert.Equal(expectedInterviewers[0].IsAssigned, actual[0].IsAssigned);
            Assert.Equal(expectedInterviewers[1].InterviewerId, actual[1].InterviewerId);
            Assert.Equal(expectedInterviewers[1].IsActive, actual[1].IsActive);
            Assert.Equal(expectedInterviewers[1].IsAssigned, actual[1].IsAssigned);
        }
Ejemplo n.º 2
0
        public void TestAddAsync_InterviewerIdIsNull_Throws()
        {
            var target = new NfieldSurveyInterviewersService();

            Assert.Throws <ArgumentNullException>(
                () => UnwrapAggregateException(target.AddAsync("surveyId", null)));
        }
Ejemplo n.º 3
0
        public void TestAddAsync_ValidSurveyResponseCode_CallsCorrectUrl()
        {
            // Arrange
            const string surveyId               = "surveyId";
            const string interviewerId          = "interviewerId";
            var          mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var          mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.PostAsJsonAsync(It.IsAny <string>(), It.IsAny <SurveyInterviewerAddModel>()))
            .Returns(CreateTask(HttpStatusCode.OK));
            var target = new NfieldSurveyInterviewersService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

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

            // Assert
            mockedHttpClient.Verify(hc =>
                                    hc.PostAsJsonAsync(
                                        It.Is <string>(url => url.EndsWith("Surveys/" + surveyId + "/Interviewers/")),
                                        It.Is <SurveyInterviewerAddModel>(model => model.InterviewerId == interviewerId)),
                                    Times.Once());
        }