/// <summary> /// Makes the fake strict. This means that any call to the fake /// that has not been explicitly configured will throw an exception, /// except calls to the <see cref="object"/> methods specified /// in <paramref name="strictOptions"/>. /// </summary> /// <typeparam name="T">The type of fake object.</typeparam> /// <param name="options">Options used to create the fake object.</param> /// <param name="strictOptions">Strict fake options.</param> /// <returns>An options object.</returns> public static IFakeOptions <T> Strict <T>(this IFakeOptions <T> options, StrictFakeOptions strictOptions) where T : class { Guard.AgainstNull(options, nameof(options)); return(options.ConfigureFake(fake => { var manager = Fake.GetFakeManager(fake); manager.AddRuleFirst(new StrictFakeRule(strictOptions)); })); }
/// <summary> /// Makes the fake strict. This means that any call to the fake /// that has not been explicitly configured will throw an exception. /// </summary> /// <param name="options">Options used to create the fake object.</param> /// <returns>An options object.</returns> public static IFakeOptions Strict(this IFakeOptions options) { Guard.AgainstNull(options, nameof(options)); return(options.ConfigureFake(fake => { var manager = Fake.GetFakeManager(fake); manager.AddRuleFirst(new StrictFakeRule()); })); }
/// <summary> /// Specifies options for the next call to the specified fake object. The next call will /// be recorded as a call configuration. /// </summary> /// <typeparam name="TFake">The type of the faked object.</typeparam> /// <param name="fake">The faked object to configure.</param> /// <returns>A call configuration object.</returns> public static IRecordingConfigurationWithArgumentValidation To <TFake>(TFake fake) { Guard.AgainstNull(fake, "fake"); var recordedRule = CreateRecordedRule(); var fakeManager = Fake.GetFakeManager(fake); var recordingRule = CreateRecordingRule <TFake>(recordedRule, fakeManager); fakeManager.AddRuleFirst(recordingRule); return(CreateBuilder(recordedRule, fakeManager)); }
private static void ManageEvents(object fake, Func <EventCall, bool> eventCallPredicate) { Guard.AgainstNull(fake, nameof(fake)); var manager = Fake.GetFakeManager(fake); A.CallTo(fake) .WithVoidReturnType() .Where( call => EventCall.TryGetEventCall(call, out var eventCall) && eventCallPredicate(eventCall), writer => { }) // This call spec will never be asserted, so we don't need to write a description .Invokes(call => { if (EventCall.TryGetEventCall(call, out var eventCall)) { manager.EventCallHandler.HandleEventCall(eventCall); } }); }
internal void WriteDescription(object fake, IOutputWriter writer) => this.WriteDescription(Fake.GetFakeManager(fake).FakeObjectDisplayName, writer);