From a1aec441e4f199ddc346a38a47841137576bce7f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 28 Nov 2024 13:12:11 +0200 Subject: [PATCH 1/6] Fix issue with template processing The template is processing the actual code --- src/Templates/src/templates/maui-mobile/MauiProgram.cs | 2 ++ 1 file changed, 2 insertions(+) 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 => From 4e967432bd710ddecf8e3d0d27df328d354b0b83 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 2 Dec 2024 23:31:23 +0800 Subject: [PATCH 2/6] Added a test --- .../BaseTemplateTests.cs | 7 +++++++ .../SimpleTemplateTest.cs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs index 2b3e48a62f87..02e9fc6ba3ae 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs @@ -19,4 +19,11 @@ 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}'."); + } } diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs index 30db22f8093a..798af19a24b2 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs @@ -329,4 +329,21 @@ 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."); } + + [Test] + [TestCase("maui", DotNetCurrent, "")] + [TestCase("maui", DotNetCurrent, "--sample-content")] + public void Build(string id, string framework, string additionalDotNetNewParams) + { + 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); + AssertContains("#if IOS || MACCATALYST", programContents); + AssertContains("handlers.AddHandler();", programContents); + AssertContains("#endif", programContents); + } } From 16c77f8485cc335694271925a3579a7981b1f5dc Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 10 Jan 2025 18:07:50 +0800 Subject: [PATCH 3/6] Fix the tests --- .../BaseTemplateTests.cs | 7 ++++++ .../SimpleTemplateTest.cs | 24 +++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs index 02e9fc6ba3ae..5fb5048891f6 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/BaseTemplateTests.cs @@ -26,4 +26,11 @@ protected void AssertContains(string expected, string actual) 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 798af19a24b2..3e888e9c1923 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; @@ -331,9 +331,9 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis } [Test] - [TestCase("maui", DotNetCurrent, "")] - [TestCase("maui", DotNetCurrent, "--sample-content")] - public void Build(string id, string framework, string additionalDotNetNewParams) + [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"); @@ -342,8 +342,18 @@ public void Build(string id, string framework, string additionalDotNetNewParams) $"Unable to create template {id}. Check test output for errors."); var programContents = File.ReadAllText(programFile); - AssertContains("#if IOS || MACCATALYST", programContents); - AssertContains("handlers.AddHandler();", programContents); - AssertContains("#endif", programContents); + + if (shouldHaveHandler2) + { + AssertContains("#if IOS || MACCATALYST", programContents); + AssertContains("handlers.AddHandler();", programContents); + AssertContains("#endif", programContents); + } + else + { + AssertDoesNotContain("#if IOS || MACCATALYST", programContents); + AssertDoesNotContain("handlers.AddHandler();", programContents); + AssertDoesNotContain("#endif", programContents); + } } } From 21231a03f7111a415c8923e5c5ff6d0215b7a65d Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 10 Jan 2025 18:10:01 +0800 Subject: [PATCH 4/6] Add temporary test for CollectionViewHandler2 --- .../src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs index 3e888e9c1923..69ff7a0c67dd 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs @@ -312,6 +312,9 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis $"Unable to create template {id}. Check test output for errors."); EnableTizen(projectFile); + // 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. FileUtilities.ReplaceInFile(projectFile, $"1.0", $"{display}"); From 49b64dba0be311c9a718c84448a40a62bb168cac Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 10 Jan 2025 18:11:01 +0800 Subject: [PATCH 5/6] Move temporary test comment to correct location --- .../Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs index 69ff7a0c67dd..9e01093f74df 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs @@ -312,9 +312,6 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis $"Unable to create template {id}. Check test output for errors."); EnableTizen(projectFile); - // 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. FileUtilities.ReplaceInFile(projectFile, $"1.0", $"{display}"); @@ -333,6 +330,9 @@ public void BuildWithDifferentVersionNumber(string id, string config, string dis $"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)] From 684681d0fb32845696cab67f28ba03d7ffcde484 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 10 Jan 2025 19:45:19 +0800 Subject: [PATCH 6/6] Remove redundant `#endif` assertions in tests --- .../src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs index 9e01093f74df..d23c63a76bd0 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/SimpleTemplateTest.cs @@ -350,13 +350,11 @@ public void SampleShouldHaveHandler2Registered(string id, string framework, stri { AssertContains("#if IOS || MACCATALYST", programContents); AssertContains("handlers.AddHandler();", programContents); - AssertContains("#endif", programContents); } else { AssertDoesNotContain("#if IOS || MACCATALYST", programContents); AssertDoesNotContain("handlers.AddHandler();", programContents); - AssertDoesNotContain("#endif", programContents); } } }