Beispiel #1
0
        public async Task ReadChildrenWithPagingTest(ICrudManyToOne <Person, Guid> restClient, string resourceName)
        {
            var parentId     = Guid.NewGuid();
            var expectedUri  = $"{ResourcePath}/Persons/{parentId}/{resourceName}?offset=0";
            var pageEnvelope = new PageEnvelope <Person>(0, PageInfo.DefaultLimit, null, new[] { _person });

            HttpClientMock.Setup(client => client.SendAsync(
                                     It.Is <HttpRequestMessage>(request => request.RequestUri.AbsoluteUri == expectedUri && request.Method == HttpMethod.Get),
                                     CancellationToken.None))
            .ReturnsAsync((HttpRequestMessage r, CancellationToken c) => CreateResponseMessage(r, pageEnvelope))
            .Verifiable();
            var readPage = await restClient.ReadChildrenWithPagingAsync(parentId, 0);

            Assert.IsNotNull(readPage?.Data);
            Assert.AreEqual(1, readPage.Data.Count());
            Assert.AreEqual(_person, readPage.Data.FirstOrDefault());
            HttpClientMock.Verify();
        }
        public async Task ReadChildrenWithPagingTest()
        {
            var parentId     = Guid.NewGuid();
            var expectedUri  = $"{ResourcePath}/Persons/{parentId}/Addresses?offset=0";
            var pageEnvelope = new PageEnvelope <Address>(0, PageInfo.DefaultLimit, null, new[] { _address });

            HttpClientMock.Setup(client => client.SendAsync(
                                     It.Is <HttpRequestMessage>(request => IsExpectedRequest(request, expectedUri, HttpMethod.Get)),
                                     CancellationToken.None))
            .ReturnsAsync((HttpRequestMessage r, CancellationToken c) => CreateResponseMessage(r, pageEnvelope))
            .Verifiable();
            var readPage = await _client.ReadChildrenWithPagingAsync(parentId, 0);

            Assert.IsNotNull(readPage?.Data);
            Assert.AreEqual(1, readPage.Data.Count());
            Assert.AreEqual(_address, readPage.Data.FirstOrDefault());
            HttpClientMock.Verify();
        }