Repository: dotnet/maui
File: src/Controls/tests/SourceGen.UnitTests/InitializeComponent/XStaticUnresolvedType.cs (C#)

Code before:
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(staticExtension!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 6, 12);
		var label = new global::Microsoft.Maui.Controls.Label();
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(label!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 6, 6);
		var __root = this;
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(__root!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 2, 2);
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		global::Microsoft.Maui.Controls.Internals.INameScope iNameScope = global::Microsoft.Maui.Controls.Internals.NameScope.GetNameScope(__root) ?? new global::Microsoft.Maui.Controls.Internals.NameScope();
#endif
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		global::Microsoft.Maui.Controls.Internals.NameScope.SetNameScope(__root, iNameScope);
#endif
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		label.transientNamescope = iNameScope;
#endif
#line 6 "{{testXamlFilePath}}"
		label.SetValue(global::Microsoft.Maui.Controls.Label.TextProperty, staticExtension);
#line default
#line 6 "{{testXamlFilePath}}"
		__root.SetValue(global::Microsoft.Maui.Controls.ContentPage.ContentProperty, label);
#line default
	}
}

""";

		var (result, generated) = RunGenerator(xaml, code, assertNoCompilationErrors: false);
		Assert.False(result.Diagnostics.Any());
		Assert.Equal(expected, generated, ignoreLineEndingDifferences: true);
	}

	[Fact]
	public void XStaticWithClrNamespaceAndAssembly()
	{
		var xaml =
"""
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:constants="clr-namespace:ExternalLib.Constants;assembly=ExternalLib"
			 x:Class="Test.TestPage">
    <Label Text="{x:Static constants:AppConstants.AppName}" />
</ContentPage>
""";

		var code =
"""
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Test;

Review comment (suggestion):
@copilot this needs to be `true`. It seems the problem is that the code in this tests references unresolved
types (MyApp.Routes.Route, ExternalLib.Constants.AppConstants, and MyApp.Config.Settings). We need to add these to the references added to the compilation internally in RunGenerator. I think if we should allow passing additional references to RunGenerator + provide the necessary references for this specific test case.

Code after:
		});

		if (rlr?.ResourceContent != null)
		{
			this.InitializeComponentRuntime();
			return;
		}

		var staticExtension = global::MyApp.Routes.Route.Value;
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(staticExtension!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 6, 12);
		var label = new global::Microsoft.Maui.Controls.Label();
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(label!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 6, 6);
		var __root = this;
		global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(__root!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 2, 2);
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		global::Microsoft.Maui.Controls.Internals.INameScope iNameScope = global::Microsoft.Maui.Controls.Internals.NameScope.GetNameScope(__root) ?? new global::Microsoft.Maui.Controls.Internals.NameScope();
#endif
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		global::Microsoft.Maui.Controls.Internals.NameScope.SetNameScope(__root, iNameScope);
#endif
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
		label.transientNamescope = iNameScope;
#endif
#line 6 "{{testXamlFilePath}}"
		label.SetValue(global::Microsoft.Maui.Controls.Label.TextProperty, staticExtension);
#line default
#line 6 "{{testXamlFilePath}}"
		__root.SetValue(global::Microsoft.Maui.Controls.ContentPage.ContentProperty, label);
#line default
	}
}

""";

		var (result, generated) = RunGenerator(xaml, code, assertNoCompilationErrors: true);
		Assert.False(result.Diagnostics.Any());
		Assert.Equal(expected, generated, ignoreLineEndingDifferences: true);
	}

	[Fact]
	public void XStaticWithClrNamespaceAndAssembly()
	{
		var xaml =
"""
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:constants="clr-namespace:ExternalLib.Constants;assembly=ExternalLib"
			 x:Class="Test.TestPage">
    <Label Text="{x:Static constants:AppConstants.AppName}" />
</ContentPage>