Skip to content

Commit

Permalink
Last in Class, Assembly & Session EventReceiver tidy up + fixes (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst authored Dec 16, 2024
1 parent 8c55e0d commit 5d52f03
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 269 deletions.
20 changes: 2 additions & 18 deletions TUnit.Core/Attributes/TestData/ClassDataSourceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public override IEnumerable<Func<T>> GenerateDataSources(DataGeneratorMetadata d
yield return () =>
{
var item = ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.Get<T>(Shared, dataGeneratorMetadata.TestClassType, Key);
.Get<T>(Shared, dataGeneratorMetadata.TestClassType, Key, dataGeneratorMetadata);

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, context) =>
{
Expand Down Expand Up @@ -43,23 +43,7 @@ await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestStart(
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestEnd(Shared, Key, item);
};

if (Shared is SharedType.PerClass)
{
dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInClass += async (_, context) =>
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnLastTestInClass<T>(context.Item2);
};
}

if (Shared is SharedType.PerAssembly)
{
dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInAssembly += async (_, context) =>
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnLastTestInAssembly<T>(context.Item2);
};
}


return item;
};
}
Expand Down
32 changes: 2 additions & 30 deletions TUnit.Core/Attributes/TestData/ClassDataSourceAttribute_2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public sealed class ClassDataSourceAttribute<
(T2 T, SharedType SharedType, string Key)
) itemsWithMetadata = (
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys)
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata)
);

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, context) =>
Expand Down Expand Up @@ -89,34 +89,6 @@ await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestEnd(
itemsWithMetadata.Item2.T);
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInClass += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnLastTestInClass<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnLastTestInClass<T2>(context.Item2);
}
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInAssembly += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T2>(context.Item2);
}
};

return (
itemsWithMetadata.Item1.T,
itemsWithMetadata.Item2.T
Expand Down
50 changes: 4 additions & 46 deletions TUnit.Core/Attributes/TestData/ClassDataSourceAttribute_3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public sealed class ClassDataSourceAttribute<
(T3 T, SharedType SharedType, string Key)
) itemsWithMetadata = (
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys)
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata)
);

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, context) =>
Expand Down Expand Up @@ -117,49 +117,7 @@ await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestEnd(
itemsWithMetadata.Item3.Key,
itemsWithMetadata.Item3.T);
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInClass += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T3>(context.Item2);
}
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInAssembly += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T3>(context.Item2);
}
};


return (
itemsWithMetadata.Item1.T,
itemsWithMetadata.Item2.T,
Expand Down
62 changes: 4 additions & 58 deletions TUnit.Core/Attributes/TestData/ClassDataSourceAttribute_4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public sealed class ClassDataSourceAttribute<
(T4 T, SharedType SharedType, string Key)
) itemsWithMetadata = (
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T4>(3, dataGeneratorMetadata.TestClassType, Shared, Keys)
.GetItemForIndex<T4>(3, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata)
);

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, context) =>
Expand Down Expand Up @@ -147,60 +147,6 @@ await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestEnd(
itemsWithMetadata.Item4.T);
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInClass += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T3>(context.Item2);
}

if (Shared.ElementAtOrDefault(3) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T4>(context.Item2);
}
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInAssembly += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T3>(context.Item2);
}

if (Shared.ElementAtOrDefault(3) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T4>(context.Item2);
}
};

return (
itemsWithMetadata.Item1.T,
itemsWithMetadata.Item2.T,
Expand Down
78 changes: 6 additions & 72 deletions TUnit.Core/Attributes/TestData/ClassDataSourceAttribute_5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public sealed class ClassDataSourceAttribute<
(T5 T, SharedType SharedType, string Key)
) itemsWithMetadata = (
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T1>(0, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T2>(1, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T3>(2, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T4>(3, dataGeneratorMetadata.TestClassType, Shared, Keys),
.GetItemForIndex<T4>(3, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata),
ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.GetItemForIndex<T5>(4, dataGeneratorMetadata.TestClassType, Shared, Keys)
.GetItemForIndex<T5>(4, dataGeneratorMetadata.TestClassType, Shared, Keys, dataGeneratorMetadata)
);

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, context) =>
Expand Down Expand Up @@ -175,73 +175,7 @@ await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId).OnTestEnd(
itemsWithMetadata.Item5.Key,
itemsWithMetadata.Item5.T);
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInClass += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T3>(context.Item2);
}

if (Shared.ElementAtOrDefault(3) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T4>(context.Item2);
}

if (Shared.ElementAtOrDefault(4) is SharedType.PerClass)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInClass<T5>(context.Item2);
}
};

dataGeneratorMetadata.TestBuilderContext.Current.Events.OnLastTestInAssembly += async (_, context) =>
{
if (Shared.ElementAtOrDefault(0) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T1>(context.Item2);
}

if (Shared.ElementAtOrDefault(1) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T2>(context.Item2);
}

if (Shared.ElementAtOrDefault(2) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T3>(context.Item2);
}

if (Shared.ElementAtOrDefault(3) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T4>(context.Item2);
}

if (Shared.ElementAtOrDefault(4) is SharedType.PerAssembly)
{
await ClassDataSources.Get(dataGeneratorMetadata!.TestSessionId)
.OnLastTestInAssembly<T5>(context.Item2);
}
};


return (
itemsWithMetadata.Item1.T,
itemsWithMetadata.Item2.T,
Expand Down
Loading

0 comments on commit 5d52f03

Please sign in to comment.