This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shell] refactor of processing uris (#5852)
fixes #5790
- Loading branch information
Showing
17 changed files
with
1,500 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ShellTestBase : BaseTestFixture | ||
{ | ||
[SetUp] | ||
public override void Setup() | ||
{ | ||
Device.SetFlags(new[] { Shell.ShellExperimental }); | ||
base.Setup(); | ||
|
||
} | ||
|
||
[TearDown] | ||
public override void TearDown() | ||
{ | ||
base.TearDown(); | ||
|
||
} | ||
|
||
protected Uri CreateUri(string uri) => new Uri(uri, UriKind.RelativeOrAbsolute); | ||
|
||
protected ShellSection MakeSimpleShellSection(string route, string contentRoute) | ||
{ | ||
return MakeSimpleShellSection(route, contentRoute, new ShellTestPage()); | ||
} | ||
|
||
protected ShellSection MakeSimpleShellSection(string route, string contentRoute, ContentPage contentPage) | ||
{ | ||
var shellSection = new ShellSection(); | ||
shellSection.Route = route; | ||
var shellContent = new ShellContent { Content = contentPage, Route = contentRoute }; | ||
shellSection.Items.Add(shellContent); | ||
return shellSection; | ||
} | ||
|
||
[QueryProperty("SomeQueryParameter", "SomeQueryParameter")] | ||
public class ShellTestPage : ContentPage | ||
{ | ||
public string SomeQueryParameter { get; set; } | ||
} | ||
|
||
protected ShellItem CreateShellItem(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null, string shellSectionRoute = null, string shellItemRoute = null) | ||
{ | ||
page = page ?? new ContentPage(); | ||
ShellItem item = null; | ||
var section = CreateShellSection(page, asImplicit, shellContentRoute, shellSectionRoute); | ||
|
||
if (!String.IsNullOrWhiteSpace(shellItemRoute)) | ||
{ | ||
item = new ShellItem(); | ||
item.Route = shellItemRoute; | ||
item.Items.Add(section); | ||
} | ||
else if (asImplicit) | ||
item = ShellItem.CreateFromShellSection(section); | ||
else | ||
{ | ||
item = new ShellItem(); | ||
item.Items.Add(section); | ||
} | ||
|
||
return item; | ||
} | ||
|
||
protected ShellSection CreateShellSection(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null, string shellSectionRoute = null) | ||
{ | ||
var content = CreateShellContent(page, asImplicit, shellContentRoute); | ||
|
||
ShellSection section = null; | ||
|
||
if (!String.IsNullOrWhiteSpace(shellSectionRoute)) | ||
{ | ||
section = new ShellSection(); | ||
section.Route = shellSectionRoute; | ||
section.Items.Add(content); | ||
} | ||
else if (asImplicit) | ||
section = ShellSection.CreateFromShellContent(content); | ||
else | ||
{ | ||
section = new ShellSection(); | ||
section.Items.Add(content); | ||
} | ||
|
||
return section; | ||
} | ||
|
||
protected ShellContent CreateShellContent(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null) | ||
{ | ||
page = page ?? new ContentPage(); | ||
ShellContent content = null; | ||
|
||
if(!String.IsNullOrWhiteSpace(shellContentRoute)) | ||
{ | ||
content = new ShellContent() { Content = page }; | ||
content.Route = shellContentRoute; | ||
} | ||
else if (asImplicit) | ||
content = (ShellContent)page; | ||
else | ||
content = new ShellContent() { Content = page }; | ||
|
||
|
||
return content; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.