Rocks 7.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rocks --version 7.0.0
                    
NuGet\Install-Package Rocks -Version 7.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rocks" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rocks" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Rocks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rocks --version 7.0.0
                    
#r "nuget: Rocks, 7.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rocks@7.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rocks&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Rocks&version=7.0.0
                    
Install as a Cake Tool

Rocks

A mocking library based on the Compiler APIs (Roslyn + Mocks)

Overview

There are great mocking libraries out there, like Moq and NSubstitute, so why did I decide to create YAML (yet another mocking library) in 2015? There are essentially two reasons.

The first reason relates to how code generation was done with mocking libraries. Most (if not all) used an approach that ends up using System.Reflection.Emit, which requires knowledge of IL. This is not a trivial endeavour. Furthermore, the generated code can't be stepped into during a debugging process. I wanted to write a mocking library with the new Compiler APIs (Roslyn) to see if I could make the code generation process for the mock much easier and allow a developer to step into that code if necessary.

The other reason was being able to pre-generate the mocks for a given assembly, rather than dynamically generate them in a test. This is what the Microsoft Fakes Library can do, but I wanted to be able to do it where I could easily modify a project file and automatically generate those mocks.

This is what Rocks can do. Mocks are created by generating C# code on the fly and compiling it with the Compiler APIs. This makes it trivial to step into the mock code. Before the 5.0.0 version, this code generation step took place at runtime, but with source generators in C# 9, this generation happens as soon as you state that you want to create a mock of a particular type. So, feel free to test Rocks out, and see what you think. Even if you don't use it as your primary mocking library, you may see just how easy it to generate code on the fly with the new Compiler APIs. Enjoy!

Tutorial

To make a mock, you take an interface or an unsealed class that has virtual members:

public interface IAmSimple
{
  void TargetAction();
}

and you use Rocks to create a mock with expectations, along with verifying its usage:

var expectations = Rock.Create<IAmSimple>();
expectations.Methods().TargetAction();

var mock = mock.Instance();
mock.TargetAction();

expectations.Verify();

More details can be found on the Quickstart page. Note that if you build the code locally, you'll need to build in Release mode for the package reference in Rocks.NuGetHost to resolve correctly (or unload that project from the solution as it's optional and delete nuget.config).

Changelog

A changelog was (finally!) added, starting from the 6.4.4 version. You can read it here.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rocks:

Package Downloads
Stashbox.Rocks

Rocks auto mocking integration for Stashbox.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-alpha.1 42 9/29/2025
9.3.0 811 9/15/2025
9.2.0 2,504 7/8/2025
9.1.0 1,487 5/11/2025
9.0.2 1,464 3/18/2025
9.0.1 1,605 12/15/2024
9.0.0 324 12/4/2024
9.0.0-alpha.1 100 10/22/2024
8.3.1 3,867 10/2/2024
8.3.1-alpha.1 100 9/29/2024
8.3.0 1,391 7/24/2024
8.2.0 369 7/17/2024
8.1.0 920 4/16/2024
8.0.0 685 1/22/2024
8.0.0-alpha.3 103 1/21/2024
8.0.0-alpha.2 92 1/14/2024
8.0.0-alpha.1 135 1/13/2024
7.3.0 731 11/26/2023
7.2.0 360 11/10/2023
7.1.4 408 10/7/2023
7.1.3 653 7/31/2023
7.1.2 238 7/26/2023
7.1.1 315 7/17/2023
7.1.0 422 7/3/2023
7.0.1 661 3/30/2023
7.0.0 983 11/20/2022
7.0.0-alpha.3 192 11/9/2022
7.0.0-alpha.2 201 10/10/2022
7.0.0-alpha.1 187 9/10/2022
6.4.5 1,214 6/29/2022
6.4.4 609 6/28/2022
6.4.3 693 5/23/2022
6.4.2 568 5/22/2022
6.4.1 913 4/15/2022
6.4.0 668 3/22/2022
6.3.0 6,563 11/24/2021
6.2.0 670 10/20/2021
6.0.0 726 4/12/2021
5.1.2 10,232 1/21/2021
5.1.1 604 1/21/2021
5.1.0 627 12/21/2020
5.0.0 654 12/10/2020
5.0.0-rc3 434 12/8/2020
5.0.0-rc2 430 12/2/2020
5.0.0-rc1 533 11/14/2020
4.2.1 825 7/25/2020
4.2.0 700 7/2/2020
4.1.1 739 4/27/2020
4.1.0 773 2/26/2020
4.0.0 1,231 9/23/2019
4.0.0-rc.2 429 8/10/2019
4.0.0-rc.1 428 7/18/2019
3.1.0 5,598 11/4/2017
3.0.0 3,012 8/18/2017
2.2.0 2,873 7/6/2017
2.1.7 2,843 7/4/2017
2.1.6 2,909 7/4/2017
2.1.5 2,868 7/4/2017
2.1.4 2,866 7/2/2017
2.1.3 2,858 7/2/2017
2.1.2 2,808 7/1/2017
2.1.1 2,878 7/1/2017
2.1.0 3,543 5/19/2017
2.0.0 3,897 5/1/2017
2.0.0-beta 2,547 4/30/2017
1.1.1 2,880 5/4/2016
1.0.0 2,936 1/29/2016
1.0.0-beta1 2,985 8/8/2015