public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithCatiInterviewers() { var expectedCatiInterviewers = new CatiInterviewer[] { new CatiInterviewer { InterviewerId = "TestInterviewer" }, new CatiInterviewer { InterviewerId = "AnotherTestInterviewer" } }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "catiinterviewers/"))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedCatiInterviewers)))); var target = new NfieldCatiInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualInterviewers = target.QueryAsync().Result; Assert.Equal(expectedCatiInterviewers[0].InterviewerId, actualInterviewers.ToArray()[0].InterviewerId); Assert.Equal(expectedCatiInterviewers[1].InterviewerId, actualInterviewers.ToArray()[1].InterviewerId); Assert.Equal(2, actualInterviewers.Count()); }
public void TestRemoveAsync_ServerRemovedCatiInterviewer_DoesNotThrow() { const string InterviewerId = "Interviewer X"; var catiInterviewer = new CatiInterviewer { InterviewerId = InterviewerId }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(new Uri(ServiceAddress, "catiinterviewers/" + InterviewerId))) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldCatiInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); // assert: no throw target.RemoveAsync(catiInterviewer).Wait(); }
public void TestAddAsync_ServerAcceptsCatiInterviewer_ReturnsCatiInterviewer() { var catiInterviewer = new CatiInterviewer { UserName = "******" }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var content = new StringContent(JsonConvert.SerializeObject(catiInterviewer)); mockedHttpClient .Setup(client => client.PostAsJsonAsync(new Uri(ServiceAddress, "catiinterviewers/"), catiInterviewer)) .Returns(CreateTask(HttpStatusCode.OK, content)); var target = new NfieldCatiInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.AddAsync(catiInterviewer).Result; Assert.Equal(catiInterviewer.UserName, actual.UserName); }
public void TestChangePasswordAsync_ServerChangesPassword_ReturnsCatiInterviewer() { const string Password = "******"; const string InterviewerId = "Interviewer X"; var catiInterviewer = new CatiInterviewer { InterviewerId = InterviewerId }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PutAsJsonAsync(new Uri(ServiceAddress, "catiinterviewers/" + InterviewerId), It.IsAny <object>())) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(catiInterviewer)))); var target = new NfieldCatiInterviewersService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.ChangePasswordAsync(catiInterviewer, Password).Result; Assert.Equal(catiInterviewer.InterviewerId, actual.InterviewerId); }
public void TestRemoveAsync_CatiInterviewerIsNull_ThrowsArgumentNullException() { var target = new NfieldCatiInterviewersService(); Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.RemoveAsync(null))); }
public void TestChangePasswordAsync_CatiInterviewerIsNull_ThrowsArgumentNullException() { var target = new NfieldCatiInterviewersService(); Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.ChangePasswordAsync(null, string.Empty))); }