SlideShare una empresa de Scribd logo
1 de 24
www.orbitone.com
Raas van Gaverestraat 83
B-9000 GENT, BELGIUM
E-mail info@orbitone.com
Website www.orbitone.com
Tel. +32 9 330 15 00
VAT BE 456.457.353
Bank 442-7059001-50 (KBC)
Presenter: Wim Roegiers
28 April, 2010
Moles
28 April, 2010
Moles2
What
Moles can be used to detour any .NET method,
including non-virtual and static methods in sealed types.
28 April, 2010
Moles3
Why
Unit testing is great, but most free isolation frameworks require
that your mocks implement an interface.
But what do you do when the class you are trying to mock is
static or sealed with no interface ?
Moles, supports mocking almost any CLR based class (including
sealed and static classes) .
28 April, 2010
Moles4
How
It uses runtime instrumentation to inject callbacks in the
method MSIL bodies of the moled methods.
28 April, 2010
Moles5
When
Refactoring is the preferred method of isolation, because it
does not require runtime instrumentation.
However, refactoring is often not a choice—in which case,
runtime instrumentation might be the only solution.
e.g. with code that calls into the .NET framework, some third-
party or legacy stuff etc
28 April, 2010
Moles6
How to install ?
Visual Studio 2010 Moles - Isolation Framework for .NET
(Free)
http://visualstudiogallery.msdn.microsoft.com/en-
us/b3b41648-1c21-471f-a2b0-f76d8fb932ee
Latest version : v0.91.50418.0, 04/19/2010
28 April, 2010
Moles7
How to install – unexpected part 2
Everyting works fine except the part where I want to prepare
my Stubs and Moles. You need to create a new .moles file based
upon a new template called Moles and Stubs for Testing. the
only issue was … the template was nowhere to be found !
Solution :
It takes a while but after a few moments it is completed, now
open Visual Studio 2010 again and select your Moles and Stubs
for Testing template.
28 April, 2010
Moles8
Getting Started
If this is your first time with Moles, try the short Exploring Code
With Moles tutorial.
Also try the short Unit Testing with Moles tutorial.
To get an overview, read Getting Started with Moles.
Also useful
http://blogs.msdn.com/kristol/archive/2010/03/07/unit-
testing-with-microsoft-moles.aspx
28 April, 2010
Moles9
How to add moles to a project ?
Add reference to project
Add Moles Assembly with a single click.
The moles are generated, and a new dll is added to the
references.
Add atribute to the tests to detour to the moled dll’s :
HostType(“Moles”)
28 April, 2010
Moles10
filtering mechanism in .moles files
We do not always want all types to be moled, this is made
possible with a filtering mechanism.
You can define a filter in the .mole file :
28 April, 2010
Moles11
How does it look in visual studio
28 April, 2010
Moles12
NUnit
Since Moles needs the Pex profiler to work, you have to run this
NUnit test using Pex command line runner with NUnit console.
Example:
pex /runner:D:TOOLSnunit-console.exe Parser.UnitTests.dll
28 April, 2010
Moles13
Limitations
The current implementation of Moles has several limitations.
These limitations might be resolved in future releases :
The Moles framework supports only a limited number of
method signature—up to 10 arguments, where the last
argument can be an out or ref argument.
Method signatures with pointers are not supported.
28 April, 2010
Moles14
Mocks and Stubs
A stub can never fail a test.
A mock records things and then tells our test if it's expectations
have been met according to its recording.
28 April, 2010
Moles15
Stub Types.
Stub Types. A stub of the type T provides a default
implementation of each virtual member of T—that is, virtual or
abstract methods, properties, and events. The default behavior
can be dynamically customized for each member
Although stub types can be generated for interfaces and non-
sealed classes with overridable methods, they cannot be used
for static or non-overridable methods.
28 April, 2010
Moles16
Mole Types
A mole of type T can provide an alternative implementation for
each non-abstract member of T. The Moles framework will
redirect method calls to members of T to the alternative mole
implementation.
28 April, 2010
Moles17
Delegates
Both stub types and mole types allow using delegates to
dynamically customize the behavior of individual stub
members.
Moles is a very lightweight framework; it does not provide
advanced declarative verification features found in other mock
frameworks, such as Moq, Rhino Mocks, NMock, or Isolator.
28 April, 2010
Moles18
Stubs - Lightweight Test Stubs for .NET
Stubs is a lightweight framework for .NET that provides test
stubs.
For interfaces and non-sealed classes, type-safe wrappers are
generated that can be easily customized by attaching delegates.
Stubs are part of Moles.
28 April, 2010
Moles19
Naming Conventions
 Types
Methods
Properties
Interfaces
Foo -> MFoo
void Foo(string v) -> FooString
string Value {get;} -> ValueGet
IFoo -> SIFoo
28 April, 2010
Moles20
Moling Interfaces
 The moles generator will create stub types for any .net interface
 public interface IFileSystem
{
string ReadAllText(string fileName);
}
 Generates - >
28 April, 2010
Moles21
No dependency injection necessary
public class OrderService : IOrderService
{
public int AddOrder(Order order)
{
// Save order using Order Repository
var repository = new OrderRepository();
return repository.SaveOrder(order);
}
[TestMethod]
[HostType("Moles")]
public void CanAddOrderWithoutMole()
{
MOrderRepository.AllInstances.SaveOrderOrder = (r, o) =>
{
// Increase counter to be sure of how many times
// our implementation of SaveOrder gets called
callesToSaveOrder++;
// Customer name should be the one we provided
Assert.AreEqual("Test Customer", o.CustomerName);
// Order date should be the 2010-03-07 14:20:00, because
// we just replaced the implementation of DateTime.Now
Assert.AreEqual(new DateTime(2010, 03, 07, 14, 20, 0), o.OrderDate);
// Allways return 42 as OrderID
return 42;
};
28 April, 2010
Moles22
Demos
Some simple examples in visual studio 2010
28 April, 2010
Moles23
Resources
 http://research.microsoft.com/en-us/projects/moles/
 http://martinfowler.com/articles/mocksArentStubs.html
 http://research.microsoft.com/en-us/projects/pex/molestutorial.pdf
 http://research.microsoft.com/en-us/projects/pex/stubstutorial.pdf
 Rufus meets Jimmy @ http://www.invalidcast.com/post/Moles-Dig-It.aspx
 http://blogs.msdn.com/kristol/archive/2010/03/07/unit-testing-with-microsoft-
moles.aspx
 http://geekswithblogs.net/thomasweller/archive/2010/04/28/mocking-the-unmockable-
using-microsoft-moles-with-gallio.aspx
www.orbitone.com
24 Moles
28 April, 2010

Más contenido relacionado

Destacado

Buddhism Assessment And Levels
Buddhism Assessment And LevelsBuddhism Assessment And Levels
Buddhism Assessment And Levelst0nywilliams
 
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...akasaka aoyama
 
Evaluation question 3
Evaluation question 3Evaluation question 3
Evaluation question 3Reece Howard
 
Разработка современной электроники с прицелом на массовый выпуск. Почем?
Разработка современной электроники с прицелом на массовый выпуск. Почем?Разработка современной электроники с прицелом на массовый выпуск. Почем?
Разработка современной электроники с прицелом на массовый выпуск. Почем?Ingria. Technopark St. Petersburg
 
Science Advising in Entertainment
Science Advising in EntertainmentScience Advising in Entertainment
Science Advising in EntertainmentJovana Grbic
 
Open Days Ingria "Коротко о коммуникациях"
Open Days Ingria "Коротко о коммуникациях"Open Days Ingria "Коротко о коммуникациях"
Open Days Ingria "Коротко о коммуникациях"Ingria. Technopark St. Petersburg
 
Dok Spetterweek 2008
Dok Spetterweek 2008Dok Spetterweek 2008
Dok Spetterweek 2008guest636e0b
 
Mongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara AB
 
Interesting Phenomena From The Outside Of The Research
Interesting Phenomena From The Outside Of The ResearchInteresting Phenomena From The Outside Of The Research
Interesting Phenomena From The Outside Of The Researchdigitalschema
 
Yedirenk THM korosu Resimleri
Yedirenk THM korosu ResimleriYedirenk THM korosu Resimleri
Yedirenk THM korosu Resimleriaokutur
 
KAYA KARATAS 26 02 2015 ckm konseri
KAYA KARATAS 26 02 2015 ckm konseriKAYA KARATAS 26 02 2015 ckm konseri
KAYA KARATAS 26 02 2015 ckm konseriaokutur
 
Daniel's Family Tree
Daniel's Family TreeDaniel's Family Tree
Daniel's Family TreeAnna Donskoy
 
How To Navigate
How To NavigateHow To Navigate
How To NavigateMCDFS
 
Никита Цуканов рассказал, как нужно учиться на чужих ошибках
Никита Цуканов рассказал, как нужно учиться на чужих ошибкахНикита Цуканов рассказал, как нужно учиться на чужих ошибках
Никита Цуканов рассказал, как нужно учиться на чужих ошибкахIngria. Technopark St. Petersburg
 
technorati
technoratitechnorati
technoratiFELIX75
 
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013aokutur
 

Destacado (20)

Buddhism Assessment And Levels
Buddhism Assessment And LevelsBuddhism Assessment And Levels
Buddhism Assessment And Levels
 
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...
News For Banks - Sep 2008 - UBS Blue Sea Index - Freight Derivatives - ilija ...
 
Obhajoba
ObhajobaObhajoba
Obhajoba
 
Maya entertainment 3 2 11
Maya entertainment 3 2 11Maya entertainment 3 2 11
Maya entertainment 3 2 11
 
Evaluation question 3
Evaluation question 3Evaluation question 3
Evaluation question 3
 
Разработка современной электроники с прицелом на массовый выпуск. Почем?
Разработка современной электроники с прицелом на массовый выпуск. Почем?Разработка современной электроники с прицелом на массовый выпуск. Почем?
Разработка современной электроники с прицелом на массовый выпуск. Почем?
 
Science Advising in Entertainment
Science Advising in EntertainmentScience Advising in Entertainment
Science Advising in Entertainment
 
Open Days Ingria "Коротко о коммуникациях"
Open Days Ingria "Коротко о коммуникациях"Open Days Ingria "Коротко о коммуникациях"
Open Days Ingria "Коротко о коммуникациях"
 
Ring Tail Lemur
Ring Tail LemurRing Tail Lemur
Ring Tail Lemur
 
Dok Spetterweek 2008
Dok Spetterweek 2008Dok Spetterweek 2008
Dok Spetterweek 2008
 
Mongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders Lindh
 
Interesting Phenomena From The Outside Of The Research
Interesting Phenomena From The Outside Of The ResearchInteresting Phenomena From The Outside Of The Research
Interesting Phenomena From The Outside Of The Research
 
Yedirenk THM korosu Resimleri
Yedirenk THM korosu ResimleriYedirenk THM korosu Resimleri
Yedirenk THM korosu Resimleri
 
KAYA KARATAS 26 02 2015 ckm konseri
KAYA KARATAS 26 02 2015 ckm konseriKAYA KARATAS 26 02 2015 ckm konseri
KAYA KARATAS 26 02 2015 ckm konseri
 
Daniel's Family Tree
Daniel's Family TreeDaniel's Family Tree
Daniel's Family Tree
 
How To Navigate
How To NavigateHow To Navigate
How To Navigate
 
Никита Цуканов рассказал, как нужно учиться на чужих ошибках
Никита Цуканов рассказал, как нужно учиться на чужих ошибкахНикита Цуканов рассказал, как нужно учиться на чужих ошибках
Никита Цуканов рассказал, как нужно учиться на чужих ошибках
 
technorati
technoratitechnorati
technorati
 
Electonic tongue
Electonic tongueElectonic tongue
Electonic tongue
 
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013
TRT Müzikte Fikrimin İnce Gülü programı resimleri 03_11_2013
 

Similar a Mocking the unmockable with Moles

TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)
TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)
TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)TOAST_NHNent
 
Feature Bits at LSSC10
Feature  Bits at LSSC10Feature  Bits at LSSC10
Feature Bits at LSSC10Erik Sowa
 
Testing mule
Testing   muleTesting   mule
Testing muleSindhu VL
 
Mule testing
Mule   testingMule   testing
Mule testingSindhu VL
 
Teams and monoliths - Matthew Skelton - London DevOps June 2017
Teams and monoliths - Matthew Skelton - London DevOps June 2017Teams and monoliths - Matthew Skelton - London DevOps June 2017
Teams and monoliths - Matthew Skelton - London DevOps June 2017Skelton Thatcher Consulting Ltd
 
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)Brian Brazil
 
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSEMODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSEAnže Vodovnik
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design PatternsSteven Smith
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Grzegorz Miejski
 
Metacello
MetacelloMetacello
MetacelloESUG
 
Wireless Communication Network Communication
Wireless Communication Network CommunicationWireless Communication Network Communication
Wireless Communication Network CommunicationVrushali Lanjewar
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhDAlbanLevy
 
24 33 -_metasploit
24 33 -_metasploit24 33 -_metasploit
24 33 -_metasploitwozgeass
 
Return of the monolith
Return of the monolith Return of the monolith
Return of the monolith Alper Hankendi
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Return on Intelligence
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsAhmad Kazemi
 

Similar a Mocking the unmockable with Moles (20)

Metacello
MetacelloMetacello
Metacello
 
TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)
TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)
TOAST Meetup2015 - TOAST Cloud XaaS framework architecture (문지응)
 
Feature Bits at LSSC10
Feature  Bits at LSSC10Feature  Bits at LSSC10
Feature Bits at LSSC10
 
Testing mule
Testing   muleTesting   mule
Testing mule
 
Mule testing
Mule   testingMule   testing
Mule testing
 
Metasploit
MetasploitMetasploit
Metasploit
 
Teams and monoliths - Matthew Skelton - London DevOps June 2017
Teams and monoliths - Matthew Skelton - London DevOps June 2017Teams and monoliths - Matthew Skelton - London DevOps June 2017
Teams and monoliths - Matthew Skelton - London DevOps June 2017
 
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
 
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSEMODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
 
An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019
 
ALT
ALTALT
ALT
 
Metacello
MetacelloMetacello
Metacello
 
Wireless Communication Network Communication
Wireless Communication Network CommunicationWireless Communication Network Communication
Wireless Communication Network Communication
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
 
24 33 -_metasploit
24 33 -_metasploit24 33 -_metasploit
24 33 -_metasploit
 
Return of the monolith
Return of the monolith Return of the monolith
Return of the monolith
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
 

Más de Orbit One - We create coherence

ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...Orbit One - We create coherence
 
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...Orbit One - We create coherence
 
ShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeOrbit One - We create coherence
 
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...Orbit One - We create coherence
 
OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...Orbit One - We create coherence
 
Social Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsSocial Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsOrbit One - We create coherence
 
Marketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsMarketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsOrbit One - We create coherence
 

Más de Orbit One - We create coherence (20)

ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
 
HoGent tips and tricks van een self-made ondernemer
HoGent tips and tricks van een self-made ondernemer HoGent tips and tricks van een self-made ondernemer
HoGent tips and tricks van een self-made ondernemer
 
Het Nieuwe Werken in de praktijk
Het Nieuwe Werkenin de praktijkHet Nieuwe Werkenin de praktijk
Het Nieuwe Werken in de praktijk
 
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
 
ShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgrade
 
ShareCafé 2 - Werk slimmer door geïntegreerde tools
ShareCafé 2 - Werk slimmer door geïntegreerde toolsShareCafé 2 - Werk slimmer door geïntegreerde tools
ShareCafé 2 - Werk slimmer door geïntegreerde tools
 
ShareCafé 1: Hou de Nieuwe Werker gemotiveerd
ShareCafé 1: Hou de Nieuwe Werker gemotiveerdShareCafé 1: Hou de Nieuwe Werker gemotiveerd
ShareCafé 1: Hou de Nieuwe Werker gemotiveerd
 
Business value of Lync integrations
Business value of Lync integrationsBusiness value of Lync integrations
Business value of Lync integrations
 
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
 
Identity in the cloud using Microsoft
Identity in the cloud using MicrosoftIdentity in the cloud using Microsoft
Identity in the cloud using Microsoft
 
OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...
 
OneCafé: The new world of work and your organisation
OneCafé: The new world of work and your organisationOneCafé: The new world of work and your organisation
OneCafé: The new world of work and your organisation
 
Social Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsSocial Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefits
 
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
 
Wie is Orbit One Internet Solutions
Wie is Orbit One Internet SolutionsWie is Orbit One Internet Solutions
Wie is Orbit One Internet Solutions
 
Azure Umbraco workshop
Azure Umbraco workshopAzure Umbraco workshop
Azure Umbraco workshop
 
Marketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsMarketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensions
 
Office 365, is cloud right for your company?
Office 365, is cloud right for your company?Office 365, is cloud right for your company?
Office 365, is cloud right for your company?
 
Who is Orbit One internet solutions?
Who is Orbit One internet solutions?Who is Orbit One internet solutions?
Who is Orbit One internet solutions?
 
Azure and Umbraco CMS
Azure and Umbraco CMSAzure and Umbraco CMS
Azure and Umbraco CMS
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Mocking the unmockable with Moles

  • 1. www.orbitone.com Raas van Gaverestraat 83 B-9000 GENT, BELGIUM E-mail info@orbitone.com Website www.orbitone.com Tel. +32 9 330 15 00 VAT BE 456.457.353 Bank 442-7059001-50 (KBC) Presenter: Wim Roegiers 28 April, 2010 Moles
  • 2. 28 April, 2010 Moles2 What Moles can be used to detour any .NET method, including non-virtual and static methods in sealed types.
  • 3. 28 April, 2010 Moles3 Why Unit testing is great, but most free isolation frameworks require that your mocks implement an interface. But what do you do when the class you are trying to mock is static or sealed with no interface ? Moles, supports mocking almost any CLR based class (including sealed and static classes) .
  • 4. 28 April, 2010 Moles4 How It uses runtime instrumentation to inject callbacks in the method MSIL bodies of the moled methods.
  • 5. 28 April, 2010 Moles5 When Refactoring is the preferred method of isolation, because it does not require runtime instrumentation. However, refactoring is often not a choice—in which case, runtime instrumentation might be the only solution. e.g. with code that calls into the .NET framework, some third- party or legacy stuff etc
  • 6. 28 April, 2010 Moles6 How to install ? Visual Studio 2010 Moles - Isolation Framework for .NET (Free) http://visualstudiogallery.msdn.microsoft.com/en- us/b3b41648-1c21-471f-a2b0-f76d8fb932ee Latest version : v0.91.50418.0, 04/19/2010
  • 7. 28 April, 2010 Moles7 How to install – unexpected part 2 Everyting works fine except the part where I want to prepare my Stubs and Moles. You need to create a new .moles file based upon a new template called Moles and Stubs for Testing. the only issue was … the template was nowhere to be found ! Solution : It takes a while but after a few moments it is completed, now open Visual Studio 2010 again and select your Moles and Stubs for Testing template.
  • 8. 28 April, 2010 Moles8 Getting Started If this is your first time with Moles, try the short Exploring Code With Moles tutorial. Also try the short Unit Testing with Moles tutorial. To get an overview, read Getting Started with Moles. Also useful http://blogs.msdn.com/kristol/archive/2010/03/07/unit- testing-with-microsoft-moles.aspx
  • 9. 28 April, 2010 Moles9 How to add moles to a project ? Add reference to project Add Moles Assembly with a single click. The moles are generated, and a new dll is added to the references. Add atribute to the tests to detour to the moled dll’s : HostType(“Moles”)
  • 10. 28 April, 2010 Moles10 filtering mechanism in .moles files We do not always want all types to be moled, this is made possible with a filtering mechanism. You can define a filter in the .mole file :
  • 11. 28 April, 2010 Moles11 How does it look in visual studio
  • 12. 28 April, 2010 Moles12 NUnit Since Moles needs the Pex profiler to work, you have to run this NUnit test using Pex command line runner with NUnit console. Example: pex /runner:D:TOOLSnunit-console.exe Parser.UnitTests.dll
  • 13. 28 April, 2010 Moles13 Limitations The current implementation of Moles has several limitations. These limitations might be resolved in future releases : The Moles framework supports only a limited number of method signature—up to 10 arguments, where the last argument can be an out or ref argument. Method signatures with pointers are not supported.
  • 14. 28 April, 2010 Moles14 Mocks and Stubs A stub can never fail a test. A mock records things and then tells our test if it's expectations have been met according to its recording.
  • 15. 28 April, 2010 Moles15 Stub Types. Stub Types. A stub of the type T provides a default implementation of each virtual member of T—that is, virtual or abstract methods, properties, and events. The default behavior can be dynamically customized for each member Although stub types can be generated for interfaces and non- sealed classes with overridable methods, they cannot be used for static or non-overridable methods.
  • 16. 28 April, 2010 Moles16 Mole Types A mole of type T can provide an alternative implementation for each non-abstract member of T. The Moles framework will redirect method calls to members of T to the alternative mole implementation.
  • 17. 28 April, 2010 Moles17 Delegates Both stub types and mole types allow using delegates to dynamically customize the behavior of individual stub members. Moles is a very lightweight framework; it does not provide advanced declarative verification features found in other mock frameworks, such as Moq, Rhino Mocks, NMock, or Isolator.
  • 18. 28 April, 2010 Moles18 Stubs - Lightweight Test Stubs for .NET Stubs is a lightweight framework for .NET that provides test stubs. For interfaces and non-sealed classes, type-safe wrappers are generated that can be easily customized by attaching delegates. Stubs are part of Moles.
  • 19. 28 April, 2010 Moles19 Naming Conventions  Types Methods Properties Interfaces Foo -> MFoo void Foo(string v) -> FooString string Value {get;} -> ValueGet IFoo -> SIFoo
  • 20. 28 April, 2010 Moles20 Moling Interfaces  The moles generator will create stub types for any .net interface  public interface IFileSystem { string ReadAllText(string fileName); }  Generates - >
  • 21. 28 April, 2010 Moles21 No dependency injection necessary public class OrderService : IOrderService { public int AddOrder(Order order) { // Save order using Order Repository var repository = new OrderRepository(); return repository.SaveOrder(order); } [TestMethod] [HostType("Moles")] public void CanAddOrderWithoutMole() { MOrderRepository.AllInstances.SaveOrderOrder = (r, o) => { // Increase counter to be sure of how many times // our implementation of SaveOrder gets called callesToSaveOrder++; // Customer name should be the one we provided Assert.AreEqual("Test Customer", o.CustomerName); // Order date should be the 2010-03-07 14:20:00, because // we just replaced the implementation of DateTime.Now Assert.AreEqual(new DateTime(2010, 03, 07, 14, 20, 0), o.OrderDate); // Allways return 42 as OrderID return 42; };
  • 22. 28 April, 2010 Moles22 Demos Some simple examples in visual studio 2010
  • 23. 28 April, 2010 Moles23 Resources  http://research.microsoft.com/en-us/projects/moles/  http://martinfowler.com/articles/mocksArentStubs.html  http://research.microsoft.com/en-us/projects/pex/molestutorial.pdf  http://research.microsoft.com/en-us/projects/pex/stubstutorial.pdf  Rufus meets Jimmy @ http://www.invalidcast.com/post/Moles-Dig-It.aspx  http://blogs.msdn.com/kristol/archive/2010/03/07/unit-testing-with-microsoft- moles.aspx  http://geekswithblogs.net/thomasweller/archive/2010/04/28/mocking-the-unmockable- using-microsoft-moles-with-gallio.aspx