Пример #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());
        }
        /// <summary>
        /// See <see cref="INfieldCatiInterviewersService.AddAsync"/>
        /// </summary>
        public async Task <CatiInterviewer> AddAsync(CatiInterviewer catiInterviewer)
        {
            using (var response = await Client.PostAsJsonAsync(CatiInterviewersApi, catiInterviewer))
            {
                var result = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <CatiInterviewer>(result));
            }
        }
        /// <summary>
        /// See <see cref="INfieldCatiInterviewersService.RemoveAsync"/>
        /// </summary>
        public async Task RemoveAsync(CatiInterviewer catiInterviewer)
        {
            if (catiInterviewer == null)
            {
                throw new ArgumentNullException("catiInterviewer");
            }

            using (await Client.DeleteAsync(new Uri(CatiInterviewersApi, catiInterviewer.InterviewerId)))
            {
            }
        }
        /// <summary>
        /// See <see cref="INfieldCatiInterviewersService.ChangePasswordAsync"/>
        /// </summary>
        public async Task <CatiInterviewer> ChangePasswordAsync(CatiInterviewer catiInterviewer, string password)
        {
            if (catiInterviewer == null)
            {
                throw new ArgumentNullException("catiInterviewer");
            }
            using (var response = await Client.PutAsJsonAsync(new Uri(CatiInterviewersApi, catiInterviewer.InterviewerId), (object)new { Password = password }))
            {
                var result = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <CatiInterviewer>(result));
            }
        }
Пример #5
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();
        }
Пример #6
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);
        }
Пример #7
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);
        }