Skip to content

Instantly share code, notes, and snippets.

@rid00z
Created June 18, 2014 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rid00z/67c1fe6c6eb20a37a681 to your computer and use it in GitHub Desktop.
Save rid00z/67c1fe6c6eb20a37a681 to your computer and use it in GitHub Desktop.
A example of a test for a Xamarin.Forms App with Mvvm
[TestFixture]
public class ContactPageModelTests
{
[Test]
public static void CreateNewContact()
{
var container = A.Fake<IRootNavigation> ();
TinyIoC.TinyIoCContainer.Current.Register<IRootNavigation> (container);
var db = new DatabaseService (new SQLiteFactory());
var vm = new ContactPageModel (db);
vm.Init (null);
//save to database
vm.Contact.Name = "Peter";
vm.Contact.Phone = "9087";
vm.Done.Execute (null);
Assert.IsTrue (vm.Contact.ContactId > 0);
//get from database
var savedContact
= db.Conn.Table<Contact> ().Where ((c) => c.ContactId == vm.Contact.ContactId).FirstOrDefault ();
Assert.AreEqual ("Peter", savedContact.Name);
Assert.AreEqual ("9087", savedContact.Phone);
A.CallTo (() => container.PopPage ()).MustHaveHappened ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment