Namespace: TypeMock.ArrangeActAssert.Fluent
Assembly: Typemock.ArrangeActAssert (in Typemock.ArrangeActAssert.dll) Version: 9.4.1.0 (9.4.1.0)
Parameters
- collection
- Type: System.CollectionsIEnumerable
The collection to use instead of the replaced collection
| Exception | Condition |
|---|---|
| TypeMockException | If the lambda expression provided in Isolate.WhenCalled() does not evaluate to an object implementing IEnumerable. |
This method is used as a completing statement to WhenCalledT1(ActionT1), and is used to replace the collection in the preceeding statement with the provided collection. This is useful when the code under test uses collection data that is prepared externally and then iterated over. The collection containing this data can be swapped with a test data collection prepared during the test set up and thus remove the dependency on the code populating the collection.
Note: because Typemock Isolator does not currently support faking objects implemented in MsCorLib.dll, the source collection used with WhenCalled() cannot be one implemented in MsCorLib, such as ListT and ArrayList.
[TestMethod] [Isolated] public void SwapCollectionValues_ReplaceCollectionWithTestData() { // Create a logger to use as test data RealLogger logger = new RealLogger(); // Swap the logger collection for the class under test with a collection containing the prepared test data Isolate.WhenCalled(() => LoggerFactory.Loggers).WillReturnCollectionValuesOf(new[] { logger }); // Verify the GetLogger() method returned the existing logger instead of creating a new one. RealLogger actual = LoggerFactory.GetLogger(); Assert.AreSame(logger, actual); }