In RazorCompilerTest, don't use BuildRenderTree directly (because it will soon be removed)
This commit is contained in:
parent
70a3ee3d98
commit
e061b98f9d
|
|
@ -88,15 +88,12 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SupportsPlainText()
|
public void SupportsPlainText()
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
var treeBuilder = new RenderTreeBuilder(new TestRenderer());
|
|
||||||
|
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
var component = CompileToComponent("Some plain text");
|
var component = CompileToComponent("Some plain text");
|
||||||
component.BuildRenderTree(treeBuilder);
|
var frames = GetRenderTree(component);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(treeBuilder.GetFrames(),
|
Assert.Collection(frames,
|
||||||
frame => AssertFrame.Text(frame, "Some plain text", 0));
|
frame => AssertFrame.Text(frame, "Some plain text", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -303,17 +300,14 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SupportsUsingStatements()
|
public void SupportsUsingStatements()
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
var treeBuilder = new RenderTreeBuilder(new TestRenderer());
|
|
||||||
|
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
var component = CompileToComponent(
|
var component = CompileToComponent(
|
||||||
@"@using System.Collections.Generic
|
@"@using System.Collections.Generic
|
||||||
@(typeof(List<string>).FullName)");
|
@(typeof(List<string>).FullName)");
|
||||||
component.BuildRenderTree(treeBuilder);
|
var frames = GetRenderTree(component);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(treeBuilder.GetFrames(),
|
Assert.Collection(frames,
|
||||||
frame => AssertFrame.Whitespace(frame, 0),
|
frame => AssertFrame.Whitespace(frame, 0),
|
||||||
frame => AssertFrame.Text(frame, typeof(List<string>).FullName, 1));
|
frame => AssertFrame.Text(frame, typeof(List<string>).FullName, 1));
|
||||||
}
|
}
|
||||||
|
|
@ -352,24 +346,22 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SupportsChildComponentsViaTemporarySyntax()
|
public void SupportsChildComponentsViaTemporarySyntax()
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
var treeBuilder = new RenderTreeBuilder(new TestRenderer());
|
|
||||||
|
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
var testComponentTypeName = typeof(TestComponent).FullName.Replace('+', '.');
|
var testComponentTypeName = typeof(TestComponent).FullName.Replace('+', '.');
|
||||||
var component = CompileToComponent($"<c:{testComponentTypeName} />");
|
var component = CompileToComponent($"<c:{testComponentTypeName} />");
|
||||||
component.BuildRenderTree(treeBuilder);
|
var frames = GetRenderTree(component);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Collection(treeBuilder.GetFrames(),
|
Assert.Collection(frames,
|
||||||
frame => AssertFrame.Component<TestComponent>(frame, 0));
|
frame => AssertFrame.Component<TestComponent>(frame, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayRange<RenderTreeFrame> GetRenderTree(IComponent component)
|
private static RenderTreeFrame[] GetRenderTree(IComponent component)
|
||||||
{
|
{
|
||||||
var treeBuilder = new RenderTreeBuilder(new TestRenderer());
|
var renderer = new TestRenderer();
|
||||||
component.BuildRenderTree(treeBuilder);
|
renderer.AttachComponent(component);
|
||||||
return treeBuilder.GetFrames();
|
component.SetParameters(ParameterCollection.Empty);
|
||||||
|
return renderer.LatestBatchReferenceFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IComponent CompileToComponent(string cshtmlSource)
|
private static IComponent CompileToComponent(string cshtmlSource)
|
||||||
|
|
@ -472,8 +464,15 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
|
|
||||||
private class TestRenderer : Renderer
|
private class TestRenderer : Renderer
|
||||||
{
|
{
|
||||||
|
public RenderTreeFrame[] LatestBatchReferenceFrames { get; private set; }
|
||||||
|
|
||||||
|
public void AttachComponent(IComponent component)
|
||||||
|
=> AssignComponentId(component);
|
||||||
|
|
||||||
protected override void UpdateDisplay(RenderBatch renderBatch)
|
protected override void UpdateDisplay(RenderBatch renderBatch)
|
||||||
=> throw new NotImplementedException();
|
{
|
||||||
|
LatestBatchReferenceFrames = renderBatch.ReferenceFrames.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestComponent : IComponent
|
public class TestComponent : IComponent
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue