|
| 1 | +using System.Linq; |
| 2 | +using NUnit.Framework; |
| 3 | + |
| 4 | +namespace Microsoft.Maui.Controls.SourceGen.UnitTests; |
| 5 | + |
| 6 | +public class ResourceDictionary : SourceGenXamlInitializeComponentTestBase |
| 7 | +{ |
| 8 | + [Test] |
| 9 | + public void ResourceDictionaryWithoutXClass() |
| 10 | + { |
| 11 | + var xaml = |
| 12 | +""" |
| 13 | +<?xml version="1.0" encoding="utf-8" ?> |
| 14 | +<ResourceDictionary |
| 15 | + xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
| 16 | + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
| 17 | + xmlns:local="using:Microsoft.Maui.Controls.Xaml.UnitTests"> |
| 18 | + <Color x:Key="AccentColor">#FF4B14</Color> |
| 19 | +</ResourceDictionary> |
| 20 | +"""; |
| 21 | + var expected = |
| 22 | +""" |
| 23 | +
|
| 24 | +//------------------------------------------------------------------------------ |
| 25 | +// <auto-generated> |
| 26 | +// This code was generated by a .NET MAUI source generator. |
| 27 | +// |
| 28 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 29 | +// the code is regenerated. |
| 30 | +// </auto-generated> |
| 31 | +//------------------------------------------------------------------------------ |
| 32 | +#nullable enable |
| 33 | +
|
| 34 | +namespace __XamlGeneratedCode__; |
| 35 | +
|
| 36 | +public partial class __TypeDBD64C1C77CDA760 |
| 37 | +{ |
| 38 | + private partial void InitializeComponent() |
| 39 | + { |
| 40 | + var color = global::Microsoft.Maui.Graphics.Color.Parse("#FF4B14"); |
| 41 | + global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(color!, new global::System.Uri(@"Resources/Styles.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 6, 4); |
| 42 | + var __root = this; |
| 43 | + global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(__root!, new global::System.Uri(@"Resources/Styles.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 2, 2); |
| 44 | +#if !_MAUIXAML_SG_NAMESCOPE_DISABLE |
| 45 | + global::Microsoft.Maui.Controls.Internals.INameScope iNameScope = new global::Microsoft.Maui.Controls.Internals.NameScope(); |
| 46 | +#endif |
| 47 | + __root.Add("AccentColor", color); |
| 48 | + } |
| 49 | +} |
| 50 | +
|
| 51 | +"""; |
| 52 | + |
| 53 | + var (result, generated) = RunGenerator(xaml, "", path: System.IO.Path.Combine("Resources", "Styles.xaml")); |
| 54 | + Assert.IsFalse(result.Diagnostics.Any()); |
| 55 | + |
| 56 | + Assert.AreEqual(expected, generated); |
| 57 | + |
| 58 | + } |
| 59 | +} |
0 commit comments