Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enable MVVM Toolkit source generator unit tests #4198

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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