InitializeNfieldConnection() 공개 메소드

public InitializeNfieldConnection ( INfieldConnectionClient connection ) : void
connection INfieldConnectionClient
리턴 void
        public void TestAddAsync_ServerAcceptsAddress_ReturnsAddress()
        {
            var address = new Address { Details = "Language X" };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(address));
            mockedHttpClient
                .Setup(client => client.PostAsJsonAsync(ServiceAddress + "Surveys/" + SurveyId +
                    "/SamplingPoints/" + SamplingPointId + "/Addresses", address))
                .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldAddressesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.AddAsync(SurveyId, SamplingPointId, address).Result;

            Assert.Equal(address.Details, actual.Details);
        }
        public void TestDeleteAsync_ServerAcceptsDelete_ReturnsNoError()
        {
            const string surveyId = "SurveyId";
            const string samplingPointId = "SamplingPointId";
            const string addressId = "AddressId";

            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.DeleteAsync(It.IsAny<string>()))
                                    .Returns(CreateTask(HttpStatusCode.NoContent));

            var target = new NfieldAddressesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            target.DeleteAsync(surveyId, samplingPointId, addressId).Wait();
        }
        public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithAddresses()
        {
            var expectedAddresses = new Address[]
            { new Address{AddressId = "id1", Details = "X"},
              new Address{AddressId = "id2", Details = "Y"}
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + SurveyId +
                    "/SamplingPoints/" + SamplingPointId + "/Addresses"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedAddresses))));

            var target = new NfieldAddressesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualAddresses = target.QueryAsync(SurveyId, SamplingPointId).Result;
            Assert.Equal(expectedAddresses[0].AddressId, actualAddresses.ToArray()[0].AddressId);
            Assert.Equal(expectedAddresses[1].AddressId, actualAddresses.ToArray()[1].AddressId);
            Assert.Equal(2, actualAddresses.Count());
        }
        public void TestGetCountAsync_ServerReturnsCount_ReturnsNumberOfAddresses()
        {
            var uri = $"{ServiceAddress}Surveys/{SurveyId}/SamplingPoints/{SamplingPointId}/Addresses/Count";
            var expectedCount = 8;

            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(uri))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(expectedCount.ToString())));

            var target = new NfieldAddressesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualCount = target.GetCountAsync(SurveyId, SamplingPointId).Result;
            Assert.Equal(expectedCount, actualCount);
        }