public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithAssignments()
        {
            var expectedAssignments = new[]
            {
                new InterviewerSamplingPointAssignmentModel {
                    Active = false, Assigned = false, FirstName = "fn1", InterviewerId = "id1", LastName = "ln1", UserName = "******"
                },
                new InterviewerSamplingPointAssignmentModel {
                    Active = true, Assigned = true, FirstName = "fn2", InterviewerId = "id2", LastName = "ln2", UserName = "******"
                }
            };

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.GetAsync(It.IsAny <Uri>()))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedAssignments))));

            var target = new NfieldSamplingPointInterviewerAssignmentsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualAssignments = target.QueryAsync(SurveyId, SamplingPointId).Result;

            Assert.Equal(expectedAssignments[0].InterviewerId, actualAssignments.ToArray()[0].InterviewerId);
            Assert.Equal(expectedAssignments[1].InterviewerId, actualAssignments.ToArray()[1].InterviewerId);
            Assert.Equal(2, actualAssignments.Count());
        }
        public void TestUnassignAsync_ServerAcceptsUnassign_ReturnsNoError()
        {
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.DeleteAsync(It.IsAny <Uri>()))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSamplingPointInterviewerAssignmentsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            target.UnassignAsync(SurveyId, SamplingPointId, InterviewerId).Wait();

            mockedHttpClient.Verify(hc =>
                                    hc.DeleteAsync(
                                        It.Is <Uri>(url => url.AbsolutePath.EndsWith("Surveys/" + SurveyId + "/SamplingPoints/" + SamplingPointId + "/Assignments/" + InterviewerId))),
                                    Times.Once());
        }
        public void TestBatchAssignAsync_ServerAcceptsAssign_ReturnsNoError()
        {
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.PostAsJsonAsync(It.IsAny <Uri>(), It.IsAny <SamplingPointInterviewerAssignmentsModel>()))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSamplingPointInterviewerAssignmentsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var model = new SamplingPointInterviewerAssignmentsModel();

            target.AssignAsync(SurveyId, model);

            mockedHttpClient.Verify(hc =>
                                    hc.PostAsJsonAsync(
                                        It.Is <Uri>(url => url.AbsolutePath.EndsWith("Surveys/" + SurveyId + "/SamplingPointsAssignments")),
                                        It.Is <SamplingPointInterviewerAssignmentsModel>(m => m == model)),
                                    Times.Once());
        }