Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with template processing #26196

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Templates/src/templates/maui-mobile/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public static MauiApp CreateMauiApp()
.ConfigureSyncfusionToolkit()
.ConfigureMauiHandlers(handlers =>
{
//-:cnd:noEmit
#if IOS || MACCATALYST
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
#endif
//+:cnd:noEmit
})
#endif
.ConfigureFonts(fonts =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,18 @@ protected void EnableTizen(string projectFile)
{ "</TargetFrameworks> -->", "</TargetFrameworks>" },
});
}

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}'.");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

namespace Microsoft.Maui.IntegrationTests;

Expand Down Expand Up @@ -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<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();", programContents);
}
else
{
AssertDoesNotContain("#if IOS || MACCATALYST", programContents);
AssertDoesNotContain("handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();", programContents);
}
}
}
Loading