diff --git a/build/ci/.azure-devops-unit-tests.yml b/build/ci/.azure-devops-unit-tests.yml index d5a870d3669c..d25f806ac0d7 100644 --- a/build/ci/.azure-devops-unit-tests.yml +++ b/build/ci/.azure-devops-unit-tests.yml @@ -61,6 +61,13 @@ jobs: artifactName: 'NugetPackages-Artifacts-reference-$(XAML_FLAVOR_BUILD)' downloadPath: '$(Agent.WorkFolder)' + # Unfortunate, but this is needed specifically for a single test: TestAndroidViewImplementingDependencyObject + - task: DownloadBuildArtifacts@0 + displayName: Download build artifact + inputs: + artifactName: 'NugetPackages-Artifacts-netcoremobile-$(XAML_FLAVOR_BUILD)' + downloadPath: '$(Agent.WorkFolder)' + - task: ExtractFiles@1 displayName: Restore binaries structure inputs: diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs index 3fa7d8a122fe..50d5372af071 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/DependencyObjectGeneratorTests/Given_DependencyObjectGenerator.cs @@ -1,5 +1,7 @@ using System.Collections.Immutable; using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; @@ -14,9 +16,51 @@ namespace Uno.UI.SourceGenerators.Tests.DependencyObjectGeneratorTests; [TestClass] public class Given_DependencyObjectGenerator { - private static readonly ImmutableArray _unoPackage = ImmutableArray.Create(new PackageIdentity("Uno.WinUI", "5.0.118")); - private static readonly ReferenceAssemblies _Net70AndroidWithUno = ReferenceAssemblies.Net.Net80Android.AddPackages(_unoPackage); - private static readonly ReferenceAssemblies _Net70WithUno = ReferenceAssemblies.Net.Net80.AddPackages(_unoPackage); + private static readonly ReferenceAssemblies _net80Android = ReferenceAssemblies.Net.Net80Android.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); + private static readonly ReferenceAssemblies _net80 = ReferenceAssemblies.Net.Net80.AddPackages([new PackageIdentity("Uno.Diagnostics.Eventing", "2.1.0")]); + + private const string Configuration = +#if DEBUG + "Debug"; +#else + "Release"; +#endif + + private const string TFM = "net8.0"; + + private static MetadataReference[] BuildUnoReferences(bool isAndroid) + { + string[] availableTargets = isAndroid + ? [Path.Combine("Uno.UI.netcoremobile", Configuration, $"{TFM}-android")] + : [ + Path.Combine("Uno.UI.Skia", Configuration, TFM), + Path.Combine("Uno.UI.Reference", Configuration, TFM), + Path.Combine("Uno.UI.Tests", Configuration, TFM), + ]; + + var unoUIBase = Path.Combine( + Path.GetDirectoryName(typeof(Given_DependencyObjectGenerator).Assembly.Location)!, + "..", + "..", + "..", + "..", + "..", + "Uno.UI", + "bin" + ); + var unoTarget = availableTargets + .Select(t => Path.Combine(unoUIBase, t, "Uno.UI.dll")) + .FirstOrDefault(File.Exists); + if (unoTarget is null) + { + throw new InvalidOperationException($"Unable to find Uno.UI.dll in {string.Join(",", availableTargets)}"); + } + + return Directory.GetFiles(Path.GetDirectoryName(unoTarget)!, "*.dll") + .Select(f => MetadataReference.CreateFromFile(Path.GetFullPath(f))) + .ToArray(); + } + private async Task TestAndroid(string testCode, params DiagnosticResult[] expectedDiagnostics) { @@ -26,8 +70,10 @@ private async Task TestAndroid(string testCode, params DiagnosticResult[] expect { Sources = { testCode }, }, - ReferenceAssemblies = _Net70AndroidWithUno, + ReferenceAssemblies = _net80Android, }; + + test.TestState.AdditionalReferences.AddRange(BuildUnoReferences(isAndroid: true)); test.ExpectedDiagnostics.AddRange(expectedDiagnostics); await test.RunAsync(); } @@ -65,7 +111,7 @@ public void UnregisterPropertyChangedCallback(DependencyProperty dp, long token) [TestMethod] public async Task TestNested() { - var test = """ + var testCode = """ using Windows.UI.Core; using Microsoft.UI.Xaml; @@ -77,11 +123,11 @@ internal partial class Inner : DependencyObject } """; - await new Verify.Test + var test = new Verify.Test { TestState = { - Sources = { test }, + Sources = { testCode }, GeneratedSources = { { (@"Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.DependencyObject.DependencyObjectGenerator\OuterClass.Inner.cs", SourceText.From(""" @@ -292,7 +338,10 @@ public void SuspendBindings() => """, Encoding.UTF8)) } } }, - ReferenceAssemblies = _Net70WithUno, - }.RunAsync(); + ReferenceAssemblies = _net80, + }; + + test.TestState.AdditionalReferences.AddRange(BuildUnoReferences(isAndroid: false)); + await test.RunAsync(); } }