diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/Microsoft.AspNetCore.Blazor.Build.Test.csproj b/test/Microsoft.AspNetCore.Blazor.Build.Test/Microsoft.AspNetCore.Blazor.Build.Test.csproj index 5b380e4031..acc88b16f3 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/Microsoft.AspNetCore.Blazor.Build.Test.csproj +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/Microsoft.AspNetCore.Blazor.Build.Test.csproj @@ -18,7 +18,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs index d978aa554c..1a1e37a509 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.Layouts; using Microsoft.AspNetCore.Blazor.Rendering; using Microsoft.AspNetCore.Blazor.RenderTree; -using Microsoft.AspNetCore.Blazor.Test.Shared; +using Microsoft.AspNetCore.Blazor.Test.Helpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using System; diff --git a/test/Microsoft.AspNetCore.Blazor.Test/AutoRenderComponent.cs b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/AutoRenderComponent.cs similarity index 94% rename from test/Microsoft.AspNetCore.Blazor.Test/AutoRenderComponent.cs rename to test/Microsoft.AspNetCore.Blazor.Test/Helpers/AutoRenderComponent.cs index dcbf6a05cd..f30e450e18 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/AutoRenderComponent.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/AutoRenderComponent.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.RenderTree; -namespace Microsoft.AspNetCore.Blazor.Test +namespace Microsoft.AspNetCore.Blazor.Test.Helpers { public abstract class AutoRenderComponent : IComponent { diff --git a/test/Microsoft.AspNetCore.Blazor.Test/Helpers/CapturedBatch.cs b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/CapturedBatch.cs new file mode 100644 index 0000000000..95356ed51b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/CapturedBatch.cs @@ -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> DiffsByComponentId { get; } + = new Dictionary>(); + + public IList DiffsInOrder { get; } + = new List(); + + public IList 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()); + } + + // Clone the diff, because its underlying storage will get reused in subsequent batches + var diffClone = new RenderTreeDiff( + diff.ComponentId, + new ArraySegment(diff.Edits.ToArray())); + DiffsByComponentId[componentId].Add(diffClone); + DiffsInOrder.Add(diffClone); + } + } +} diff --git a/test/Microsoft.AspNetCore.Blazor.Test/Helpers/TestRenderer.cs b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/TestRenderer.cs new file mode 100644 index 0000000000..8c652d6bd4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Test/Helpers/TestRenderer.cs @@ -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 Batches { get; } + = new List(); + + 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(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Blazor.Test/Microsoft.AspNetCore.Blazor.Test.csproj b/test/Microsoft.AspNetCore.Blazor.Test/Microsoft.AspNetCore.Blazor.Test.csproj index 299fa84e0f..64a966b165 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/Microsoft.AspNetCore.Blazor.Test.csproj +++ b/test/Microsoft.AspNetCore.Blazor.Test/Microsoft.AspNetCore.Blazor.Test.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeBuilderTest.cs b/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeBuilderTest.cs index 3bba6922a7..b7ad4d0a0f 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeBuilderTest.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.Rendering; using Microsoft.AspNetCore.Blazor.RenderTree; -using Microsoft.AspNetCore.Blazor.Test.Shared; +using Microsoft.AspNetCore.Blazor.Test.Helpers; using System; using System.Linq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeDiffBuilderTest.cs b/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeDiffBuilderTest.cs index 5822f29a29..bb44087497 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeDiffBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/RenderTreeDiffBuilderTest.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.Rendering; using Microsoft.AspNetCore.Blazor.RenderTree; -using Microsoft.AspNetCore.Blazor.Test.Shared; +using Microsoft.AspNetCore.Blazor.Test.Helpers; using System; using System.Collections.Generic; using System.Linq; diff --git a/test/Microsoft.AspNetCore.Blazor.Test/RendererTest.cs b/test/Microsoft.AspNetCore.Blazor.Test/RendererTest.cs index 5a2c34f2e9..ffeebe7eca 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/RendererTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/RendererTest.cs @@ -7,12 +7,12 @@ using System.Linq; using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.Rendering; using Microsoft.AspNetCore.Blazor.RenderTree; -using Microsoft.AspNetCore.Blazor.Test.Shared; +using Microsoft.AspNetCore.Blazor.Test.Helpers; using Xunit; namespace Microsoft.AspNetCore.Blazor.Test { - public partial class RendererTest + public class RendererTest { [Fact] public void CanRenderTopLevelComponents() @@ -873,62 +873,6 @@ namespace Microsoft.AspNetCore.Blazor.Test } } - private class TestRenderer : Renderer - { - public List Batches { get; } - = new List(); - - 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> DiffsByComponentId { get; } - = new Dictionary>(); - - public IList DiffsInOrder { get; } - = new List(); - - public IList 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()); - } - - // Clone the diff, because its underlying storage will get reused in subsequent batches - var diffClone = new RenderTreeDiff( - diff.ComponentId, - new ArraySegment(diff.Edits.ToArray())); - DiffsByComponentId[componentId].Add(diffClone); - DiffsInOrder.Add(diffClone); - } - } - private class TestComponent : IComponent { private RenderHandle _renderHandle; diff --git a/test/shared/AssertFrame.cs b/test/shared/AssertFrame.cs index 64d25559b4..1bc2cb9d12 100644 --- a/test/shared/AssertFrame.cs +++ b/test/shared/AssertFrame.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.RenderTree; using Xunit; -namespace Microsoft.AspNetCore.Blazor.Test.Shared +namespace Microsoft.AspNetCore.Blazor.Test.Helpers { internal static class AssertFrame {