Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentcb/pclmock
A simple mocking framework in a PCL.
https://github.com/kentcb/pclmock
c-sharp dotnet mock mocking-framework portable
Last synced: 18 days ago
JSON representation
A simple mocking framework in a PCL.
- Host: GitHub
- URL: https://github.com/kentcb/pclmock
- Owner: kentcb
- License: mit
- Created: 2014-09-24T00:36:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T02:06:51.000Z (over 4 years ago)
- Last Synced: 2024-04-29T22:17:39.337Z (9 months ago)
- Topics: c-sharp, dotnet, mock, mocking-framework, portable
- Language: C#
- Size: 42.7 MB
- Stars: 44
- Watchers: 6
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Logo](Art/Logo150x150.png "Logo")
# PCLMock
[![Build status](https://ci.appveyor.com/api/projects/status/wj9tyg3m99jogmqw?svg=true)](https://ci.appveyor.com/project/kentcb/pclmock)
## What?
**PCLMock** is a lightweight, but powerful mocking framework targeting .NET Standard 1.0 (it was originally a Portable Class Library, hence the name).
## Why?
At the time of inception, existing mocking frameworks (such as [Moq](https://github.com/Moq/moq4)) rely heavily on reflection and other mechanisms that are not available on more limited .NET runtimes, such as Mono. Writing mocks without the aid of a framework is laborious, error-prone, and results in inconsistent code. **PCLMock** aims to fill this gap.
## Where?
The easiest way to get **PCLMock** is via [NuGet](http://www.nuget.org/packages/PCLMock/):
```PowerShell
Install-Package PCLMock
```There are also packages specific to [code generation](Doc/generating-mocks.md).
## How?
Mocks can be created automatically via [code generation](Doc/generating-mocks.md) 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](Doc/defining-mocks.md).
Test code can utilize the mocks in various ways. Here is a typical example:
```C#
[Fact]
public void some_test()
{
var mockService = new SomeServiceMock();
mockService
.When(x => x.Login(It.IsAny(), "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](Doc/using-mocks.md).
## Who?
**PCLMock** is created and maintained by [Kent Boogaart](http://kent-boogaart.com). Issues and pull requests are welcome.