示例#1
0
        public async Task ApplyAsync_UpdatesCandidateSet_IfLoaderReturnsAsynchronously()
        {
            // Arrange
            var compiled = new CompiledPageActionDescriptor();

            compiled.Endpoint = CreateEndpoint(new PageActionDescriptor());

            var tcs          = new TaskCompletionSource <int>();
            var candidateSet = CreateCandidateSet(compiled);

            var loadTask = Task.Run(async() =>
            {
                await tcs.Task;
                return(compiled);
            });
            var loader = Mock.Of <PageLoader>(p => p.LoadAsync(It.IsAny <PageActionDescriptor>(), It.IsAny <EndpointMetadataCollection>()) == loadTask);
            var policy = new PageLoaderMatcherPolicy(loader);

            // Act
            var applyTask = policy.ApplyAsync(new DefaultHttpContext(), candidateSet);

            tcs.SetResult(0);
            await applyTask;

            // Assert
            Assert.Same(compiled.Endpoint, candidateSet[0].Endpoint);
        }
示例#2
0
        public async Task ApplyAsync_UpdatesCandidateSet()
        {
            // Arrange
            var compiled = new CompiledPageActionDescriptor();

            compiled.Endpoint = CreateEndpoint(new PageActionDescriptor());

            var candidateSet = CreateCandidateSet(compiled);

            var loader = Mock.Of <PageLoader>(p => p.LoadAsync(It.IsAny <PageActionDescriptor>(), It.IsAny <EndpointMetadataCollection>()) == Task.FromResult(compiled));
            var policy = new PageLoaderMatcherPolicy(loader);

            // Act
            await policy.ApplyAsync(new DefaultHttpContext(), candidateSet);

            // Assert
            Assert.Same(compiled.Endpoint, candidateSet[0].Endpoint);
        }