Created
June 18, 2014 02:32
-
-
Save rid00z/67c1fe6c6eb20a37a681 to your computer and use it in GitHub Desktop.
A example of a test for a Xamarin.Forms App with Mvvm
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
[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