Reorganise some test helpers in shared locations
This commit is contained in:
parent
96c6d959c0
commit
df825de86d
|
|
@ -18,7 +18,7 @@
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Build\Microsoft.AspNetCore.Blazor.Build.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Build\Microsoft.AspNetCore.Blazor.Build.csproj" />
|
||||||
|
|
||||||
<!-- Shared sources -->
|
<!-- Shared sources -->
|
||||||
<Compile Include="..\shared\AssertFrame.cs" />
|
<Compile Include="..\shared\AssertFrame.cs" Link="Helpers\AssertFrame.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.Layouts;
|
using Microsoft.AspNetCore.Blazor.Layouts;
|
||||||
using Microsoft.AspNetCore.Blazor.Rendering;
|
using Microsoft.AspNetCore.Blazor.Rendering;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
using Microsoft.AspNetCore.Blazor.Test.Shared;
|
using Microsoft.AspNetCore.Blazor.Test.Helpers;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using Microsoft.AspNetCore.Blazor.Components;
|
using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Blazor.Test
|
namespace Microsoft.AspNetCore.Blazor.Test.Helpers
|
||||||
{
|
{
|
||||||
public abstract class AutoRenderComponent : IComponent
|
public abstract class AutoRenderComponent : IComponent
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Blazor.Test
|
||||||
|
{
|
||||||
|
public class CapturedBatch
|
||||||
|
{
|
||||||
|
public IDictionary<int, List<RenderTreeDiff>> DiffsByComponentId { get; }
|
||||||
|
= new Dictionary<int, List<RenderTreeDiff>>();
|
||||||
|
|
||||||
|
public IList<RenderTreeDiff> DiffsInOrder { get; }
|
||||||
|
= new List<RenderTreeDiff>();
|
||||||
|
|
||||||
|
public IList<int> DisposedComponentIDs { get; set; }
|
||||||
|
public RenderTreeFrame[] ReferenceFrames { get; set; }
|
||||||
|
|
||||||
|
internal void AddDiff(RenderTreeDiff diff)
|
||||||
|
{
|
||||||
|
var componentId = diff.ComponentId;
|
||||||
|
if (!DiffsByComponentId.ContainsKey(componentId))
|
||||||
|
{
|
||||||
|
DiffsByComponentId.Add(componentId, new List<RenderTreeDiff>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone the diff, because its underlying storage will get reused in subsequent batches
|
||||||
|
var diffClone = new RenderTreeDiff(
|
||||||
|
diff.ComponentId,
|
||||||
|
new ArraySegment<RenderTreeEdit>(diff.Edits.ToArray()));
|
||||||
|
DiffsByComponentId[componentId].Add(diffClone);
|
||||||
|
DiffsInOrder.Add(diffClone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Blazor.Components;
|
||||||
|
using Microsoft.AspNetCore.Blazor.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Blazor.Test.Helpers
|
||||||
|
{
|
||||||
|
public class TestRenderer : Renderer
|
||||||
|
{
|
||||||
|
public List<CapturedBatch> Batches { get; }
|
||||||
|
= new List<CapturedBatch>();
|
||||||
|
|
||||||
|
public new int AssignComponentId(IComponent component)
|
||||||
|
=> base.AssignComponentId(component);
|
||||||
|
|
||||||
|
public new void DispatchEvent(int componentId, int eventHandlerId, UIEventArgs args)
|
||||||
|
=> base.DispatchEvent(componentId, eventHandlerId, args);
|
||||||
|
|
||||||
|
protected override void UpdateDisplay(RenderBatch renderBatch)
|
||||||
|
{
|
||||||
|
var capturedBatch = new CapturedBatch();
|
||||||
|
Batches.Add(capturedBatch);
|
||||||
|
|
||||||
|
for (var i = 0; i < renderBatch.UpdatedComponents.Count; i++)
|
||||||
|
{
|
||||||
|
ref var renderTreeDiff = ref renderBatch.UpdatedComponents.Array[i];
|
||||||
|
capturedBatch.AddDiff(renderTreeDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone other data, as underlying storage will get reused by later batches
|
||||||
|
capturedBatch.ReferenceFrames = renderBatch.ReferenceFrames.ToArray();
|
||||||
|
capturedBatch.DisposedComponentIDs = renderBatch.DisposedComponentIDs.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
|
||||||
|
|
||||||
<!-- Shared sources -->
|
<!-- Shared sources -->
|
||||||
<Compile Include="..\shared\AssertFrame.cs" />
|
<Compile Include="..\shared\AssertFrame.cs" Link="Helpers\AssertFrame.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using Microsoft.AspNetCore.Blazor.Components;
|
using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.Rendering;
|
using Microsoft.AspNetCore.Blazor.Rendering;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
using Microsoft.AspNetCore.Blazor.Test.Shared;
|
using Microsoft.AspNetCore.Blazor.Test.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using Microsoft.AspNetCore.Blazor.Components;
|
using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.Rendering;
|
using Microsoft.AspNetCore.Blazor.Rendering;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
using Microsoft.AspNetCore.Blazor.Test.Shared;
|
using Microsoft.AspNetCore.Blazor.Test.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@ using System.Linq;
|
||||||
using Microsoft.AspNetCore.Blazor.Components;
|
using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.Rendering;
|
using Microsoft.AspNetCore.Blazor.Rendering;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
using Microsoft.AspNetCore.Blazor.Test.Shared;
|
using Microsoft.AspNetCore.Blazor.Test.Helpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Blazor.Test
|
namespace Microsoft.AspNetCore.Blazor.Test
|
||||||
{
|
{
|
||||||
public partial class RendererTest
|
public class RendererTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanRenderTopLevelComponents()
|
public void CanRenderTopLevelComponents()
|
||||||
|
|
@ -873,62 +873,6 @@ namespace Microsoft.AspNetCore.Blazor.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestRenderer : Renderer
|
|
||||||
{
|
|
||||||
public List<CapturedBatch> Batches { get; }
|
|
||||||
= new List<CapturedBatch>();
|
|
||||||
|
|
||||||
public new int AssignComponentId(IComponent component)
|
|
||||||
=> base.AssignComponentId(component);
|
|
||||||
|
|
||||||
public new void DispatchEvent(int componentId, int eventHandlerId, UIEventArgs args)
|
|
||||||
=> base.DispatchEvent(componentId, eventHandlerId, args);
|
|
||||||
|
|
||||||
protected override void UpdateDisplay(RenderBatch renderBatch)
|
|
||||||
{
|
|
||||||
var capturedBatch = new CapturedBatch();
|
|
||||||
Batches.Add(capturedBatch);
|
|
||||||
|
|
||||||
for (var i = 0; i < renderBatch.UpdatedComponents.Count; i++)
|
|
||||||
{
|
|
||||||
ref var renderTreeDiff = ref renderBatch.UpdatedComponents.Array[i];
|
|
||||||
capturedBatch.AddDiff(renderTreeDiff);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone other data, as underlying storage will get reused by later batches
|
|
||||||
capturedBatch.ReferenceFrames = renderBatch.ReferenceFrames.ToArray();
|
|
||||||
capturedBatch.DisposedComponentIDs = renderBatch.DisposedComponentIDs.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CapturedBatch
|
|
||||||
{
|
|
||||||
public IDictionary<int, List<RenderTreeDiff>> DiffsByComponentId { get; }
|
|
||||||
= new Dictionary<int, List<RenderTreeDiff>>();
|
|
||||||
|
|
||||||
public IList<RenderTreeDiff> DiffsInOrder { get; }
|
|
||||||
= new List<RenderTreeDiff>();
|
|
||||||
|
|
||||||
public IList<int> DisposedComponentIDs { get; set; }
|
|
||||||
public RenderTreeFrame[] ReferenceFrames { get; set; }
|
|
||||||
|
|
||||||
internal void AddDiff(RenderTreeDiff diff)
|
|
||||||
{
|
|
||||||
var componentId = diff.ComponentId;
|
|
||||||
if (!DiffsByComponentId.ContainsKey(componentId))
|
|
||||||
{
|
|
||||||
DiffsByComponentId.Add(componentId, new List<RenderTreeDiff>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone the diff, because its underlying storage will get reused in subsequent batches
|
|
||||||
var diffClone = new RenderTreeDiff(
|
|
||||||
diff.ComponentId,
|
|
||||||
new ArraySegment<RenderTreeEdit>(diff.Edits.ToArray()));
|
|
||||||
DiffsByComponentId[componentId].Add(diffClone);
|
|
||||||
DiffsInOrder.Add(diffClone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestComponent : IComponent
|
private class TestComponent : IComponent
|
||||||
{
|
{
|
||||||
private RenderHandle _renderHandle;
|
private RenderHandle _renderHandle;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Blazor.Components;
|
||||||
using Microsoft.AspNetCore.Blazor.RenderTree;
|
using Microsoft.AspNetCore.Blazor.RenderTree;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Blazor.Test.Shared
|
namespace Microsoft.AspNetCore.Blazor.Test.Helpers
|
||||||
{
|
{
|
||||||
internal static class AssertFrame
|
internal static class AssertFrame
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue