Skip to content

Commit

Permalink
Merge pull request #161 from unoplatform/dev/dr/fixCaseSource
Browse files Browse the repository at this point in the history
fix: Fix support of DynamicData
  • Loading branch information
dr1rrb committed Jan 4, 2024
2 parents fc20729 + b3ce536 commit e3031e2
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/TestApp/shared/HotReloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public async Task Is_SourcesEditable(CancellationToken ct)
var file = Path.Combine(dir, sutPath);

Assert.IsTrue(File.Exists(file));
Assert.IsTrue(File.ReadAllText(file).Contains("Original text"));
Assert.IsTrue((await File.ReadAllTextAsync(file, ct)).Contains("Original text"));

await using var _ = await HotReloadHelper.UpdateSourceFile(sutPath, "Original text", "Updated text from Can_Edit_File", waitForMetadataUpdate: false, ct);

await TestHelper.WaitFor(() => File.ReadAllText(file).Contains("Updated text from Can_Edit_File"), ct);

Assert.IsTrue(File.ReadAllText(file).Contains("Updated text from Can_Edit_File"));
Assert.IsTrue((await File.ReadAllTextAsync(file, ct)).Contains("Updated text from Can_Edit_File"));
}

[TestMethod]
Expand Down
23 changes: 23 additions & 0 deletions src/TestApp/shared/SanityTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -44,6 +45,28 @@ public async Task When_Test_ContentHelper()
[DataRow("goodbye", DisplayName = "goodbye test")]
public void Is_Sane_With_Cases(string text)
{
#pragma warning disable CA1861 // Prefer static readonly
Assert.IsTrue(new[] { "hello", "goodbye" }.Contains(text));
}

[TestMethod]
[DynamicData(nameof(DynamicData), DynamicDataSourceType.Property)]
[DynamicData(nameof(GetDynamicData), DynamicDataSourceType.Method)]
public void Is_Sane_With_DynamicData(string text)
{
Assert.IsTrue(new[] { "hello", "goodbye" }.Contains(text));
}

public static IEnumerable<object[]> DynamicData { get; } = new[]
{
new object[] { "hello" },
new object[] { "goodbye" },
};

public static IEnumerable<object[]> GetDynamicData()
{
yield return new object[] { "hello" };
yield return new object[] { "goodbye" };
}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private static int GetTcpPort()
}
catch (global::System.Exception e)
{
global::Microsoft.Extensions.Logging.LoggerExtensions.LogError(_log, "Failed to kill dev server", e);
global::Microsoft.Extensions.Logging.LoggerExtensions.LogError(_log, e, "Failed to kill dev server");
}

await _process.WaitForExitAsync(global::System.Threading.CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ internal static partial class SecondaryApp
}
}

private static readonly global::System.Text.Json.JsonSerializerOptions _serializeOpts = new global::System.Text.Json.JsonSerializerOptions { DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault };
private static int _instance;

private static async global::System.Threading.Tasks.Task<string> RunLocalApp(string devServerHost, int devServerPort, UnitTestEngineConfig config, bool isAppVisible, global::System.Threading.CancellationToken ct)
{
var testOutput = global::System.IO.Path.GetTempFileName();
var configJson = global::System.Text.Json.JsonSerializer.Serialize(config, new global::System.Text.Json.JsonSerializerOptions { DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault });
var configJson = global::System.Text.Json.JsonSerializer.Serialize(config, _serializeOpts);

var childStartInfo = new global::System.Diagnostics.ProcessStartInfo(
global::System.Environment.ProcessPath ?? throw new global::System.InvalidOperationException("Cannot determine the current app executable path"),
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.RuntimeTests.Engine.Library/Engine/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CA1852 // Make class final : unnecessary breaking change

using System;
using System.Linq;
Expand All @@ -11,7 +12,6 @@
namespace Uno.UI.RuntimeTests;

#if !UNO_RUNTIMETESTS_DISABLE_UI

internal record TestCase
{
public object[] Parameters { get; init; } = Array.Empty<object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CA1852 // Make class final : unnecessary breaking change

using System;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Uno.UI.RuntimeTests
{
public sealed partial class UnitTestsControl
{
private class ConsoleOutputRecorder : IDisposable
private sealed class ConsoleOutputRecorder : IDisposable
{
private readonly TextWriterDuplicator _duplicator;
private readonly TextWriter _originalOutput;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void Dispose()
}
}

private class TextWriterDuplicator : TextWriter
private sealed class TextWriterDuplicator : TextWriter
{
private readonly TextWriter _inner;
private readonly StringBuilder _accumulator = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CA1852 // Make class final : unnecessary breaking change

public sealed partial class UnitTestsControl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ private async Task ExecuteTestsForInstance(
.Select(method => new UnitTestMethodInfo(instance, method))
.ToArray();

if (!tests.Any() || testClassInfo.Type == null)
if (tests.Length <= 0 || testClassInfo.Type == null)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if !IS_UNO_RUNTIMETEST_PROJECT
#pragma warning disable
#endif
#pragma warning disable CA1852 // Make class final : unnecessary breaking change

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -93,15 +94,15 @@ public IEnumerable<TestCase> GetCases(CancellationToken ct)
foreach (var testCaseSource in _casesParameters)
{
// Note: CT is not propagated when using a test data source
foreach (var caseData in testCaseSource.GetData(Method))
{
var data = testCaseSource
.GetData(Method)
.SelectMany(x => x)
.ToArray();

cases.Add(new TestCase { Parameters = data, DisplayName = testCaseSource.GetDisplayName(Method, data) });
}
var testCases = testCaseSource
.GetData(Method)
.Select(caseData => new TestCase
{
Parameters = caseData,
DisplayName = testCaseSource.GetDisplayName(Method, caseData)
});

cases.AddRange(testCases);
}

if (_injectedPointerTypes.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public UpdateFile ToMessage()
};
}

private class DevServerUpdater : IFileUpdater
private sealed class DevServerUpdater : IFileUpdater
{
/// <inheritdoc />
public async ValueTask EnsureReady(CancellationToken ct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static partial void TryUseLocalFileUpdater()
public static void UseLocalFileUpdater()
=> Use(new LocalFileUpdater());

private class LocalFileUpdater : IFileUpdater
private sealed class LocalFileUpdater : IFileUpdater
{
/// <inheritdoc />
public async global::System.Threading.Tasks.ValueTask EnsureReady(global::System.Threading.CancellationToken ct) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Uno.UI.RuntimeTests;

public static partial class HotReloadHelper
{
private class NotSupported : IFileUpdater
private sealed class NotSupported : IFileUpdater
{
/// <inheritdoc />
public global::System.Threading.Tasks.ValueTask EnsureReady(global::System.Threading.CancellationToken ct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial record FileEdit(string FilePath, string OldText, string NewText)
public FileEdit Revert() => this with { OldText = NewText, NewText = OldText };
}

private record RevertFileEdit(FileEdit Edition, bool WaitForMetadataUpdate) : global::System.IAsyncDisposable
private sealed record RevertFileEdit(FileEdit Edition, bool WaitForMetadataUpdate) : global::System.IAsyncDisposable
{
/// <inheritdoc />
public async global::System.Threading.Tasks.ValueTask DisposeAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void InjectMouseInput(IEnumerable<InjectedInputMouseInfo?> input)
public void InjectMouseInput(params InjectedInputMouseInfo?[] input)
=> Injector.InjectMouseInput(input.Where(i => i is not null).Cast<InjectedInputMouseInfo>());

private record PointerSubscription(InputInjectorHelper Injector, PointerDeviceType Previous, PointerDeviceType Current) : IDisposable
private sealed record PointerSubscription(InputInjectorHelper Injector, PointerDeviceType Previous, PointerDeviceType Current) : IDisposable
{
/// <inheritdoc />
public void Dispose()
Expand Down

0 comments on commit e3031e2

Please sign in to comment.