Skip to content

Commit

Permalink
Merge pull request #160 from Lombiq/issue/OSOE-838
Browse files Browse the repository at this point in the history
OSOE-838: Updating xUnit to latest and adapting to it
  • Loading branch information
Piedone committed May 15, 2024
2 parents 4a503d8 + 0ca7988 commit faa7dc2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Lombiq.DataTables/Lombiq.DataTables.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="9.1.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.LinqToDb" Version="9.1.0" />
<PackageReference Include="Lombiq.NodeJs.Extensions" Version="1.3.3-alpha.0.osoe-751" />
<PackageReference Include="Lombiq.NodeJs.Extensions" Version="2.1.0" />
</ItemGroup>

<Import Condition="'$(NuGetBuild)' != 'true'" Project="..\..\..\Utilities\Lombiq.NodeJs.Extensions\Lombiq.NodeJs.Extensions\Lombiq.NodeJs.Extensions.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="OrchardCore.Liquid" Version="1.8.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.DataTables.Tests.UnitTests.Services;

[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This is just an input class for a unit test.")]
public class DataTableShouldMatchExpectationInput(
string note,
object[][] dataSet,
(string Name, string Text, bool Exportable)[] columns,
string[][] pattern,
int start,
int length,
int orderColumnIndex)
{
public string Note { get; set; } = note;
public object[][] DataSet { get; set; } = dataSet;
public (string Name, string Text, bool Exportable)[] Columns { get; set; } = columns;
public string[][] Pattern { get; set; } = pattern;
public int Start { get; set; } = start;
public int Length { get; set; } = length;
public int OrderColumnIndex { get; set; } = orderColumnIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,34 @@ public class ExportTests
// ClosedXML looks at the CurrentCulture to initialize the workbook's culture.
private static readonly CultureInfo _worksheetCulture = new("en-US", useUserOverride: false);

public static readonly TheoryData<DataTableShouldMatchExpectationInput> ExportTableShouldMatchExpectationInputs =
new(GenerateExportTableShouldMatchExpectationInputs());

[Theory]
[MemberData(nameof(Data))]
public async Task ExportTableShouldMatchExpectation(
string note,
object[][] dataSet,
(string Name, string Text, bool Exportable)[] columns,
string[][] pattern,
int start,
int length,
int orderColumnIndex)
// DataTableShouldMatchExpectationInput would need to implement IXunitSerializable but it works like this anyway.
#pragma warning disable xUnit1045 // Avoid using TheoryData type arguments that might not be serializable
[MemberData(nameof(ExportTableShouldMatchExpectationInputs))]
#pragma warning restore xUnit1045 // Avoid using TheoryData type arguments that might not be serializable
public async Task ExportTableShouldMatchExpectation(DataTableShouldMatchExpectationInput input)
{
// ClosedXML looks at the CurrentCulture to initialize the workbook's culture. They also to set it like this in
// their own unit tests. See:
// https://github.com/ClosedXML/ClosedXML/blob/c2d408b/ClosedXML_Tests/Excel/CalcEngine/LookupTests.cs#L16-L17
// Since this is an async method, it runs in its own thread; so this has no effect on other tests.
Thread.CurrentThread.CurrentCulture = _worksheetCulture;

note.ShouldNotBeEmpty("Please state the purpose of this input set!");
input.Note.ShouldNotBeEmpty("Please state the purpose of this input set!");

var columns = input.Columns;
var pattern = input.Pattern;

using var memoryCache = new MemoryCache(new OptionsWrapper<MemoryCacheOptions>(new MemoryCacheOptions()));
var (provider, request) = MockDataProviderHelper.GetProviderAndRequest(
dataSet,
input.DataSet,
columns,
start,
length,
orderColumnIndex,
input.Start,
input.Length,
input.OrderColumnIndex,
memoryCache);

var service = MockHelper.CreateAutoMockerInstance<ExcelDataTableExportService>(
Expand Down Expand Up @@ -104,7 +106,7 @@ public class ExportTests
}
}

public static IEnumerable<object[]> Data()
public static IEnumerable<DataTableShouldMatchExpectationInput> GenerateExportTableShouldMatchExpectationInputs()
{
var dataset = new[]
{
Expand Down Expand Up @@ -133,19 +135,16 @@ public static IEnumerable<object[]> Data()
("MagicWords", "Magic Words", true),
};

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Show full data set.",
dataset,
columns,
"1,z,foo;2,y,bar;10,x,baz".Split(';').Select(row => row.Split(',')).ToArray(),
0,
10,
0,
};
0);

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Make last column not exportable.",
dataset,
new[]
Expand All @@ -157,57 +156,47 @@ public static IEnumerable<object[]> Data()
"1,z;2,y;10,x".Split(';').Select(row => row.Split(',')).ToArray(),
0,
10,
0,
};
0);

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Test pagination.",
dataset,
columns,
new[] { "10,x,baz".Split(',') },
2,
10,
0,
};
0);

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Test sorting on 2nd column.",
dataset,
columns,
"10,x,baz;2,y,bar;1,z,foo".Split(';').Select(row => row.Split(',')).ToArray(),
0,
10,
1,
};
1);

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Test sorting on 3nd column.",
dataset,
columns,
"2,y,bar;10,x,baz;1,z,foo".Split(';').Select(row => row.Split(',')).ToArray(),
0,
10,
2,
};
2);

yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Verify boolean formatting.",
new[]
{
[
[1, true],
[2, true],
new object[] { 3, false },
},
[3, false],
],
new[] { ("Num", "Numbers", true), ("Bool", "Booleans", true) },
"1,Yes;2,Yes;3,No".Split(';').Select(row => row.Split(',')).ToArray(),
0,
10,
0,
};
0);

var date1 = new DateTime(2020, 11, 26, 23, 42, 01, DateTimeKind.Utc);
var date2 = new DateTime(2020, 11, 26, 13, 42, 01, DateTimeKind.Utc);
Expand All @@ -217,8 +206,7 @@ public static IEnumerable<object[]> Data()
// consistency.
#pragma warning disable IDE0300 // Simplify collection initialization
// The date value should be the same, only the formatting changes.
yield return new object[]
{
yield return new DataTableShouldMatchExpectationInput(
"Verify custom number formatting.",
new[]
{
Expand All @@ -238,8 +226,7 @@ public static IEnumerable<object[]> Data()
.ToArray(),
0,
10,
0,
};
0);
#pragma warning restore IDE0300 // Simplify collection initialization
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ public class LiquidTests
{
private static readonly string[] Separator = ["||"];

public static readonly TheoryData<DataTableShouldMatchExpectationInput> LiquidEvaluationMatchExpectationInputs =
new(GenerateLiquidEvaluationMatchExpectationInputs());

[Theory]
[MemberData(nameof(Data))]
public async Task LiquidEvaluationMatchExpectation(
string note,
object[][] dataSet,
(string Name, string Text, bool Exportable)[] columns,
string[][] pattern,
int start,
int length,
int orderColumnIndex)
// DataTableShouldMatchExpectationInput would need to implement IXunitSerializable but it works like this anyway.
#pragma warning disable xUnit1045 // Avoid using TheoryData type arguments that might not be serializable
[MemberData(nameof(LiquidEvaluationMatchExpectationInputs))]
#pragma warning restore xUnit1045 // Avoid using TheoryData type arguments that might not be serializable
public async Task LiquidEvaluationMatchExpectation(DataTableShouldMatchExpectationInput input)
{
note.ShouldNotBeEmpty("Please state the purpose of this input set!");
input.Note.ShouldNotBeEmpty("Please state the purpose of this input set!");

var columns = input.Columns;
var pattern = input.Pattern;

// Everything in this section of code is required for the Liquid renderer to work. Otherwise it will throw NRE
// or render empty string results. On the final line shellScope.StartAsyncFlow() initializes the static variable
Expand Down Expand Up @@ -72,11 +74,11 @@ public class LiquidTests

using var memoryCache = new MemoryCache(new OptionsWrapper<MemoryCacheOptions>(new MemoryCacheOptions()));
var (provider, request) = MockDataProviderHelper.GetProviderAndRequest(
dataSet,
input.DataSet,
columns,
start,
length,
orderColumnIndex,
input.Start,
input.Length,
input.OrderColumnIndex,
memoryCache,
shellContext.ServiceProvider);
var rows = (await provider.GetRowsAsync(request)).Data.ToList();
Expand All @@ -93,7 +95,7 @@ public class LiquidTests
}
}

public static IEnumerable<object[]> Data()
public static IEnumerable<DataTableShouldMatchExpectationInput> GenerateLiquidEvaluationMatchExpectationInputs()
{
// Simplified collection initialization for the first two would leave the third one as it is. Keeping for
// consistency.
Expand All @@ -107,9 +109,8 @@ public static IEnumerable<object[]> Data()
#pragma warning restore IDE0300 // Simplify collection initialization
var today = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

yield return new object[]
{
// By "built-in" we mean only those implemented in Fluid, not the ones added by OrchardCore.
// By "built-in" we mean only those implemented in Fluid, not the ones added by OrchardCore.
yield return new DataTableShouldMatchExpectationInput(
"Demonstrate some built-in filters.",
dataset,
new[]
Expand All @@ -123,7 +124,6 @@ public static IEnumerable<object[]> Data()
.ToArray(),
0,
10,
1,
};
1);
}
}

0 comments on commit faa7dc2

Please sign in to comment.