Esempio n. 1
0
    public async Task Virtualize_DispatchesExceptionsFromItemsProviderThroughRenderer()
    {
        Virtualize <int> renderedVirtualize = null;

        var rootComponent = new VirtualizeTestHostcomponent
        {
            InnerContent = BuildVirtualize(10f, AlwaysThrowsItemsProvider <int>, null, virtualize => renderedVirtualize = virtualize)
        };

        var serviceProvider = new ServiceCollection()
                              .AddTransient((sp) => Mock.Of <IJSRuntime>())
                              .BuildServiceProvider();

        var testRenderer = new TestRenderer(serviceProvider);
        var componentId  = testRenderer.AssignRootComponentId(rootComponent);

        // Render to populate the component reference.
        await testRenderer.RenderRootComponentAsync(componentId);

        Assert.NotNull(renderedVirtualize);

        // Simulate a JS spacer callback.
        ((IVirtualizeJsCallbacks)renderedVirtualize).OnAfterSpacerVisible(10f, 50f, 100f);

        // Validate that the exception is dispatched through the renderer.
        var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await testRenderer.RenderRootComponentAsync(componentId));

        Assert.Equal("Thrown from items provider.", ex.Message);
    }
Esempio n. 2
0
    public async Task Virtualize_ThrowsWhenGivenMultipleItemSources()
    {
        var rootComponent = new VirtualizeTestHostcomponent
        {
            InnerContent = BuildVirtualize(10f, EmptyItemsProvider <int>, new List <int>())
        };

        var serviceProvider = new ServiceCollection()
                              .AddTransient((sp) => Mock.Of <IJSRuntime>())
                              .BuildServiceProvider();

        var testRenderer = new TestRenderer(serviceProvider);
        var componentId  = testRenderer.AssignRootComponentId(rootComponent);

        var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await testRenderer.RenderRootComponentAsync(componentId));

        Assert.Contains("can only accept one item source from its parameters", ex.Message);
    }
Esempio n. 3
0
    public async Task Virtualize_ThrowsWhenGivenNoItemSources()
    {
        var rootComponent = new VirtualizeTestHostcomponent
        {
            InnerContent = BuildVirtualize <int>(10f, null, null)
        };

        var serviceProvider = new ServiceCollection()
                              .AddTransient((sp) => Mock.Of <IJSRuntime>())
                              .BuildServiceProvider();

        var testRenderer = new TestRenderer(serviceProvider);
        var componentId  = testRenderer.AssignRootComponentId(rootComponent);

        var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await testRenderer.RenderRootComponentAsync(componentId));

        Assert.Contains("parameters to be specified and non-null", ex.Message);
    }
Esempio n. 4
0
    public async Task Virtualize_ThrowsWhenGivenNonPositiveItemSize()
    {
        var rootComponent = new VirtualizeTestHostcomponent
        {
            InnerContent = BuildVirtualize(0f, EmptyItemsProvider <int>, null)
        };

        var serviceProvider = new ServiceCollection()
                              .AddTransient((sp) => Mock.Of <IJSRuntime>())
                              .BuildServiceProvider();

        var testRenderer = new TestRenderer(serviceProvider);
        var componentId  = testRenderer.AssignRootComponentId(rootComponent);

        var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await testRenderer.RenderRootComponentAsync(componentId));

        Assert.Contains("requires a positive value for parameter", ex.Message);
    }