Skip to content

modulexcite/PCLMock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

PCLMock

What?

PCLMock is a simple mocking framework in a Portable Class Library. The PCL targets a wide range of platforms including:

  • .NET 4.5
  • Windows 8
  • Windows Store
  • Windows Phone 8
  • Xamarin iOS
  • Xamarin Android

Why?

Existing mocking frameworks, such as Moq, do not work on platforms running a limited subset of the .NET framework. Writing mocks without the aid of a framework is laborious, error-prone, and results in inconsistent code. PCLMock aims to reduce this pain.

Where?

The easiest way to get PCLMock is via NuGet:

Install-Package PCLMock

There are also packages specific to code generation.

How?

Mocks can be created automatically via code generation or manually. Generally speaking, you will want to use one of the code generation packages to generate the bulk of your mock implementation. If, instead, you want to define mocks manually, read the documentation on defining mocks.

Test code can utilize the mocks in various ways. Here is a typical example:

[Fact]
public void some_test()
{
    var mockService = new SomeServiceMock();
	mockService
	    .When(x => x.Login(It.IsAny<string>(), "123456"))
	    .Return(true);

    var sut = new Foo(mockService);

    // some test code here
    
    mockService
        .Verify(x => x.Login("me", "123456"))
        .WasNotCalled();
}

For a detailed discussion, read the documentation on using mocks.

Who?

PCLMock is created and maintained by Kent Boogaart. Issues and pull requests are welcome.

About

A simple mocking framework in a PCL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.4%
  • F# 2.5%
  • Batchfile 0.1%