Skip to content

Commit

Permalink
Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar committed Apr 1, 2024
1 parent 9196821 commit 273e463
Show file tree
Hide file tree
Showing 22 changed files with 3,249 additions and 7 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,26 @@ jobs:
- name: Restore dependencies
run: dotnet restore

- name: Build
- name: Build Debug - TaskWhenAllNotificationPublisher
run: dotnet build --no-restore -p:ExtraDefineConstants=TASKWHENALLPUBLISHER

- name: Test Debug - TaskWhenAllNotificationPublisher
run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed"

- name: Clean Debug
run: dotnet clean

- name: Build Debug
run: dotnet build --no-restore

- name: Test Debug
run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed"

- name: Build Release
run: dotnet build --no-restore -c Release

- name: Test
run: dotnet test --no-restore --verbosity normal -c Release
- name: Test Release
run: dotnet test --no-restore --no-build -c Release --logger "console;verbosity=detailed"

- name: Pack
if: ${{ success() && !github.base_ref }}
Expand Down
7 changes: 6 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ build:
dotnet build Mediator.sln

test:
dotnet test Mediator.sln
dotnet clean
dotnet build -p:ExtraDefineConstants=TASKWHENALLPUBLISHER
dotnet test --no-build --logger "console;verbosity=detailed"
dotnet clean
dotnet build
dotnet test --no-build --logger "console;verbosity=detailed"
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,34 @@ CancellationToken cancellationToken
if (!string.IsNullOrWhiteSpace(namespaceArg))
MediatorNamespace = namespaceArg!;
}
else if (attrFieldName == "NotificationPublisherType")
{
if (attrArg.Expression is not TypeOfExpressionSyntax identifier)
{
ReportDiagnostic((in CompilationAnalyzerContext c) => c.ReportInvalidCodeBasedConfiguration());
return;
}
var typeSymbol = semanticModel.GetTypeInfo(identifier.Type, cancellationToken).Type;
if (typeSymbol is null)
{
ReportDiagnostic((in CompilationAnalyzerContext c) => c.ReportInvalidCodeBasedConfiguration());
return;
}

if (typeSymbol is not INamedTypeSymbol namedTypeSymbol)
{
ReportDiagnostic((in CompilationAnalyzerContext c) => c.ReportInvalidCodeBasedConfiguration());
return;
}

if (!Context.Compilation.HasImplicitConversion(namedTypeSymbol, _notificationPublisherInterfaceSymbol))
{
ReportDiagnostic((in CompilationAnalyzerContext c) => c.ReportInvalidCodeBasedConfiguration());
return;
}

_notificationPublisherImplementationSymbol = namedTypeSymbol;
}
}

ConfiguredViaAttribute = true;
Expand Down
77 changes: 76 additions & 1 deletion test/Mediator.SourceGenerator.Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,43 @@ namespace Mediator.SourceGenerator.Tests;
public sealed class ConfigurationTests
{
[Fact]
public async Task Test_TaskWhenAllPublisher_For_Notifications_Program()
public async Task Test_ForEachAwaitPublisher_Default()
{
var inputCompilation = Fixture.CreateLibrary(
"""
using System;
using System.Threading;
using System.Threading.Tasks;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
namespace TestCode;
public class Program
{
public static void Main()
{
var services = new ServiceCollection();
services.AddMediator();
}
}
"""
);

await inputCompilation.AssertAndVerify(
Assertions.CompilesWithoutDiagnostics,
result =>
{
var model = result.Generator.CompilationModel;
Assert.NotNull(model);
Assert.Equal("global::Mediator.ForeachAwaitPublisher", model.NotificationPublisherType.FullName);
}
);
}

[Fact]
public async Task Test_TaskWhenAllPublisher_For_Notifications_AddMediator()
{
var inputCompilation = Fixture.CreateLibrary(
"""
Expand Down Expand Up @@ -38,6 +74,45 @@ await inputCompilation.AssertAndVerify(
{
var model = result.Generator.CompilationModel;
Assert.NotNull(model);
Assert.Equal("global::Mediator.TaskWhenAllPublisher", model.NotificationPublisherType.FullName);
}
);
}

[Fact]
public async Task Test_TaskWhenAllPublisher_For_Notifications_Attribute()
{
var inputCompilation = Fixture.CreateLibrary(
"""
using System;
using System.Threading;
using System.Threading.Tasks;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
[assembly: MediatorOptions(NotificationPublisherType = typeof(TaskWhenAllPublisher))]
namespace TestCode;
public class Program
{
public static void Main()
{
var services = new ServiceCollection();
services.AddMediator();
}
}
"""
);

await inputCompilation.AssertAndVerify(
Assertions.CompilesWithoutDiagnostics,
result =>
{
var model = result.Generator.CompilationModel;
Assert.NotNull(model);
Assert.Equal("global::Mediator.TaskWhenAllPublisher", model.NotificationPublisherType.FullName);
}
);
}
Expand Down
Loading

0 comments on commit 273e463

Please sign in to comment.