예제 #1
0
        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());
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public void TestRemoveAsync_CatiInterviewerIsNull_ThrowsArgumentNullException()
        {
            var target = new NfieldCatiInterviewersService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.RemoveAsync(null)));
        }
예제 #6
0
        public void TestChangePasswordAsync_CatiInterviewerIsNull_ThrowsArgumentNullException()
        {
            var target = new NfieldCatiInterviewersService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.ChangePasswordAsync(null, string.Empty)));
        }