public void TestQueryOfficesOfInterviewerAsync_ServerReturnsQuery_ReturnsListWithFieldworkOffices() { const string interviewerId = "interviewerId"; var expectedFieldworkOffices = new[] { "Amsterdam", "Barcelona", "Headquarters" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync( new Uri(ServiceAddress, $"interviewers/{interviewerId}/Offices")) ) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedFieldworkOffices)))); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualFieldworkOffices = target.QueryOfficesOfInterviewerAsync(interviewerId).Result; var fieldworkOffices = actualFieldworkOffices as string[] ?? actualFieldworkOffices.ToArray(); Assert.Equal(expectedFieldworkOffices[0], fieldworkOffices[0]); Assert.Equal(expectedFieldworkOffices[1], fieldworkOffices[1]); Assert.Equal(expectedFieldworkOffices[2], fieldworkOffices[2]); Assert.Equal(3, fieldworkOffices.Count()); }
public void TestRemoveInterviewerFromFieldworkOfficesAsync_WhenExecuted_CallsClientPostAsJsonAsyncWithCorrectArgs() { const string interviewerId = "interviewerId"; const string fieldworkOfficeId = "Barcelona"; var expectedUrl = $"interviewers/{interviewerId}/Offices/{fieldworkOfficeId}"; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(It.IsAny <Uri>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.RemoveInterviewerFromFieldworkOfficesAsync(interviewerId, fieldworkOfficeId).Wait(); mockedHttpClient.Verify( h => h.DeleteAsync(new Uri(ServiceAddress, expectedUrl)), Times.Once()); }
public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithInterviewers() { var expectedInterviewers = new Interviewer[] { new Interviewer { InterviewerId = "TestInterviewer" }, new Interviewer { InterviewerId = "AnotherTestInterviewer" } }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "interviewers/"))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedInterviewers)))); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualInterviewers = target.QueryAsync().Result; Assert.Equal(expectedInterviewers[0].InterviewerId, actualInterviewers.ToArray()[0].InterviewerId); Assert.Equal(expectedInterviewers[1].InterviewerId, actualInterviewers.ToArray()[1].InterviewerId); Assert.Equal(2, actualInterviewers.Count()); }
public void TestAddInterviewerToFieldworkOfficesAsync_WhenExecuted_CallsClientPostAsJsonAsyncWithCorrectArgs() { const string interviewerId = "interviewerId"; const string fieldworkOfficeId = "Barcelona"; var expectedUrl = string.Format(CultureInfo.InvariantCulture, "{0}interviewers/{1}/Offices", ServiceAddress, interviewerId); var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PostAsJsonAsync(It.IsAny <string>(), It.IsAny <InterviewerFieldworkOfficeModel>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.AddInterviewerToFieldworkOfficesAsync(interviewerId, fieldworkOfficeId); mockedHttpClient.Verify( h => h.PostAsJsonAsync(expectedUrl, It.Is <InterviewerFieldworkOfficeModel>(f => f.OfficeId == fieldworkOfficeId)), Times.Once()); }
public void TestRemoveAsync_ServerRemovedInterviewer_DoesNotThrow() { const string InterviewerId = "Interviewer X"; var interviewer = new Interviewer { InterviewerId = InterviewerId }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(ServiceAddress + "interviewers/" + InterviewerId)) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); Assert.DoesNotThrow(() => target.RemoveAsync(interviewer).Wait()); }
public void TestAddAsync_ServerAcceptsInterviewer_ReturnsInterviewer() { var interviewer = new Interviewer { UserName = "******" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var content = new StringContent(JsonConvert.SerializeObject(interviewer)); mockedHttpClient .Setup(client => client.PostAsJsonAsync(new Uri(ServiceAddress, "interviewers/"), interviewer)) .Returns(CreateTask(HttpStatusCode.OK, content)); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.AddAsync(interviewer).Result; Assert.Equal(interviewer.UserName, actual.UserName); }
public void TestChangePasswordAsync_ServerChangesPassword_ReturnsInterviewer() { const string Password = "******"; const string InterviewerId = "Interviewer X"; var interviewer = new Interviewer { InterviewerId = InterviewerId }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PutAsJsonAsync(new Uri(ServiceAddress, "interviewers/" + InterviewerId), It.IsAny <object>())) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(interviewer)))); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.ChangePasswordAsync(interviewer, Password).Result; Assert.Equal(interviewer.InterviewerId, actual.InterviewerId); }
public void TestUpdateAsync_InterviewerExists_ReturnsInterviewer() { const string InterviewerId = "Interviewer X"; var interviewer = new Interviewer { InterviewerId = InterviewerId, FirstName = "XXX" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PatchAsJsonAsync(new Uri(ServiceAddress, "interviewers/" + InterviewerId), It.IsAny <UpdateInterviewer>())) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(interviewer)))); var target = new NfieldInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.UpdateAsync(interviewer).Result; Assert.Equal(interviewer.FirstName, actual.FirstName); }