Last active
January 10, 2017 14:58
-
-
Save jonathanpeppers/36228af4fae095c48985511548c2d3af to your computer and use it in GitHub Desktop.
Xamarin.Forms.Mocks examples
This file contains hidden or 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
//Dynamically load XAML | |
// NOTE: At the top, include using Xamarin.Forms.Xaml; | |
[Test] | |
public void LoadFromXaml() | |
{ | |
var label = new Label(); | |
label.LoadFromXaml("<Label Text=\"Woot\" />"); | |
Assert.AreEqual("Woot", label.Text); | |
} | |
//Unit test navigation | |
[Test] | |
public async Task Push() | |
{ | |
var root = new ContentPage(); | |
var page = new ContentPage(); | |
await root.Navigation.PushAsync(page); | |
Assert.AreEqual(root.Navigation.NavigationStack.Last(), page); | |
} | |
//Unit test animations | |
[Test] | |
public async Task FadeTo() | |
{ | |
var view = new BoxView(); | |
await view.FadeTo(0); | |
Assert.AreEqual(0, view.Opacity); | |
} | |
//Unit test a markup extension | |
[Test] | |
public void MarkupExtension() | |
{ | |
var label = new Label(); | |
label.LoadFromXaml("<Label xmlns:f=\"clr-namespace:Xamarin.Forms.Mocks.Tests;assembly=Xamarin.Forms.Mocks.Tests\" Text=\"{f:Terrible}\" />"); | |
Assert.AreEqual("2016", label.Text); //amirite? | |
} | |
//Here is the markup extension | |
public class TerribleExtension : IMarkupExtension<string> | |
{ | |
public string ProvideValue(IServiceProvider serviceProvider) | |
{ | |
return "2016"; | |
} | |
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) | |
{ | |
return ProvideValue(serviceProvider); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment