Skip to content

Commit 23edc2c

Browse files
committed
fixes #2305
1 parent 01a5508 commit 23edc2c

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

docs/test/using-stubs-to-isolate-parts-of-your-application-from-each-other-for-unit-testing.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Using stubs to isolate parts of your application for unit testing"
2+
title: "Using stubs to isolate parts of your app for testing"
33
ms.date: 11/04/2016
44
ms.topic: conceptual
55
ms.author: gewarren
@@ -222,9 +222,9 @@ class TestMyComponent
222222
public void TestVariableContosoPrice()
223223
{
224224
// Arrange:
225-
int priceToReturn;
226-
string companyCodeUsed;
227-
var componentUnderTest = new StockAnalyzer(new StubIStockFeed()
225+
int priceToReturn = 345;
226+
string companyCodeUsed = "";
227+
var componentUnderTest = new StockAnalyzer(new StockAnalysis.Fakes.StubIStockFeed()
228228
{
229229
GetSharePriceString = (company) =>
230230
{
@@ -234,8 +234,6 @@ class TestMyComponent
234234
return priceToReturn;
235235
};
236236
};
237-
// Set the value that will be returned by the stub:
238-
priceToReturn = 345;
239237

240238
// Act:
241239
int actualResult = componentUnderTest.GetContosoPrice();
@@ -257,7 +255,7 @@ Class TestMyComponent
257255
<TestMethod()> _
258256
Public Sub TestVariableContosoPrice()
259257
' Arrange:
260-
Dim priceToReturn As Integer
258+
Dim priceToReturn As Integer = 345
261259
Dim companyCodeUsed As String = ""
262260
Dim stockFeed As New StockAnalysis.Fakes.StubIStockFeed()
263261
With stockFeed
@@ -272,8 +270,6 @@ Class TestMyComponent
272270
End With
273271
' Create an object to test:
274272
Dim componentUnderTest As New StockAnalyzer(stockFeed)
275-
' Set the value that will be returned by the stub:
276-
priceToReturn = 345
277273

278274
' Act:
279275
Dim actualResult As Integer = componentUnderTest.GetContosoPrice()
@@ -310,7 +306,7 @@ var stub = new StubIMyInterface ();
310306
stub.MyMethodString = (value) => 1;
311307
```
312308

313-
If you do not provide a stub for a function, Fakes will generate a function that returns the default value of the return type. For numbers, the default value is 0, and for class types it is `null` (C#) or `Nothing` (Visual Basic).
309+
If you do not provide a stub for a function, Fakes generates a function that returns the default value of the return type. For numbers, the default value is 0 and for class types it is `null` (C#) or `Nothing` (Visual Basic).
314310

315311
### Properties
316312

@@ -334,7 +330,7 @@ stub.ValueGet = () => i;
334330
stub.ValueSet = (value) => i = value;
335331
```
336332

337-
If you do not provide stub methods for either the setter or the getter of a property, Fakes will generate a stub that stores values, so that the stub property works like a simple variable.
333+
If you do not provide stub methods for either the setter or the getter of a property, Fakes generates a stub that stores values so that the stub property works like a simple variable.
338334

339335
### Events
340336

@@ -402,7 +398,7 @@ In the previous examples, the stubs have been generated from interfaces. You can
402398
}
403399
```
404400

405-
In the stub generated from this class, you can set delegate methods for DoAbstract() and DoVirtual(), but not DoConcrete().
401+
In the stub generated from this class, you can set delegate methods for `DoAbstract()` and `DoVirtual()`, but not `DoConcrete()`.
406402

407403
```csharp
408404
// unit test
@@ -431,13 +427,13 @@ The stub types are designed to provide a smooth debugging experience. By default
431427

432428
## Stub limitations
433429

434-
1. Method signatures with pointers aren't supported.
430+
- Method signatures with pointers aren't supported.
435431

436-
2. Sealed classes or static methods can't be stubbed because stub types rely on virtual method dispatch. For such cases, use shim types as described in [Use shims to isolate your application from other assemblies for unit testing](../test/using-shims-to-isolate-your-application-from-other-assemblies-for-unit-testing.md)
432+
- Sealed classes or static methods can't be stubbed because stub types rely on virtual method dispatch. For such cases, use shim types as described in [Use shims to isolate your application from other assemblies for unit testing](../test/using-shims-to-isolate-your-application-from-other-assemblies-for-unit-testing.md)
437433

438434
## Change the default behavior of stubs
439435

440-
Each generated stub type holds an instance of the `IStubBehavior` interface (through the `IStub.InstanceBehavior` property). The behavior is called whenever a client calls a member with no attached custom delegate. If the behavior has not been set, it will use the instance returned by the `StubsBehaviors.Current` property. By default, this property returns a behavior that throws a `NotImplementedException` exception.
436+
Each generated stub type holds an instance of the `IStubBehavior` interface (through the `IStub.InstanceBehavior` property). The behavior is called whenever a client calls a member with no attached custom delegate. If the behavior has not been set, it uses the instance returned by the `StubsBehaviors.Current` property. By default, this property returns a behavior that throws a `NotImplementedException` exception.
441437

442438
The behavior can be changed at any time by setting the `InstanceBehavior` property on any stub instance. For example, the following snippet changes a behavior that does nothing or returns the default value of the return type: `default(T)`:
443439

0 commit comments

Comments
 (0)