Mockolate.Migration
0.4.0
Prefix Reserved
See the version list below for details.
dotnet add package Mockolate.Migration --version 0.4.0
NuGet\Install-Package Mockolate.Migration -Version 0.4.0
<PackageReference Include="Mockolate.Migration" Version="0.4.0" />
<PackageVersion Include="Mockolate.Migration" Version="0.4.0" />
<PackageReference Include="Mockolate.Migration" />
paket add Mockolate.Migration --version 0.4.0
#r "nuget: Mockolate.Migration, 0.4.0"
#:package Mockolate.Migration@0.4.0
#addin nuget:?package=Mockolate.Migration&version=0.4.0
#tool nuget:?package=Mockolate.Migration&version=0.4.0
Mockolate.Migration
A Roslyn analyzer and code-fix provider that migrates Moq usage to Mockolate. Drop the package into a project that uses Moq and the analyzer flags each mock it can migrate; the accompanying code fix rewrites the setup, verification, and event APIs to their Mockolate equivalents.
Installation
Install the NuGet package into the project you want to migrate:
dotnet add package Mockolate.Migration
The package only needs to be referenced while you are migrating — it ships the analyzer and code fixer, not runtime code. Once Moq is gone from a project you can remove the reference again.
Usage
After installing the package, every supported Moq construct (starting from new Mock<T>()) is reported
as a warning with diagnostic id MockolateM001 (Moq should be migrated.). Apply the code fix
Migrate Moq to Mockolate from your IDE (Visual Studio, Rider, VS Code with C# Dev Kit) or via
dotnet format analyzers to rewrite the call site.
The fixer rewrites the whole mock — the new Mock<T>() construction, all Setup… calls on that mock,
the corresponding Verify… calls, event wiring, and trailing .Object accesses — in a single step.
Supported migrations
| Moq construct | Rewritten to |
|---|---|
new Mock<IFoo>() |
IFoo.CreateMock() |
new Mock<IFoo>(MockBehavior.Strict) |
IFoo.CreateMock(MockBehavior.Default.ThrowingWhenNotSetup()) |
sut.Object |
sut (the .Object access is dropped) |
sut.Setup(m => m.Method(args)) |
sut.Mock.Setup.Method(args) |
sut.Setup(m => m.Prop) / sut.SetupGet(...) |
sut.Mock.Setup.Prop |
sut.SetupProperty(m => m.Prop) |
sut.Mock.Setup.Prop.Register() |
sut.SetupProperty(m => m.Prop, value) |
sut.Mock.Setup.Prop.InitializeWith(value) |
sut.SetupSequence(...).Returns(a).Returns(b) |
sut.Mock.Setup.Method(...).Returns(a).Returns(b) |
.Returns(...) / .ReturnsAsync(...) / .Throws(...) |
preserved on the Mockolate setup chain |
.Callback(...) |
.Do(...) on the Mockolate setup |
sut.InSequence(seq).Setup(...) (and other setup forms) |
.InSequence(...) wrapper is stripped; use Verify…Then(...) for ordering |
sut.Verify(m => m.Method(args), Times.Once()) |
sut.Mock.Verify.Method(args).Once() |
sut.VerifyGet / sut.VerifySet |
sut.Mock.Verify.Prop.Got(...) / .Set(...) |
sut.Raise(m => m.Event += null, args) |
sut.Mock.Raise.Event(sender, args) |
sut.VerifyAdd(m => m.Event += ..., times) |
sut.Mock.Verify.Event.Subscribed().<times>() |
sut.VerifyRemove(m => m.Event -= ..., times) |
sut.Mock.Verify.Event.Unsubscribed().<times>() |
It.IsAny<T>() |
preserved as It.IsAny<T>() |
It.Is<T>(predicate) |
It.Satisfies<T>(predicate) |
It.IsInRange(lo, hi, Range.Inclusive) |
It.IsInRange(lo, hi) (the Range argument is dropped) |
It.IsRegex(pattern, options) |
It.Matches(pattern).AsRegex(options) |
It.Ref<T>.IsAny / out parameters |
It.IsAnyRef<T>() / It.IsOut(() => value) |
Nested mocks (sut.Setup(m => m.Child.Prop)) |
Navigation chain is preserved: sut.Child.Mock.Setup.Prop |
| Product | Versions 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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.