Skip to content

Commit 532c22c

Browse files
committed
Started on unit tests.
1 parent 02a03f4 commit 532c22c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Components.Rendering;
8+
using Microsoft.AspNetCore.Components.Test.Helpers;
9+
using Microsoft.AspNetCore.Components.Web;
10+
using Xunit;
11+
412
namespace Microsoft.AspNetCore.Components.Virtualization
513
{
614
public class VirtualizeTest
715
{
816
// TODO: Functional tests.
17+
[Fact]
18+
public void Virtualize_ThrowsWhenGivenNonPositiveItemSize()
19+
{
20+
var rootComponent = new VirtualizeTestHostcomponent
21+
{
22+
InnerContent = BuildVirtualize(
23+
i => builder => { },
24+
null,
25+
context => builder => { },
26+
0f,
27+
null,
28+
new List<int>())
29+
};
30+
31+
var testRenderer = new TestRenderer();
32+
var componentId = testRenderer.AssignRootComponentId(rootComponent);
33+
34+
var ex = Assert.Throws<InvalidOperationException>(() => testRenderer.RenderRootComponent(componentId));
35+
}
36+
37+
public RenderFragment BuildVirtualize<TItem>(
38+
RenderFragment<TItem> childContent,
39+
RenderFragment<TItem> item,
40+
RenderFragment<PlaceholderContext> placeholder,
41+
float itemSize,
42+
ItemsProviderDelegate<TItem> itemsProvider,
43+
ICollection<TItem> items)
44+
=> builder =>
45+
{
46+
builder.OpenComponent<Virtualize<TItem>>(0);
47+
builder.AddAttribute(1, "ChildContent", childContent);
48+
builder.AddAttribute(2, "Item", item);
49+
builder.AddAttribute(3, "Placeholder", placeholder);
50+
builder.AddAttribute(4, "ItemSize", itemSize);
51+
builder.AddAttribute(5, "ItemsProvider", itemsProvider);
52+
builder.AddAttribute(6, "Items", items);
53+
builder.CloseComponent();
54+
};
55+
56+
private class VirtualizeTestHostcomponent : AutoRenderComponent
57+
{
58+
public RenderFragment InnerContent { get; set; }
59+
60+
protected override void BuildRenderTree(RenderTreeBuilder builder)
61+
{
62+
builder.OpenElement(0, "div");
63+
builder.AddAttribute(1, "style", "overflow: auto; height: 800px;");
64+
builder.AddAttribute(2, "ChildContent", InnerContent);
65+
builder.CloseElement();
66+
}
67+
}
968
}
1069
}

0 commit comments

Comments
 (0)