Skip to content

Commit

Permalink
fix: Fix DynamicData support
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Jan 4, 2024
1 parent fc20729 commit 7e96973
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
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 @@ -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

0 comments on commit 7e96973

Please sign in to comment.