diff --git a/src/Templates/src/templates/maui-mobile/MauiProgram.cs b/src/Templates/src/templates/maui-mobile/MauiProgram.cs index 3419fd4cd0f1..43dd1272843c 100644 --- a/src/Templates/src/templates/maui-mobile/MauiProgram.cs +++ b/src/Templates/src/templates/maui-mobile/MauiProgram.cs @@ -20,9 +20,11 @@ public static MauiApp CreateMauiApp() .ConfigureSyncfusionToolkit() .ConfigureMauiHandlers(handlers => { +//-:cnd:noEmit #if IOS || MACCATALYST handlers.AddHandler(); #endif +//+:cnd:noEmit }) #endif .ConfigureFonts(fonts => diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs index 2b3e48a62f87..5fb5048891f6 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs @@ -19,4 +19,18 @@ protected void EnableTizen(string projectFile) { " -->", "" }, }); } + + protected void AssertContains(string expected, string actual) + { + Assert.IsTrue( + actual.Contains(expected, StringComparison.Ordinal), + $"Expected string '{actual}' to contain '{expected}'."); + } + + protected void AssertDoesNotContain(string expected, string actual) + { + Assert.IsFalse( + actual.Contains(expected, StringComparison.Ordinal), + $"Expected string '{actual}' to not contain '{expected}'."); + } } diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs index 30db22f8093a..d23c63a76bd0 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs @@ -1,4 +1,4 @@ -using System.Xml.Linq; +using System.Xml.Linq; namespace Microsoft.Maui.IntegrationTests; @@ -329,4 +329,32 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: buildProps, msbuildWarningsAsErrors: true), $"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors."); } + + // This test is super temporary and is just for the interim + // while we productize the CollectionViewHandler2. Once we + // ship it as the default, this test will fail and can be deleted. + [Test] + [TestCase("maui", DotNetCurrent, "", false)] + [TestCase("maui", DotNetCurrent, "--sample-content", true)] + public void SampleShouldHaveHandler2Registered(string id, string framework, string additionalDotNetNewParams, bool shouldHaveHandler2) + { + var projectDir = TestDirectory; + var programFile = Path.Combine(projectDir, "MauiProgram.cs"); + + Assert.IsTrue(DotnetInternal.New(id, projectDir, framework, additionalDotNetNewParams), + $"Unable to create template {id}. Check test output for errors."); + + var programContents = File.ReadAllText(programFile); + + if (shouldHaveHandler2) + { + AssertContains("#if IOS || MACCATALYST", programContents); + AssertContains("handlers.AddHandler();", programContents); + } + else + { + AssertDoesNotContain("#if IOS || MACCATALYST", programContents); + AssertDoesNotContain("handlers.AddHandler();", programContents); + } + } }