Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix support of DynamicData #161

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -327,7 +327,7 @@
Text = $"{testClass.Name} ({testClass.Assembly.GetName().Name})",
Foreground = new SolidColorBrush(Colors.White),
FontSize = 16d,
IsTextSelectionEnabled = true

Check warning on line 330 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)

Check warning on line 330 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)
};

testResults.Children.Add(testResultBlock);
Expand Down Expand Up @@ -383,7 +383,7 @@
FontFamily = new FontFamily("Courier New"),
Margin = new Thickness(8, 0, 0, 0),
Foreground = new SolidColorBrush(Colors.LightGray),
IsTextSelectionEnabled = true

Check warning on line 386 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)

Check warning on line 386 in src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsControl.cs

View workflow job for this annotation

GitHub Actions / build

Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled is not implemented in Uno (https://aka.platform.uno/notimplemented?m=Microsoft.UI.Xaml.Controls.TextBlock.IsTextSelectionEnabled) (https://aka.platform.uno/notimplemented)
};

var retriesText = _currentRun.CurrentRepeatCount != 0 ? $" (Retried {_currentRun.CurrentRepeatCount} time(s))" : "";
Expand Down Expand Up @@ -725,7 +725,7 @@
.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
Loading