Exemple #1
0
        public void TestPutAsync_Always_CallsCorrectURI()
        {
            var relocation = new SurveyRelocation {
                Reason = "reason X", Url = "url X"
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

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

            var target = new NfieldSurveyRelocationsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            target.UpdateAsync(SurveyId, relocation).Wait();

            mockedHttpClient
            .Verify(
                client =>
                client.PutAsJsonAsync(new Uri(ServiceAddress, "Surveys/" + SurveyId + "/Relocations"), It.IsAny <SurveyRelocation>()),
                Times.Once());
        }
Exemple #2
0
        public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithRelocations()
        {
            var expectedRelocationss = new[]
            { new SurveyRelocation {
                  Reason = "reason X", Url = "url X"
              },
              new SurveyRelocation {
                  Reason = "reason Y", Url = "url Y"
              } };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(new Uri(ServiceAddress, "Surveys/" + SurveyId + "/Relocations")))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedRelocationss))));

            var target = new NfieldSurveyRelocationsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualRelocations = target.QueryAsync(SurveyId).Result.ToArray();;

            Assert.Equal(expectedRelocationss[0].Reason, actualRelocations[0].Reason);
            Assert.Equal(expectedRelocationss[0].Url, actualRelocations[0].Url);
            Assert.Equal(expectedRelocationss[1].Reason, actualRelocations[1].Reason);
            Assert.Equal(expectedRelocationss[1].Url, actualRelocations[1].Url);
            Assert.Equal(2, actualRelocations.Length);
        }
Exemple #3
0
        public void TestUpdateAsync_ServerAcceptsRelocations_ReturnsOk()
        {
            var relocation = new SurveyRelocation {
                Reason = "reason X", Url = "url X"
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(relocation));

            mockedHttpClient
            .Setup(
                client => client.PutAsJsonAsync(new Uri(ServiceAddress, "Surveys/" + SurveyId + "/Relocations"), relocation))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveyRelocationsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // assert: no throw
            target.UpdateAsync(SurveyId, relocation).Wait();
        }
Exemple #4
0
        public void TestUpdateAsync_SurveyIdIsEmpty_Throws()
        {
            var target = new NfieldSurveyRelocationsService();

            Assert.Throws <ArgumentException>(() => UnwrapAggregateException(target.UpdateAsync("", new SurveyRelocation())));
        }
Exemple #5
0
        public void TestQueryAsync_SurveyIdIsNull_Throws()
        {
            var target = new NfieldSurveyRelocationsService();

            Assert.Throws <ArgumentNullException>(() => UnwrapAggregateException(target.QueryAsync(null)));
        }