public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { options.Wrapping(WrappedObject); } }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { options.Strict(); } }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { options.WithArgumentsForConstructor(new object[] { this.GetType().Name }); } }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { options.CallsBaseMethods(); } }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { options.WithArgumentsForConstructor(() => new ConstructorArgumentsSetByConstructor(this.GetType().Name)); } }
/// <summary> /// Add additional interfaces to the builder. /// </summary> /// <typeparam name="T">The proxy type.</typeparam> /// <param name="builder">The <see cref="IFakeOptions{T}"/>.</param> protected virtual void Build <T>(IFakeOptions <T> builder) { foreach (var i in this.additionalInterfaces) { builder.Implements(i); } }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options is not null) { options.Wrapping(null !); } }
private void UserAccountOptionsBuilder(IFakeOptions <ei_infrastructure.Data.POCOs.UserAccount> fakeOptions) { fakeOptions.ConfigureFake(userAccount => { userAccount.Username = RandomString(10); userAccount.Password = RandomString(6); }); }
/// <summary> /// Makes the fake default to calling base methods, so long as they aren't abstract. /// </summary> /// <param name="options">Options used to create the fake object.</param> /// <returns>An options object.</returns> public static IFakeOptions CallsBaseMethods(this IFakeOptions options) { Guard.AgainstNull(options, nameof(options)); return(options.ConfigureFake(fake => A.CallTo(fake) .Where(call => !call.Method.IsAbstract) .CallsBaseMethod())); }
public void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options == null) { return; } options.ConfigureFake(fake => A.CallTo(() => ((TypeWithDummyFactory)fake).WasConfigured).Returns(true)); }
protected override void BuildOptions(IFakeOptions <SomeClass> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } options.ConfigureFake(fake => fake.IsConfigured = true); }
public void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options == null) { return; } options.ConfigureFake(fake => ((TypeWithOptionsBuilders)fake).WasConfigured = true); }
/// <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)); })); }
void IFakeOptionsBuilder.BuildOptions(Type typeOfFake, IFakeOptions options) { if (!((IFakeOptionsBuilder)this).CanBuildOptionsForFakeOfType(typeOfFake)) { throw new InvalidOperationException( $"Specified type {typeOfFake} is not valid. Only {typeof(TFake)} is allowed."); } this.BuildOptions((IFakeOptions <TFake>)options); }
/// <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> /// Applies base configuration to a fake object. /// </summary> /// <param name="typeOfFake">The type the fake object represents.</param> /// <param name="fakeOptions">The options to build for the fake's creation.</param> public void BuildOptions(Type typeOfFake, IFakeOptions fakeOptions) { var fakeOptionsBuilder = this.cachedFakeOptionsBuilders.GetOrAdd( typeOfFake, type => this.allFakeOptionsBuilders.FirstOrDefault(builder => builder.CanBuildOptionsForFakeOfType(type))); if (fakeOptionsBuilder != null) { fakeOptionsBuilder.BuildOptions(typeOfFake, fakeOptions); } }
void IFakeOptionsBuilder.BuildOptions(Type typeOfFake, IFakeOptions options) { if (!((IFakeOptionsBuilder)this).CanBuildOptionsForFakeOfType(typeOfFake)) { throw new InvalidOperationException( "Specified type '{0}' is not valid. Only '{1}' is allowed." .FormatInvariant(typeOfFake.FullNameCSharp(), typeof(TFake).FullNameCSharp())); } this.BuildOptions((IFakeOptions <TFake>)options); }
/// <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="optionsBuilder">Action that builds options used to create the fake object.</param> /// <returns>A configuration object.</returns> public static IFakeOptions Strict(this IFakeOptions optionsBuilder) { Guard.AgainstNull(optionsBuilder, "optionsBuilder"); Action <IFakeObjectCall> thrower = call => { throw new ExpectationException("Call to non configured method \"{0}\" of strict fake.".FormatInvariant(call.Method.Name)); }; return(optionsBuilder.ConfigureFake(fake => A.CallTo(fake).Invokes(thrower))); }
public override void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options != null) { #if FEATURE_SELF_INITIALIZED_FAKES options.Wrapping(WrappedObject).RecordedBy(Recorder); #else options.Wrapping(WrappedObject); #endif } }
/// <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)); Action <IFakeObjectCall> thrower = call => { throw new ExpectationException(ExceptionMessages.CallToUnconfiguredMethodOfStrictFake(call)); }; return(options.ConfigureFake(fake => A.CallTo(fake).Invokes(thrower))); }
private void ApplyOptions <T>(IFakeOptions <T> options)//IFakeOptionsBuilder<T> [to] IFakeOptions<T> { if (this._strict) { options.Strict(); } if (this._onFakeCreated != null) { options.ConfigureFake(x => this._onFakeCreated(x));//OnFakeCreated(x=>) [to] ConfigureFake(x=>) } }
private void ApplyOptions <T>(IFakeOptions <T> options) { if (this._strict) { options.Strict(); } if (this._configureFake != null) { options.ConfigureFake(x => this._configureFake(x)); } }
public void CreateFake_should_pass_options_object_that_returns_itself_for_any_call(Func <IFakeOptions <Foo>, IFakeOptions <Foo> > call) { Guard.AgainstNull(call, "call"); // Arrange IFakeOptions <Foo> optionsPassedToAction = null; // Act this.creator.CreateFake <Foo>(x => { optionsPassedToAction = x; }); // Assert call.Invoke(optionsPassedToAction).Should().BeSameAs(optionsPassedToAction); }
protected override void BuildOptions(IFakeOptions <RobotRunsAmokEvent> options) { if (options == null) { return; } options.ConfigureFake(fake => { var robotRunsAmokEvent = fake; A.CallTo(() => robotRunsAmokEvent.CalculateTimestamp()) .Returns(ConfiguredTimestamp); robotRunsAmokEvent.ID = -99; }); }
public void BuildOptions(Type typeOfFake, IFakeOptions options) { var iqueryableInterfaceType = typeof(IQueryable <>); var idbAsyncEnumerableInterfaceType = typeof(IDbAsyncEnumerable <>); var genericClass = typeOfFake.GetGenericArguments().First(); var iqueryableTypeName = $"{iqueryableInterfaceType.FullName}[[{genericClass.AssemblyQualifiedName}]],{iqueryableInterfaceType.Assembly.FullName}"; var idbAsyncEnumerableTypeName = $"{idbAsyncEnumerableInterfaceType.FullName}[[{genericClass.AssemblyQualifiedName}]],{idbAsyncEnumerableInterfaceType.Assembly.FullName}"; var iqueryableType = Type.GetType(iqueryableTypeName, true, true); var idbAsyncEnumerableType = Type.GetType(idbAsyncEnumerableTypeName, true, true); options.Implements(iqueryableType); options.Implements(idbAsyncEnumerableType); }
private void ApplyOptions(IFakeOptions options) { if (this._strict) { options = options.Strict(); } if (this._configureFake != null) { options = options.ConfigureFake(x => this._configureFake(x)); } if (this._callsBaseMethods) { options.CallsBaseMethods(); } }
public void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options == null) { return; } options.ConfigureFake(fake => { var domainEvent = (DomainEvent)fake; domainEvent.ID = this.nextID++; domainEvent.Name = typeOfFake.Name; }) .WithAttributes(() => new ForTestAttribute()) .Implements(typeof(IDisposable)) .Implements <IComparable>(); }
public void BuildOptions(Type typeOfFake, IFakeOptions options) { if (options == null) { return; } options.ConfigureFake(fake => { var domainEvent = (DomainEvent)fake; domainEvent.ID = this.nextID++; domainEvent.Name = typeOfFake.Name; }) .WithAdditionalAttributes(new[] { CreateCustomAttributeBuilder() }) .Implements(typeof(IDisposable)) .Implements <ICloneable>(); }
/// <summary> /// Applies base configuration to a fake object. /// </summary> /// <param name="typeOfFake">The type the fake object represents.</param> /// <param name="fakeOptions">The options to build for the fake's creation.</param> public void BuildOptions(Type typeOfFake, IFakeOptions fakeOptions) { var fakeOptionsBuilder = this.cachedFakeOptionsBuilders.GetOrAdd( typeOfFake, type => this.allFakeOptionsBuilders.FirstOrDefault(builder => builder.CanBuildOptionsForFakeOfType(type))); if (fakeOptionsBuilder != null) { try { fakeOptionsBuilder.BuildOptions(typeOfFake, fakeOptions); } catch (Exception ex) { throw new UserCallbackException(ExceptionMessages.UserCallbackThrewAnException($"Fake options builder '{fakeOptionsBuilder.GetType()}'"), ex); } } }
/// <summary> /// Configures a fake's creation options. /// </summary> /// <param name="typeOfFake">The type the fake object represents.</param> /// <param name="fakeOptions">The options to build for the fake's creation.</param> public void BuildOptions(Type typeOfFake, IFakeOptions fakeOptions) { }
/// <summary> /// Manipulates <paramref name="options"/>, which will later be used to /// create a Fake. /// </summary> /// <param name="options">The fake options to manipulate.</param> protected abstract void BuildOptions(IFakeOptions <TFake> options);