Beispiel #1
0
        public void TestCountsQueryAsync_ServerReturnsQuery_ReturnsCounts()
        {
            const int expectedDroppedOutCount  = 1;
            const int expectedRejectedCount    = 2;
            const int expectedScreenedOutCount = 3;
            const int expectedSuccessfulCount  = 4;
            var       surveyId       = Guid.NewGuid().ToString();
            var       expectedCounts = new SurveyCounts
            {
                DroppedOutCount  = expectedDroppedOutCount,
                RejectedCount    = expectedRejectedCount,
                ScreenedOutCount = expectedScreenedOutCount,
                SuccessfulCount  = expectedSuccessfulCount
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var url = new Uri(ServiceAddress, $"Surveys/{surveyId}/Counts");

            mockedHttpClient
            .Setup(client => client.GetAsync(url))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedCounts))));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var result = target.CountsQueryAsync(surveyId).Result;

            Assert.Equal(expectedDroppedOutCount, result.DroppedOutCount);
            Assert.Equal(expectedRejectedCount, result.RejectedCount);
            Assert.Equal(expectedScreenedOutCount, result.ScreenedOutCount);
            Assert.Equal(expectedSuccessfulCount, result.SuccessfulCount);
        }