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
16 changes: 0 additions & 16 deletions docs/docs/2019-01-01-search.md

This file was deleted.

26 changes: 0 additions & 26 deletions docs/docs/toc.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ title: Docs and getting help
permalink: /help.html
---

<p>Read <a href="/docs/2010-01-01-getting-started.html">Getting started</a> for a quick tour of NSubstitute.</p>
<p>Read <a href="/help/getting-started">Getting started</a> for a quick tour of NSubstitute.</p>

<p>For more in depth information start with <a href="/docs/2010-01-02-creating-a-substitute.html">Creating a substitute</a>.</p>
<p>For more in depth information start with <a href="/help/creating-a-substitute">Creating a substitute</a>.</p>

<p>If you can't find the answer you're looking for, or if you have feature requests or feedback on NSubstitute, please <a href="https://github.com/nsubstitute/NSubstitute/issues">raise an issue</a> on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try <a href="https://stackoverflow.com/tags/nsubstitute">StackOverflow with the [nsubstitute] tag</a>, which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework).</p>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is how you'll normally create substitutes for types. Generally this type wi

⚠️ **Warning:** Substituting for classes can have some nasty side-effects!

For starters, **NSubstitute can only work with *virtual* members of the class** that are overridable in the test assembly, so any non-virtual code in the class will actually execute! If you try to substitute for a class that formats your hard drive in the constructor or in a non-virtual property setter then you're asking for trouble. By overridable we mean `public virtual`, `protected virtual`, `protected internal virtual`, or `internal virtual` with `InternalsVisibleTo` attribute applied (although to configure or assert on calls members will also need to be callable from the test assembly, so `public virtual` or `internal virtual` with `InternalsVisibleTo`). See [How NSubstitute works](/help/how-nsub-works) for more information.
For starters, **NSubstitute can only work with *virtual* members of the class** that are overridable in the test assembly, so any non-virtual code in the class will actually execute! If you try to substitute for a class that formats your hard drive in the constructor or in a non-virtual property setter then you're asking for trouble. By overridable we mean `public virtual`, `protected virtual`, `protected internal virtual`, or `internal virtual` with `InternalsVisibleTo` attribute applied (although to configure or assert on calls members will also need to be callable from the test assembly, so `public virtual` or `internal virtual` with `InternalsVisibleTo`). See [How NSubstitute works](/help/how-nsub-works/) for more information.

It also means features like `Received()`, `Returns()`, `Arg.Is()`, `Arg.Any()` and `When()..Do()` **will not work with these non-overridable members**. For example: `subClass.Received().NonVirtualCall()` will not actually run an assertion (it will always pass, even if there are no calls to `NonVirtualCall()`), and can even cause confusing problems with later tests. These features will work correctly with virtual members of the class, but we have to be careful to avoid the non-virtual ones.

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions docs/help/search/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Search
---

<script async src="https://cse.google.com/cse.js?cx=005697633880271604295:lw9srlgcpg8">
</script>
<div class="gcse-search"></div>
File renamed without changes.
26 changes: 26 additions & 0 deletions docs/help/toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- href: getting-started/index.md
Comment thread
Romfos marked this conversation as resolved.
- href: creating-a-substitute/index.md
- href: set-return-value/index.md
- href: return-for-args/index.md
- href: return-for-any-args/index.md
- href: return-from-function/index.md
- href: multiple-returns/index.md
- href: replacing-return-values/index.md
- href: received-calls/index.md
- href: clear-received-calls/index.md
- href: argument-matchers/index.md
- href: callbacks/index.md
- href: throwing-exceptions/index.md
- href: configure/index.md
- href: raising-events/index.md
- href: auto-and-recursive-mocks/index.md
- href: setting-out-and-ref-arguments/index.md
- href: actions-with-arguments/index.md
- href: received-in-order/index.md
- href: partial-subs/index.md
- href: return-for-all/index.md
- href: threading/index.md
- href: compat-args/index.md
- href: nsubstitute-analysers/index.md
- href: how-nsub-works/index.md
- href: search/index.md
48 changes: 23 additions & 25 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ layout: landing
title: A friendly substitute for .NET mocking libraries
---

<div id="downloads" class="sidebar download">

# Welcome to NSubstitute

<p>Mock, stub, fake, spy, test double? Strict or loose? Nah, just substitute for the type you need!</p>
<p>NSubstitute is designed for Arrange-Act-Assert (AAA) testing, so you just need to arrange how it should work, then assert it received the calls you expected once you're done.</p>

<ul>
<li class="nuget">
<a href="https://nuget.org/List/Packages/NSubstitute">Install via NuGet:</a> <code>Install-Package NSubstitute</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers">Optional analysers for C#:</a>
<code>Install-Package NSubstitute.<wbr>Analyzers.<wbr>CSharp</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers">Optional analysers for VB:</a>
<code>Install-Package NSubstitute.<wbr>Analyzers.<wbr>VisualBasic</code>
</li>
<li class="github">
<a href="https://github.com/nsubstitute/nsubstitute">Source</a>
</li>
</ul>
</div>

<div id="features">
<div class="feature" markdown="1">

Expand Down Expand Up @@ -54,31 +77,6 @@ Received 2 non-matching calls (non-matching arguments indicated with '*' charact
</div>
</div>

<div class="feature" markdown="1">

## Don't sweat the small stuff

<p>Mock, stub, fake, spy, test double? Strict or loose? Nah, just substitute for the type you need!</p>
<p>NSubstitute is designed for Arrange-Act-Assert (AAA) testing, so you just need to arrange how it should work, then assert it received the calls you expected once you're done. Because you've got more important code to write than whether you need a mock or a stub.</p>
</div>

</div>

<div id="downloads" class="sidebar download">
<ul>
<li class="nuget">
<a href="https://nuget.org/List/Packages/NSubstitute">Install via NuGet:</a> <code>Install-Package NSubstitute</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers/">Optional analysers for C#:</a>
<code>Install-Package NSubstitute.<wbr>Analyzers.<wbr>CSharp</code>
</li>
<li class="nuget"><a href="/help/nsubstitute-analysers/">Optional analysers for VB:</a>
<code>Install-Package NSubstitute.<wbr>Analyzers.<wbr>VisualBasic</code>
</li>
<li class="github">
<a href="https://github.com/nsubstitute/nsubstitute">Source</a>
</li>
</ul>
</div>

<div class="sidebar">
Expand Down
2 changes: 1 addition & 1 deletion docs/toc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Documentation
href: docs/
href: help/

- name: Getting help
href: help.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public static string FormatCode(string code)

private static string GenerateTestsClassName(AdditionalText markdownFile)
{
return $"Tests_{Path.GetFileNameWithoutExtension(markdownFile.Path).Replace("-", "_")}";
var file = Path.GetFileNameWithoutExtension(markdownFile.Path);
var dirName = new FileInfo(markdownFile.Path).Directory.Name;
var nameToUse = string.Equals(file, "index", StringComparison.InvariantCultureIgnoreCase)
? dirName
: file;
return $"Tests_{nameToUse.Replace("-", "_")}";
}

private static string GenerateTestClassContent(string testsClassName, AdditionalText markdownFile)
Expand All @@ -55,7 +60,7 @@ private static string GenerateTestClassContent(string testsClassName, Additional
using NSubstitute.ExceptionExtensions;

namespace NSubstitute.Documentation.Tests.Generated;

public sealed class {{testsClassName}}
{
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\docs\docs\*.md" />
<AdditionalFiles Include="..\..\docs\**\*.md" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading