Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Jul 7, 2019
1 parent 523f5b2 commit e8b3e32
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 62 deletions.
25 changes: 13 additions & 12 deletions Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public class ShellLifeCycleTests : ShellTestBase
const string SectionRoute = "section";
const string ItemRoute = "item";


[Test]
public void AppearingOnCreate()
{
Shell shell = new Shell();
Shell shell = CreateShell();

FlyoutItem flyoutItem = new FlyoutItem();
Tab tab = new Tab();
Expand All @@ -43,7 +44,7 @@ public void AppearingOnCreate()
[Test]
public void AppearingOnCreateFromTemplate()
{
Shell shell = new Shell();
Shell shell = CreateShell();

FlyoutItem flyoutItem = new FlyoutItem();
Tab tab = new Tab();
Expand Down Expand Up @@ -83,7 +84,7 @@ public void AppearingOnCreateFromTemplate()
[Test]
public async Task NavigatedFiresAfterContentIsCreatedWhenUsingTemplate()
{
Shell shell = new Shell();
Shell shell = CreateShell();

FlyoutItem flyoutItem = new FlyoutItem();
Tab tab = new Tab();
Expand Down Expand Up @@ -128,7 +129,7 @@ public async Task NavigatedFiresAfterContentIsCreatedWhenUsingTemplate()
[Test]
public void AppearingOnShellContentChanged()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
var section = item.SearchForRoute<ShellSection>(SectionRoute);

Expand All @@ -155,7 +156,7 @@ public void AppearingOnShellContentChanged()
[Test]
public void AppearingOnShellSectionChanged()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
var section = item.SearchForRoute<ShellSection>(SectionRoute);
var newSection = CreateShellSection();
Expand Down Expand Up @@ -183,7 +184,7 @@ public void AppearingOnShellSectionChanged()
[Test]
public void AppearingOnShellItemChanged()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
var item2 = CreateShellItem();
shell.Items.Add(item2);
Expand Down Expand Up @@ -211,7 +212,7 @@ public void AppearingOnShellItemChanged()
[Test]
public async Task ShellPartWithModalPush()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
ShellLifeCycleState lifeCycleState = new ShellLifeCycleState(item);
shell.Items.Add(item);
Expand All @@ -229,7 +230,7 @@ public async Task ShellPartWithModalPush()
[Test]
public async Task ShellPartWithPagePush()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
ShellLifeCycleState lifeCycleState = new ShellLifeCycleState(item);
shell.Items.Add(item);
Expand Down Expand Up @@ -261,7 +262,7 @@ public async Task ShellPartWithPagePush()
[Test]
public async Task ShellPartWithPopToRoot()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
ShellLifeCycleState lifeCycleState = new ShellLifeCycleState(item);
shell.Items.Add(item);
Expand All @@ -285,7 +286,7 @@ public async Task ShellPartWithPopToRoot()
[Test]
public async Task PagePushModal()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
ShellLifeCycleState lifeCycleState = new ShellLifeCycleState(item);
shell.Items.Add(item);
Expand All @@ -309,7 +310,7 @@ public async Task PagePushModal()
[Test]
public async Task PagePush()
{
Shell shell = new Shell();
Shell shell = CreateShell();
var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);
shell.Items.Add(item);

Expand All @@ -330,7 +331,7 @@ public async Task PagePush()
public async Task OnNavigatedOnlyFiresOnce()
{
int navigated = 0;
Shell shell = new Shell();
Shell shell = CreateShell();
shell.Navigated += (_, __) =>
{
navigated++;
Expand Down
8 changes: 8 additions & 0 deletions Xamarin.Forms.Core.UnitTests/ShellTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace Xamarin.Forms.Core.UnitTests
[TestFixture]
public class ShellTestBase : BaseTestFixture
{

protected Shell CreateShell()
{
Shell returnValue = new Shell();
(returnValue as IShellController).Initialize();
return returnValue;
}

[SetUp]
public override void Setup()
{
Expand Down
58 changes: 29 additions & 29 deletions Xamarin.Forms.Core.UnitTests/ShellTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class ShellTests : ShellTestBase
[Test]
public void DefaultState()
{
var shell = new Shell();
Shell shell = CreateShell();

Assert.IsEmpty(shell.Items);
}

[Test]
public void CurrentItemAutoSets()
{
var shell = new Shell();
Shell shell = CreateShell();
var shellItem = new ShellItem();
var shellSection = new ShellSection();
var shellContent = new ShellContent { Content = new ContentPage() };
Expand All @@ -35,7 +35,7 @@ public void CurrentItemAutoSets()
[Test]
public void ShellChildrenBindingContext()
{
var shell = new Shell();
Shell shell = CreateShell();

var shellItem = CreateShellItem();
shell.Items.Add(shellItem);
Expand All @@ -53,7 +53,7 @@ public void ShellChildrenBindingContext()
[Test]
public void ShellPropagateBindingContextWhenAddingNewShellItem()
{
var shell = new Shell();
Shell shell = CreateShell();

shell.Items.Add(CreateShellItem());

Expand All @@ -71,7 +71,7 @@ public void ShellPropagateBindingContextWhenAddingNewShellItem()
[Test]
public void ShellPropagateBindingContextWhenAddingNewShellSection()
{
var shell = new Shell();
Shell shell = CreateShell();

shell.Items.Add(CreateShellItem());

Expand All @@ -88,7 +88,7 @@ public void ShellPropagateBindingContextWhenAddingNewShellSection()
[Test]
public void ShellPropagateBindingContextWhenAddingNewShellContent()
{
var shell = new Shell();
Shell shell = CreateShell();

shell.Items.Add(CreateShellItem());

Expand All @@ -104,7 +104,7 @@ public void ShellPropagateBindingContextWhenAddingNewShellContent()
[Test]
public void ShellPropagateBindingContextWhenChangingContent()
{
var shell = new Shell();
Shell shell = CreateShell();

shell.Items.Add(CreateShellItem());

Expand All @@ -119,7 +119,7 @@ public void ShellPropagateBindingContextWhenChangingContent()
[Test]
public async Task ShellPropagateBindingContextWhenPushingContent()
{
var shell = new Shell();
Shell shell = CreateShell();
shell.Items.Add(CreateShellItem());

object viewModel = new object();
Expand All @@ -134,7 +134,7 @@ public async Task ShellPropagateBindingContextWhenPushingContent()
public void NavigationProxyWireUpTest()
{
var page = new ContentPage();
var shell = new Shell();
Shell shell = CreateShell();
var shellItem = new ShellItem();
var shellSection = new ShellSection();
var shellContent = new ShellContent { Content = page };
Expand All @@ -153,7 +153,7 @@ public void NavigationProxyWireUpTest()
[Test]
public void CurrentItemDoesNotChangeOnSecondAdd()
{
var shell = new Shell();
Shell shell = CreateShell();
var shellItem = new ShellItem();
var shellSection = new ShellSection();
var shellContent = new ShellContent { Content = new ContentPage() };
Expand All @@ -171,7 +171,7 @@ public void CurrentItemDoesNotChangeOnSecondAdd()
[Test]
public void SimpleGoTo()
{
var shell = new Shell();
Shell shell = CreateShell();

var one = new ShellItem { Route = "one" };
var two = new ShellItem { Route = "two" };
Expand Down Expand Up @@ -304,7 +304,7 @@ public async Task RelativeGoTo()
[Test]
public async Task NavigationWithQueryStringWhenPageMatchesBindingContext()
{
var shell = new Shell();
Shell shell = CreateShell();

var one = new ShellItem { Route = "one" };
var two = new ShellItem { Route = "two" };
Expand Down Expand Up @@ -337,7 +337,7 @@ public async Task NavigationWithQueryStringWhenPageMatchesBindingContext()
[Test]
public async Task NavigationWithQueryStringThenWithoutQueryString()
{
var shell = new Shell();
Shell shell = CreateShell();

var one = new ShellItem { Route = "one" };
var two = new ShellItem { Route = "two" };
Expand Down Expand Up @@ -372,7 +372,7 @@ public async Task NavigationWithQueryStringThenWithoutQueryString()
[Test]
public async Task NavigationBetweenShellContentsPassesQueryString()
{
var shell = new Shell();
Shell shell = CreateShell();

var item = CreateShellItem(shellSectionRoute: "section2");
var content = CreateShellContent(shellContentRoute: "content");
Expand All @@ -395,7 +395,7 @@ public async Task NavigationBetweenShellContentsPassesQueryString()
[Test]
public async Task NavigationWithQueryStringAndNoDataTemplate()
{
var shell = new Shell();
Shell shell = CreateShell();

var one = new ShellItem { Route = "one" };
var two = new ShellItem { Route = "two" };
Expand All @@ -416,7 +416,7 @@ public async Task NavigationWithQueryStringAndNoDataTemplate()
[Test]
public void CancelNavigation()
{
var shell = new Shell();
Shell shell = CreateShell();

var one = new ShellItem { Route = "one" };
var two = new ShellItem { Route = "two" };
Expand Down Expand Up @@ -464,7 +464,7 @@ public void BackButtonBehaviorSet()
[Test]
public void FlyoutHeaderProjection()
{
var shell = new Shell();
Shell shell = CreateShell();

var label = new Label();

Expand Down Expand Up @@ -493,7 +493,7 @@ public void FlyoutHeaderProjection()
[Test]
public async Task FlyoutNavigateToImplicitContentPage()
{
var shell = new Shell();
Shell shell = CreateShell();
var shellITem = new ShellItem() { FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems, };
var shellSection = new ShellSection() { Title = "can navigate to" };
shellSection.Items.Add(new ContentPage());
Expand Down Expand Up @@ -525,7 +525,7 @@ public async Task FlyoutNavigateToImplicitContentPage()
[Test]
public async Task UriNavigationTests()
{
var shell = new Shell();
Shell shell = CreateShell();
var item1 = CreateShellItem(asImplicit: true, shellContentRoute: "rootlevelcontent1");
var item2 = CreateShellItem(asImplicit: true, shellContentRoute: "rootlevelcontent2");

Expand All @@ -542,7 +542,7 @@ public async Task UriNavigationTests()
[Test]
public async Task TitleViewBindingContext()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));
page.BindingContext = new { Text = "Binding" };
Expand All @@ -562,7 +562,7 @@ public async Task TitleViewBindingContext()
[Test]
public async Task VisualPropagationPageLevel()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));

Expand All @@ -584,7 +584,7 @@ public async Task VisualPropagationPageLevel()
[Test]
public async Task VisualPropagationShellLevel()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));

Expand All @@ -605,7 +605,7 @@ public async Task VisualPropagationShellLevel()
[Test]
public async Task FlyoutViewVisualPropagation()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));

Expand All @@ -625,7 +625,7 @@ public async Task FlyoutViewVisualPropagation()
[Test]
public async Task FlyoutViewBindingContext()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));
shell.BindingContext = new { Text = "Binding" };
Expand All @@ -647,7 +647,7 @@ public async Task FlyoutViewBindingContext()
[Test]
public void MenuItemBindingContext()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));
shell.BindingContext = new { Text = "Binding" };
Expand All @@ -671,7 +671,7 @@ public void MenuItemBindingContext()
[Test]
public async Task TitleViewLogicalChild()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));
page.BindingContext = new { Text = "Binding" };
Expand All @@ -691,7 +691,7 @@ public async Task TitleViewLogicalChild()
[Test]
public async Task FlyoutHeaderLogicalChild()
{
Shell shell = new Shell();
Shell shell = CreateShell();
ContentPage page = new ContentPage();
shell.Items.Add(CreateShellItem(page));

Expand Down Expand Up @@ -724,7 +724,7 @@ public async Task ImplicitDefaultPrefixForInstantiatedRoute()
[Test]
public async Task TabBarAutoCreation()
{
Shell shell = new Shell();
Shell shell = CreateShell();
shell.Items.Add(ShellItem.CreateFromShellSection(new Tab()));
shell.Items.Add(ShellItem.CreateFromShellSection(new Tab()));
shell.Items.Add(ShellItem.CreateFromShellSection(new Tab()));
Expand Down Expand Up @@ -766,7 +766,7 @@ public async Task TabBarAutoCreation()
public async Task NavigatedFiresAfterContentIsCreatedWhenUsingTemplate()
{

var shell = new Shell();
Shell shell = CreateShell();
var item1 = CreateShellItem(asImplicit: true, shellContentRoute: "rootlevelcontent1");

shell.Items.Add(item1);
Expand Down
Loading

0 comments on commit e8b3e32

Please sign in to comment.