Exemplo n.º 1
0
        public async Task TestRestSample()
        {
            // create mocks
            var logger        = new Mock <ILogger <QueryService> >();
            var tfsClient     = new Mock <ITfsClient>();
            var witHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            // inject behaviors in mocks
            witHttpClient.Setup(x => x.GetQueriesAsync(It.IsAny <string>(), null, It.IsAny <int?>(), null, It.IsAny <object>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetNominalTfsQueryHierarchy());
            witHttpClient.Setup(x => x.QueryByIdAsync(It.IsAny <Guid>(), null, It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetNominalTfsQueryResult());
            witHttpClient.Setup(x => x.GetWorkItemsAsync(It.IsAny <IEnumerable <int> >(), null, It.IsAny <DateTime?>(), It.IsAny <WorkItemExpand?>(), null, It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetNominalWorkItemList());
            tfsClient.Setup(x => x.WorkItemTrackingHttpClient)
            .Returns(() => witHttpClient.Object);

            // do the actual test
            var service = new QueryService(logger.Object, tfsClient.Object);
            var output  = await service.DoRestSample("dummyProject");

            // verify the test execution
            Assert.True(output != null);
            Assert.Equal(5, output.Count);
        }