Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/agents/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ For day-to-day work, `dotnet build` and `dotnet test` are enough.

## Documentation

`README.md` is the NuGet and GitHub landing page; keep it plain Markdown and self-contained, and link to the docs with full `https://docs.testably.org/...` URLs. The docs site pages in `Docs/pages/` (overview, Moq, NSubstitute) are written separately and follow the [docs style guide](https://github.com/Testably/Testably.Site/blob/main/Docs/style-guide.md). The docs site copies `Docs/pages` into the Mockolate migration folder, so this repository owns the whole "Migration" section: the overview, which also holds the manual translation table, is served at `/Mockolate/migration/` and the pages at `/Mockolate/migration/moq` and `/Mockolate/migration/nsubstitute`. Their relative links point into the Mockolate docs as they are on the site (`../05-setup/01-methods.md`). Link to the pages of this repository with relative paths, also to `00-index.md` (`./00-index.md#…`): the docs site renames it to `index` and adjusts the links. Link to pages of the Mockolate repository outside these relative paths by site path (`/Mockolate/core-concepts/`). Update the pages when the supported migrations change. Author and agent docs live in `Docs/agents/` and are not published.
`README.md` is the NuGet and GitHub landing page; keep it plain Markdown and self-contained, and link to the docs with full `https://docs.testably.org/...` URLs. The docs site pages in `Docs/pages/` (overview, Moq, NSubstitute) are written separately and follow the [docs style guide](https://github.com/Testably/Testably.Site/blob/main/Docs/style-guide.md). The docs site copies `Docs/pages` into the Mockolate migration folder, so this repository owns the whole "Migration" section: the overview, which also holds the manual translation table, is served at `/Mockolate/migration/` and the pages at `/Mockolate/migration/moq` and `/Mockolate/migration/nsubstitute`. Link to the pages of this repository with relative paths, also to `00-index.md` (`./00-index.md#…`): the docs site renames it to `index` and adjusts the links. Link to pages of the Mockolate repository by site path (`/Mockolate/setup/methods`, `/Mockolate/core-concepts/`), because a relative path names the file, and the build of the docs site fails when Mockolate renumbers it. Update the pages when the supported migrations change. Author and agent docs live in `Docs/agents/` and are not published.
8 changes: 4 additions & 4 deletions Docs/pages/00-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Coming from **[Moq](https://github.com/devlooped/moq)**, **[NSubstitute](https:/

### Installation

The migration package contains only the analyzer and the code fixes, no runtime code, and does not reference Mockolate. Add [Mockolate](../01-getting-started.mdx) to the test project you want to migrate yourself, so that the migrated code still compiles after you remove the migration package:
The migration package contains only the analyzer and the code fixes, no runtime code, and does not reference Mockolate. Add [Mockolate](/Mockolate/getting-started) to the test project you want to migrate yourself, so that the migrated code still compiles after you remove the migration package:

<PackageInstall package="Mockolate" />

Expand Down Expand Up @@ -63,7 +63,7 @@ dotnet format analyzers --diagnostics MockolateM001 MockolateM002
The code fix leaves a `// TODO(MockolateM001)` or `// TODO(MockolateM002)` comment where it cannot finish the migration on its own. Search for them after you apply the code fix:

- **Nested mocks**: Moq and NSubstitute create mocks for nested members (`m => m.Child.Prop`) automatically. Mockolate does not, so set up the parent to return a mock for `Child` yourself.
- **Moq sequences whose steps are not chained to `SetupSequence(…)`**, for example when the setup is stored in a variable. After the last step, Moq returns the default value (or does nothing for a `void` method), while a Mockolate [sequence](../05-setup/01-methods.md#sequences) starts over. End the sequence as the comment describes.
- **Moq sequences whose steps are not chained to `SetupSequence(…)`**, for example when the setup is stored in a variable. After the last step, Moq returns the default value (or does nothing for a `void` method), while a Mockolate [sequence](/Mockolate/setup/methods#sequences) starts over. End the sequence as the comment describes.
- **[CallInfo callbacks](./02-nsubstitute.md#callinfo-callbacks)** that cannot be rewritten safely, for example when they use `call` directly, compute the index at runtime, assign `out` or `ref` arguments, call an ambiguous `call.Arg<T>()`, or declare local variables with the same names as the parameters of the method.
- **Moq `Times` arguments that the code fix cannot translate**, for example a variable or a conditional expression. The Moq verification stays as it is.

Expand Down Expand Up @@ -275,12 +275,12 @@ dispenser.Mock.Verify["Dark"].Got().Once();

:::warning[Differences to watch out for]

- A `Returns`/`Throws` [sequence](../05-setup/01-methods.md#sequences) starts over after its last entry. Mark the last
- A `Returns`/`Throws` [sequence](/Mockolate/setup/methods#sequences) starts over after its last entry. Mark the last
entry with `.Forever()` to keep repeating it instead.
- Class mocks call the base class implementation by default, even when a setup matches. See
[Core concepts](/Mockolate/core-concepts/#what-happens-when-the-mock-is-called).
- A later setup with the same arguments replaces an earlier one, so chain everything that belongs to one setup.

:::

For the complete Mockolate syntax on one page, see the [cheat sheet](../02-core-concepts/02-cheat-sheet.md).
For the complete Mockolate syntax on one page, see the [cheat sheet](/Mockolate/core-concepts/cheat-sheet).
12 changes: 6 additions & 6 deletions Docs/pages/01-moq.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dispenser.Mock.Verify.Dispense("White", It.IsAny<int>()).Never();

## Supported Moq constructs

The tables list the constructs the code fix rewrites. Everything else [needs manual review](./00-index.md#what-needs-manual-review). The examples use the `IChocolateDispenser` interface from the [migration overview](./00-index.md#side-by-side) and the `VendingMachine` from [Getting started](../01-getting-started.mdx); the code fix keeps your variable names, so the mock keeps its name and `sut` stays the system under test.
The tables list the constructs the code fix rewrites. Everything else [needs manual review](./00-index.md#what-needs-manual-review). The examples use the `IChocolateDispenser` interface from the [migration overview](./00-index.md#side-by-side) and the `VendingMachine` from [Getting started](/Mockolate/getting-started); the code fix keeps your variable names, so the mock keeps its name and `sut` stays the system under test.

### Creating mocks

Expand Down Expand Up @@ -71,7 +71,7 @@ IChocolateDispenser dispenserObject = dispenser;

</ApplyFix>

Strict mocks get a [behavior](../04-create-mocks.md#customizing-mock-behavior) that throws when no setup matches, written as `Mockolate.MockBehavior` because Moq has a `MockBehavior` as well:
Strict mocks get a [behavior](/Mockolate/create-mocks#customizing-mock-behavior) that throws when no setup matches, written as `Mockolate.MockBehavior` because Moq has a `MockBehavior` as well:

<ApplyFix id="MockolateM001" migrateTo="Mockolate">

Expand Down Expand Up @@ -101,7 +101,7 @@ dispenser.Mock.Setup.Dispense("Dark", 1).Returns(true);
| `.Callback(…)` | `.Do(…)` |
| `mock.InSequence(sequence).Setup(…)` | `mock.Mock.Setup.Method(…)` (the `InSequence` wrapper is removed) |

`Callback` becomes `Do`, and a `SetupSequence` becomes a setup with the same chain of `Returns`, which Mockolate uses as a [sequence](../05-setup/01-methods.md#sequences). A Mockolate sequence starts over after its last step, while Moq returns the default value, so the code fix ends the chain with `.Returns(default(T)).Forever()`:
`Callback` becomes `Do`, and a `SetupSequence` becomes a setup with the same chain of `Returns`, which Mockolate uses as a [sequence](/Mockolate/setup/methods#sequences). A Mockolate sequence starts over after its last step, while Moq returns the default value, so the code fix ends the chain with `.Returns(default(T)).Forever()`:

<ApplyFix id="MockolateM001" migrateTo="Mockolate">

Expand Down Expand Up @@ -188,7 +188,7 @@ dispenser.Mock.Verify.TotalDispensed.Set(10).Never();
| `It.IsRegex(pattern, options)` | `It.Matches(pattern).AsRegex(options).CaseSensitive()` |
| `It.Ref<T>.IsAny`, `out` parameters | `It.IsAnyRef<T>()`, `It.IsOut(() => value)` |

`It.IsAny` stays as it is, while `It.Is` with a predicate becomes `It.Satisfies` and `It.IsRegex` becomes `It.Matches(…).AsRegex(…)`. `It.Matches` ignores the case by default, so the code fix appends `CaseSensitive()` to match the case like Moq does; a `RegexOptions.IgnoreCase` option still applies. See [parameter matching](../06-parameter-matching.md) for the Mockolate matchers.
`It.IsAny` stays as it is, while `It.Is` with a predicate becomes `It.Satisfies` and `It.IsRegex` becomes `It.Matches(…).AsRegex(…)`. `It.Matches` ignores the case by default, so the code fix appends `CaseSensitive()` to match the case like Moq does; a `RegexOptions.IgnoreCase` option still applies. See [parameter matching](/Mockolate/parameter-matching) for the Mockolate matchers.

<ApplyFix id="MockolateM001" migrateTo="Mockolate">

Expand Down Expand Up @@ -247,6 +247,6 @@ Moq creates the mock for `Child` automatically, Mockolate does not; set up the p

The migrated code compiles, but behaves differently from Moq in these cases:

- **Class mocks call the base class.** A Moq mock calls the base class implementation only with `CallBase = true`, while a Mockolate class mock calls it for virtual members by default, even when a setup matches. To keep the Moq behavior, pass `Mockolate.MockBehavior.Default.SkippingBaseClass()` to `CreateMock` (see [customizing mock behavior](../04-create-mocks.md#customizing-mock-behavior)).
- **Setups no longer check the call order.** The code fix removes the `InSequence(…)` wrapper. Mockolate checks the order after the calls instead: add a [`Then(…)`](../07-verify-interactions.md#call-order) chain to the verification.
- **Class mocks call the base class.** A Moq mock calls the base class implementation only with `CallBase = true`, while a Mockolate class mock calls it for virtual members by default, even when a setup matches. To keep the Moq behavior, pass `Mockolate.MockBehavior.Default.SkippingBaseClass()` to `CreateMock` (see [customizing mock behavior](/Mockolate/create-mocks#customizing-mock-behavior)).
- **Setups no longer check the call order.** The code fix removes the `InSequence(…)` wrapper. Mockolate checks the order after the calls instead: add a [`Then(…)`](/Mockolate/verify-interactions#call-order) chain to the verification.
- **Failure messages are dropped.** `mock.Verify(m => m.Method(args), "message")` becomes `mock.Mock.Verify.Method(args).AtLeastOnce()` without the message.
8 changes: 4 additions & 4 deletions Docs/pages/02-nsubstitute.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dispenser.Mock.Verify.Dispense("White", It.IsAny<int>()).Never();

## Supported NSubstitute constructs

The tables list the constructs the code fix rewrites. Everything else [needs manual review](./00-index.md#what-needs-manual-review). The examples use the `IChocolateDispenser` interface from the [migration overview](./00-index.md#side-by-side) and the `VendingMachine` from [Getting started](../01-getting-started.mdx); the code fix keeps your variable names, so the mock keeps its name and `sut` stays the system under test.
The tables list the constructs the code fix rewrites. Everything else [needs manual review](./00-index.md#what-needs-manual-review). The examples use the `IChocolateDispenser` interface from the [migration overview](./00-index.md#side-by-side) and the `VendingMachine` from [Getting started](/Mockolate/getting-started); the code fix keeps your variable names, so the mock keeps its name and `sut` stays the system under test.

### Creating substitutes

Expand All @@ -66,7 +66,7 @@ The tables list the constructs the code fix rewrites. Everything else [needs man
| `sub.When(x => x.Method(args)).Do(callback)` | `sub.Mock.Setup.Method(args).Do(callback)` |
| `sub.When(x => x.Method(args)).DoNotCallBase()` | `sub.Mock.Setup.Method(args).SkippingBaseClass()` |

Multiple return values become a [sequence](../05-setup/01-methods.md#sequences) that ends with `.Forever()`, so the last value repeats as in NSubstitute, and `ReturnsForAnyArgs` ignores the arguments with `AnyParameters()`:
Multiple return values become a [sequence](/Mockolate/setup/methods#sequences) that ends with `.Forever()`, so the last value repeats as in NSubstitute, and `ReturnsForAnyArgs` ignores the arguments with `AnyParameters()`:

<ApplyFix id="MockolateM002" migrateTo="Mockolate">

Expand Down Expand Up @@ -151,7 +151,7 @@ dispenser.Mock.Verify.TotalDispensed.Got().AtLeastOnce();
| `Arg.Is(value)`, `Arg.Is<T>(value)` | `It.Is(value)`, `It.Is<T>(value)` |
| `Arg.Compat.Any<T>()` and the other `Arg.Compat` matchers | the same as the matching `Arg` matcher |

See [parameter matching](../06-parameter-matching.md) for the Mockolate matchers.
See [parameter matching](/Mockolate/parameter-matching) for the Mockolate matchers.

### CallInfo callbacks

Expand Down Expand Up @@ -223,4 +223,4 @@ NSubstitute creates the substitute for `Child` automatically, Mockolate does not

The migrated code compiles, but behaves differently from NSubstitute in this case:

- **Class substitutes call the base class.** The code fix creates both `Substitute.For<T>()` and `Substitute.ForPartsOf<T>()` as `T.CreateMock()`, and a Mockolate class mock calls the base class implementation of virtual members by default, even when a setup matches. To keep the behavior of `Substitute.For<T>()` for a class, pass `MockBehavior.Default.SkippingBaseClass()` to `CreateMock` (see [customizing mock behavior](../04-create-mocks.md#customizing-mock-behavior)).
- **Class substitutes call the base class.** The code fix creates both `Substitute.For<T>()` and `Substitute.ForPartsOf<T>()` as `T.CreateMock()`, and a Mockolate class mock calls the base class implementation of virtual members by default, even when a setup matches. To keep the behavior of `Substitute.For<T>()` for a class, pass `MockBehavior.Default.SkippingBaseClass()` to `CreateMock` (see [customizing mock behavior](/Mockolate/create-mocks#customizing-mock-behavior)).
Loading