Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JasonBock/Rocks
A mocking library based on the Compiler APIs (Roslyn + Mocks)
https://github.com/JasonBock/Rocks
csharp csharp-sourcegenerator mock mocking testing
Last synced: about 1 month ago
JSON representation
A mocking library based on the Compiler APIs (Roslyn + Mocks)
- Host: GitHub
- URL: https://github.com/JasonBock/Rocks
- Owner: JasonBock
- License: mit
- Created: 2015-02-09T15:28:40.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T15:13:23.000Z (7 months ago)
- Last Synced: 2024-05-22T04:33:26.088Z (7 months ago)
- Topics: csharp, csharp-sourcegenerator, mock, mocking, testing
- Language: C#
- Homepage:
- Size: 15.8 MB
- Stars: 198
- Watchers: 12
- Forks: 17
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- RSCG_Examples - https://github.com/JasonBock/Rocks/
- csharp-source-generators - Rocks - ![stars](https://img.shields.io/github/stars/JasonBock/Rocks?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/JasonBock/Rocks?style=flat-square&cacheSeconds=86400) A mocking library based on the Compiler APIs (Roslyn + Mocks). (Source Generators / Testing)
README
# Rocks
A mocking library based on the Compiler APIs (Roslyn + Mocks)
## Getting Started
Reference the `Rocks` [NuGet package](https://www.nuget.org/packages/Rocks) - that's it.
### Prerequisites
The Rocks package targets .NET Standard 2.0 for host flexibility. That said, Rocks (as of `9.0.0`) will generate code that requires .NET 9.
## Usage
To make a mock, you take an interface or an unsealed class that has virtual members:
```csharp
public interface IAmSimple
{
void TargetAction();
}
```and you use Rocks to create a mock with expectations, along with verifying its usage:
```csharp
[assembly: Rock(typeof(IAmSimple), BuildType.Create)]var expectations = new IAmSimpleCreateExpectations();
expectations.Methods.TargetAction();var mock = expectations.Instance();
mock.TargetAction();expectations.Verify();
```More details can be found on the [Overview page](https://github.com/JasonBock/Rocks/blob/main/docs/Overview.md).
## Additional Documentation
* [Discord Server](https://discord.gg/ZXMhkKsMRb)
* [Changelog](https://github.com/JasonBock/Rocks/blob/main/changelog.md)
* [Unit testing best practices with .NET Core and .NET Standard](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-best-practices)
* [BenchmarkMockNet](https://github.com/ecoAPM/BenchmarkMockNet)## Feedback
If you run into any issues, please add them [here](https://github.com/JasonBock/Rocks/issues).