Ejemplo n.º 1
0
        public async Task QueryDataAsync_CreatesResultsCorrectly(bool isDone, int count)
        {
            //arrange
            int iteration = 0;

            _messageServiceSub.BuildQueryMessage(Arg.Any <string>(), Arg.Any <bool>()).Returns(_ =>
            {
                return(new HttpRequestMessage(HttpMethod.Get, "https://someuri"));
            });
            _messageServiceSub.ProcessResponseAsync <QueryResultModel <TestSfObject> >(Arg.Any <HttpResponseMessage>(), Arg.Any <CancellationToken>()).Returns(x =>
            {
                if (isDone)
                {
                    return(new QueryResultModel <TestSfObject>(2, true, new TestSfObject[] { new TestSfObject(), new TestSfObject() }, null));
                }
                else
                {
                    if (iteration == 0)
                    {
                        iteration++;
                        return(new QueryResultModel <TestSfObject>(4, false, new TestSfObject[] { new TestSfObject(), new TestSfObject() }, null));
                    }
                    else
                    {
                        return(new QueryResultModel <TestSfObject>(2, true, new TestSfObject[] { new TestSfObject(), new TestSfObject() }, null));
                    }
                }
            });
            SetupClient(string.Empty, HttpStatusCode.OK);

            //act
            var result = await _testedService.QueryDataAsync <TestSfObject>("");

            //assert
            Assert.AreEqual(count, result.Length);
        }