Overloaded. Fakes all static methods for the given type, and allows to set the behavior of how the fake object is created.
Namespace: TypeMock.ArrangeActAssert.Fluent
Assembly: Typemock.ArrangeActAssert (in Typemock.ArrangeActAssert.dll) Version: 9.4.1.0 (9.4.1.0)
Syntax
Parameters
- type
- Type: SystemType
The type to fake static methods for. - behavior
- Type: TypeMock.ArrangeActAssertMembers
Can be one of the following values:Members Value Description Members.MustSpecifyReturnValues Default. All void calls are ignored. Unless using WhenCalled(Action) on methods that return values and properties, they will throw a . Members.ReturnNulls All void calls are ignored. Unless using WhenCalled(Action) on methods that return values and properties, they will return null values (or zero for value types). Members.CallOriginal All methods are called. Use WhenCalled(Action) to change this behavior. Members.ReturnRecursiveFakes All void calls are ignored. When calling the fake's methods returning values or properties, they will return a fake value, which presents this behavior recursively. Any deep call will never return a Null value.
Return Value
Type:A fake instance of Type T.
Remarks
Examples
C#
[TestMethod] [Isolated] public void FakeStaticMethods_UseDefault() { Isolate.Fake.StaticMethods(typeof (LoggerFactory)); LoggerFactory.Count = 0; // This call is faked because we used the default overload for FakeStaticMethods - // IncrementCount() is not really performed LoggerFactory.IncrementCount(); Assert.AreEqual(0, LoggerFactory.Count); // The following statement will throw, because we didn't set behavior on GetCount() method. int x = LoggerFactory.GetCount(); }
C#
[TestMethod] [Isolated] public void FakeStaticMethods_UseCallOriginal() { Isolate.Fake.StaticMethods(typeof (LoggerFactory), Members.CallOriginal); LoggerFactory.Count = 0; // This call is not faked. Count should be incremented. LoggerFactory.Increment(); Assert.AreEqual(1, fake.Count); }
C#
[TestMethod] [Isolated] public void FakeStaticMethods_UseReturnNulls() { Isolate.Fake.StaticMethods(typeof (LoggerFactory), Members.ReturnNulls); LoggerFactory.Count = 0; // This call is faked because we set faked method behavior using ReturnNulls LoggerFactory.Increment(); Assert.AreEqual(0, fake.Count); // Since we're returning Null by default the following Assert passes Assert.IsNull(LoggerFactory.GetLogger()); }
C#
[TestMethod] [Isolated] public void RecursiveStubsChain() { Isolate.Fake.StaticMethods(typeof (LoggerFactory), Members.ReturnRecursiveFakes); // This method returns a value type, and therefore, returns a fake 0. Assert.AreEqual(0, LoggerFactory.GetLoggerCount()); // This method returns an object, and therefore returns a non-null object Assert.IsNotNull(LoggerFactory.GetLogger()); // And the result of GetLogger also returns a non-null object Assert.IsNotNull(LoggerFactory.GetLogger().GetWriter()); }
See Also