Skip to content

Commit

Permalink
Merge pull request #4198 from Sergio0694/testing/mvvm-toolkit-sg
Browse files Browse the repository at this point in the history
Fix and enable MVVM Toolkit source generator unit tests
  • Loading branch information
Sergio0694 authored Sep 3, 2021
2 parents 984fe18 + 33bdd30 commit 0ce4553
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.SourceGenerators;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -249,6 +250,7 @@ public partial class SampleViewModel
private void VerifyGeneratedDiagnostics<TGenerator>(string source, params string[] diagnosticsIds)
where TGenerator : class, ISourceGenerator, new()
{
Type observableObjectType = typeof(ObservableObject);
Type validationAttributeType = typeof(ValidationAttribute);

SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source);
Expand All @@ -271,6 +273,7 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies()

Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds));

GC.KeepAlive(observableObjectType);
GC.KeepAlive(validationAttributeType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Toolkit.Mvvm.SourceGenerators\Microsoft.Toolkit.Mvvm.SourceGenerators.csproj" />
<ProjectReference Include="..\..\Microsoft.Toolkit.Mvvm\Microsoft.Toolkit.Mvvm.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions build/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ Task("Test")
ArgumentCustomization = arg => arg.Append($"-s {baseDir}/.runsettings /p:Platform=AnyCPU"),
};
DotNetCoreTest(file.FullPath, testSettings);
}).DoesForEach(GetFiles(baseDir + "/**/UnitTests.SourceGenerators.csproj"), (file) =>
{
Information("\nRunning NetCore Source Generator Unit Tests");
var testSettings = new DotNetCoreTestSettings
{
Configuration = configuration,
NoBuild = true,
Loggers = new[] { "trx;LogFilePrefix=VsTestResults" },
Verbosity = DotNetCoreVerbosity.Normal,
ArgumentCustomization = arg => arg.Append($"-s {baseDir}/.runsettings /p:Platform=AnyCPU"),
};
DotNetCoreTest(file.FullPath, testSettings);
}).DeferOnError();

Task("UITest")
Expand Down

0 comments on commit 0ce4553

Please sign in to comment.