SlideShare a Scribd company logo
1 of 33
___________________________________________________




                                              Michele Capra
                                              Software Engineer @ OrangeCode
WP7 App

View and ViewModel


WP7 Class Library



TestSuite
public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
        Content = UnitTestSystem.CreateTestPage();
    }
}
[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());
    }
}
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();
        }
    }
}
[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");
        }
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();
    }
}
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();
    }
}
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);
}
Email : michele@orangecode.it   Blog: www.orangecode.it/blog


Twitter: @piccoloaiutante       GitHub: github.com/piccoloaiutante

More Related Content

What's hot

Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptJon Kruger
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBOren Eini
 
Hibernate
Hibernate Hibernate
Hibernate Sunil OS
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩GDG Korea
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
White Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureWhite Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureShahzad
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...Shahzad
 

What's hot (20)

Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
Green dao
Green daoGreen dao
Green dao
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
 
Hibernate
Hibernate Hibernate
Hibernate
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
Green dao
Green daoGreen dao
Green dao
 
SOLID PRINCIPLES
SOLID PRINCIPLESSOLID PRINCIPLES
SOLID PRINCIPLES
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
ERRest
ERRestERRest
ERRest
 
White Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureWhite Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application Architecture
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
Servlets intro
Servlets introServlets intro
Servlets intro
 

Viewers also liked

Getting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testGetting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testMichele Capra
 
Biografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBiografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBryan100500
 
Mobile application
Mobile applicationMobile application
Mobile applicationenunmint
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.jsMichele Capra
 
Mobile application
Mobile applicationMobile application
Mobile applicationenunmint
 
Biografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBiografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBryan100500
 

Viewers also liked (6)

Getting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit testGetting started with Windows Phone 7 and unit test
Getting started with Windows Phone 7 and unit test
 
Biografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBiografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato b
 
Mobile application
Mobile applicationMobile application
Mobile application
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.js
 
Mobile application
Mobile applicationMobile application
Mobile application
 
Biografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato bBiografia bryan mena 1 bachillerato b
Biografia bryan mena 1 bachillerato b
 

Similar to Test and profile your Windows Phone 8 App

Présentation et bonnes pratiques du pattern MVVM - MIC Belgique
Présentation et bonnes pratiques du pattern MVVM - MIC BelgiquePrésentation et bonnes pratiques du pattern MVVM - MIC Belgique
Présentation et bonnes pratiques du pattern MVVM - MIC BelgiqueDenis Voituron
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudRoger Brinkley
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Eyal Vardi
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data BindingEric Maxwell
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java scriptÜrgo Ringo
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperGary Hockin
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutDror Helper
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC InternalsVitaly Baum
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutDror Helper
 
Model View Presenter presentation
Model View Presenter presentationModel View Presenter presentation
Model View Presenter presentationMichael Cameron
 

Similar to Test and profile your Windows Phone 8 App (20)

Présentation et bonnes pratiques du pattern MVVM - MIC Belgique
Présentation et bonnes pratiques du pattern MVVM - MIC BelgiquePrésentation et bonnes pratiques du pattern MVVM - MIC Belgique
Présentation et bonnes pratiques du pattern MVVM - MIC Belgique
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile Cloud
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you about
 
SOLID
SOLIDSOLID
SOLID
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Jsr 303
Jsr 303Jsr 303
Jsr 303
 
MVVM Lights
MVVM LightsMVVM Lights
MVVM Lights
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Solid angular
Solid angularSolid angular
Solid angular
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
 
Model View Presenter presentation
Model View Presenter presentationModel View Presenter presentation
Model View Presenter presentation
 

More from Michele Capra

Nodeschool italy at codemotion
Nodeschool italy at codemotionNodeschool italy at codemotion
Nodeschool italy at codemotionMichele Capra
 
Little bits & node.js IOT for beginner
Little bits & node.js IOT for beginnerLittle bits & node.js IOT for beginner
Little bits & node.js IOT for beginnerMichele Capra
 
Testing Windows Phone 8.1 app with unit test and Coded UI test
Testing Windows Phone 8.1 app with unit test and Coded UI testTesting Windows Phone 8.1 app with unit test and Coded UI test
Testing Windows Phone 8.1 app with unit test and Coded UI testMichele Capra
 
Porting business apps to Windows Phone
Porting business apps to Windows PhonePorting business apps to Windows Phone
Porting business apps to Windows PhoneMichele Capra
 
The magic of Dynamic in Nancy Fx
The magic of Dynamic in Nancy FxThe magic of Dynamic in Nancy Fx
The magic of Dynamic in Nancy FxMichele Capra
 
Windows Phone 7 Development
Windows Phone 7 DevelopmentWindows Phone 7 Development
Windows Phone 7 DevelopmentMichele Capra
 
My Final Dissertation
My Final DissertationMy Final Dissertation
My Final DissertationMichele Capra
 

More from Michele Capra (7)

Nodeschool italy at codemotion
Nodeschool italy at codemotionNodeschool italy at codemotion
Nodeschool italy at codemotion
 
Little bits & node.js IOT for beginner
Little bits & node.js IOT for beginnerLittle bits & node.js IOT for beginner
Little bits & node.js IOT for beginner
 
Testing Windows Phone 8.1 app with unit test and Coded UI test
Testing Windows Phone 8.1 app with unit test and Coded UI testTesting Windows Phone 8.1 app with unit test and Coded UI test
Testing Windows Phone 8.1 app with unit test and Coded UI test
 
Porting business apps to Windows Phone
Porting business apps to Windows PhonePorting business apps to Windows Phone
Porting business apps to Windows Phone
 
The magic of Dynamic in Nancy Fx
The magic of Dynamic in Nancy FxThe magic of Dynamic in Nancy Fx
The magic of Dynamic in Nancy Fx
 
Windows Phone 7 Development
Windows Phone 7 DevelopmentWindows Phone 7 Development
Windows Phone 7 Development
 
My Final Dissertation
My Final DissertationMy Final Dissertation
My Final Dissertation
 

Recently uploaded

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Test and profile your Windows Phone 8 App

  • 1. ___________________________________________________ Michele Capra Software Engineer @ OrangeCode
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. WP7 App View and ViewModel WP7 Class Library TestSuite
  • 7.
  • 8.
  • 9.
  • 10. public partial class MainPage : PhoneApplicationPage { public MainPage() { InitializeComponent(); Content = UnitTestSystem.CreateTestPage(); } }
  • 11.
  • 12.
  • 13.
  • 14. [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()); } }
  • 15.
  • 16. 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(); } } }
  • 17.
  • 18. [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"); }
  • 19. 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(); } }
  • 20.
  • 21. 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(); } }
  • 22. 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); }
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Email : michele@orangecode.it Blog: www.orangecode.it/blog Twitter: @piccoloaiutante GitHub: github.com/piccoloaiutante

Editor's Notes

  1. Dove eravamo con Windows Phone 7:- MS Test o nunit per il testing del codice- e per il mocking Moq 3.1 per silverlight
  2. Per eseguire le nostre suite di test avevamo a disposizionesvariati test runnerQui facciovederequello di resharper
  3. La strutturaclassicadella nostra soluzione era composta da:Applicazionecon View,VewiModel- Class library chereferenziavailprogettocontenente le test suite
  4. Eccocinelnuovomondo:grossicambiamenti, dal punto di vista del testinggestioneda parte dei test runner delle keyword async/awaitnecessitàdi eseguireilcodicenell&apos;emulatore o sul device
  5. Per risolverequestiprobelmivienerilasciato con il toolkit un test framework che due peculiaritàcheallostadioattuale e la via principe per potereseguire test su windows phone.- necessita del toolkit
  6. Con questostrumentocambianoperòanche le nostreabitudini di test:- la prima èche le nostre suite di test non sarannoospitate in una class library ma bensi in unavera a propriaappilcazione- purtroppoillanciodei test non saràpiùautomatico ma vedremoche ci sonodeibottoni- ma gestionaancheilcodiceasincrono
  7. refenziavia nuget la dll- nellamainpagedell&apos;applicazionedobbiamosettareil content con il content fornitodalladll in modo tale chesia poi lei a gestirel&apos;interfaccia
  8. Eccocome appareil test tools:Tags chepermetteevenutalmente di eseguiredelle suite di test specifiche e non di eseguiretuttii test di unaclasseun bottone play per lanciarei teste ilrisultatodei test dove ci sonoicontatoridei test e irisultati per suite
  9. Applicazionedi demo:- applicazione con un db e un viewmodelchedeve fare visualizzare la listadeiprodotti.- usatoildbengine di sqlite per fare unaversionepiùaggiornata- pattern MVVM per questaapplicazione per potertestaretuttoilcodice.
  10. Strutturadellesoluzione, come possiamovedere 2 vere e proprieapplicazioni per wp8 piùlinkatoil wrapper per usaresqlite- prima app vm e service e sqlite- utilizzo di caliburn.micro per vm framework- seconda app chereferenzia la prima con le relative fixture e referenziatoil toolkit test
  11. Facciamoil primo test: - moccarevuol dire creare un oggettofittiziocheimplemental&apos;interfaccia e tienecontodellechiamatechevengonoeffetuatedaimetodi- interfacciaidbservicechereperisceidati- viewmodel con metodo initialize chedeveeffettuare la chiamata la serivzio.- usiamomoq per moccarel&apos;interfaccia.
  12. Scriviamoilcodice per afrepassareil test:- nell&apos;initializecarichiamo la listadeidati- ilviewmodelderiva da propertyChangedbase per eriditarel&apos;impelemntazionie di caliburndellainotifypropertychanged.
  13. Green
  14. Secondo test:-vogliocheilvmmostriidatisulla vista e quindi mi aspettoche ci siaunalista products chedopoaverechiamatol&apos;initializemostriidati.- mocco la chiamata al servizio e mi aspettoche mi ritorniunalista di prodotti con un prodotto- verificoanchechel&apos;oggettoabbia le proprietàgiuste.
  15. Implementonelvm e facciogirarei test
  16. Green
  17. Implementonelservizio la chiamata a sqlite e verificochepassiil test:- mi faccioritornaretuttii record dellatabella Product da sqlite
  18. finoa qui codicesincrono, che in realtà in wp8 non girerebbeperchèl&apos;i/o e ildbvannogestiti in modoasincronoscriviamo la primitiva del serviziocheabbiamovisto prima in modoasincrono e facciamo un test di integrazione.prepare inserisceidatineldbNel test verifico la presenzadeidatiusandoasync await
  19. ----- Meeting Notes (1/27/13 16:57) -----ed ecco il risultato
  20. Io lo utilizzereisopratutto se uno ha giàscrittodelle suite di test per un&apos;app wp7 e vuoletenerle per l&apos;aggiornamento a wp8utile per fare dei test di integrazione e di regressione per vedere se spaccoqualcosamentresviluppo, ma non per fare unit test
  21. Come profilareun&apos;app? Tool in Visual Studio per profilare e monitorare.- monitoring : focus sulla user experience quindiresponsività e tempi di avvio- profiling: per veder le risorseusate come memoria e cpu.
  22. Potetetrovarlo sotto il menu di debug o con Alt +F1e presenta le due possibilitàchedicevamo prima:monitoring o profiling
  23. Applicazionedi esempiochecaricavolutamenteomoltegrosseimmagini in un controllo panorama.
  24. Facciamopartirel&apos;applicazioneediniziamo ad usarla. Quandoabbiamofinitoclicchiamosu End Session..
  25. E ci apparequesto report e possiamovedereche la responsività come potevamofacilmenteimmaginare ci vienedettoche non è molto buona. Vengofornitealtreinformazioni come - la memoriausata- la bandautilizzata- e il tempo di partenza
  26. - U sono le input gesture- prima banda frame rate dell&apos;applicazione- utilizzodellacpu- reposonsivitàdell&apos;app- utilizzodellabatteria- utilizzomemoria- notare la cpu a canna-&gt;frame rate basso, repsonsivitàbassa
  27. Giusto due consigliche mi permetto di darvi, ma solo perchè ci sonocascato:- per iviewmodel: implementarel&apos;idisposable e fare il dispose di tuttiglioggetticheavetenelvm e sganciarvi da tuttiglieventi a cui vi sietesottoscritti- per le visteusateil virtualizing stack panel per caricare solo glioggettiche vi servono, da valutarecaso per caso, perchè poi potresteavere un caricamento a scattidelleimmagini (spece se giàscaricate).
  28. Cosaabbiamovistooggi