Beispiel #1
0
    public async Task ApplyAsync_ReadsLoaderFromRequestServices()
    {
        // Arrange
        var compiled = new CompiledPageActionDescriptor();

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

        var candidateSet = CreateCandidateSet(compiled);
        var loader       = new Mock <PageLoader>();

        loader.Setup(l => l.LoadAsync(It.IsAny <PageActionDescriptor>(), It.IsAny <EndpointMetadataCollection>()))
        .Returns(Task.FromResult(compiled))
        .Verifiable();
        var policy      = new PageLoaderMatcherPolicy();
        var httpContext = new DefaultHttpContext
        {
            RequestServices = new ServiceCollection().AddSingleton(loader.Object).BuildServiceProvider(),
        };

        // Act
        await policy.ApplyAsync(httpContext, candidateSet);

        // Assert
        Assert.Same(compiled.Endpoint, candidateSet[0].Endpoint);
        loader.Verify();
    }
Beispiel #2
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);
    }
Beispiel #3
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);
    }