Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Test and profile your Windows Phone 8 App

0 views

Published on

In this presentation i will give you a deep overview about Windows Phone 8 testing tool and how to profile and monitor your application performance.

Published in: Technology
  • Be the first to comment

Test and profile your Windows Phone 8 App

  1. 1. ___________________________________________________ Michele Capra Software Engineer @ OrangeCode
  2. 2. WP7 AppView and ViewModelWP7 Class LibraryTestSuite
  3. 3. public partial class MainPage : PhoneApplicationPage{ public MainPage() { InitializeComponent(); Content = UnitTestSystem.CreateTestPage(); }}
  4. 4. [TestClass]public class MainViewModelFixture{ private MainViewModel _viewModel; private Mock<IDbService> _service; public MainViewModelFixture() { _service= new Mock<IDbService>(); _viewModel= new MainViewModel(_service.Object); } [TestMethod] public void Initialize_Should_LoadDataFromDb() { _viewModel.Initialize(); _service.Verify(p=>p.LoadProducts()); }}
  5. 5. using Caliburn.Micro;using OrangeCode.Wpreborn.SQLIteApp.Services;namespace OrangeCode.Wpreborn.SQLIteApp.ViewModels{ public class MainViewModel :PropertyChangedBase { private readonly IDbService _service; public MainViewModel(IDbService service) { _service = service; } public void Initialize() { _service.LoadProducts(); } }}
  6. 6. [TestMethod] public void Initialize_Should_ShowData() { _service.Setup(p => p.LoadProducts()).Returns( new List<Product>{ new Product {Name = "Product 1", Serial ="123456"} } ); _viewModel.Initialize(); Assert.AreEqual(_viewModel.Products.Count,1); Assert.AreEqual(_viewModel.Products[0].Serial,"123456"); }
  7. 7. public class MainViewModel :PropertyChangedBase{ private readonly IDbService _service; public IList<Product> Products { get; set; } public MainViewModel(IDbService service) { _service = service; } public void Initialize() { Products=_service.LoadProducts(); }}
  8. 8. public interface IDbServiceAsync{ Task<IList<Product>> LoadProductsAsync();}public class DbServiceAsync :IDbServiceAsync{ private readonly SQLiteAsyncConnection _context; public DbService(SQLiteAsyncConnection context) { _context = context; } public async Task<IList<Product>> LoadProductsAsync() { return await _context.Table<Product>().ToListAsync(); }}
  9. 9. private async void PrepareDb(){ SQLiteAsyncConnection connection = new SQLiteAsyncConnection("TestDb.sqlite”); await connection.DropTableAsync<Product>(); await connection.CreateTableAsync<Product>(); await connection.InsertAsync(new Product { Name = "Product 1", Serial = "123456" });}[TestMethod]public async void LoadProductsAsync_Should_Load_Data_FromDb(){ await PrepareDb(); var data= await _service.LoadProductsAsync(); Assert.AreEqual(data.Count,1);}
  10. 10. Email : michele@orangecode.it Blog: www.orangecode.it/blogTwitter: @piccoloaiutante GitHub: github.com/piccoloaiutante

×