Exemple #1
0
 public override void BuildOptions(Type typeOfFake, IFakeOptions options)
 {
     if (options != null)
     {
         options.Wrapping(WrappedObject);
     }
 }
Exemple #2
0
 public override void BuildOptions(Type typeOfFake, IFakeOptions options)
 {
     if (options != null)
     {
         options.Strict();
     }
 }
Exemple #3
0
 public override void BuildOptions(Type typeOfFake, IFakeOptions options)
 {
     if (options != null)
     {
         options.WithArgumentsForConstructor(new object[] { this.GetType().Name });
     }
 }
Exemple #4
0
 public override void BuildOptions(Type typeOfFake, IFakeOptions options)
 {
     if (options != null)
     {
         options.CallsBaseMethods();
     }
 }
Exemple #5
0
 public override void BuildOptions(Type typeOfFake, IFakeOptions options)
 {
     if (options != null)
     {
         options.WithArgumentsForConstructor(() => new ConstructorArgumentsSetByConstructor(this.GetType().Name));
     }
 }
Exemple #6
0
 /// <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()));
        }
Exemple #10
0
            public void BuildOptions(Type typeOfFake, IFakeOptions options)
            {
                if (options == null)
                {
                    return;
                }

                options.ConfigureFake(fake => A.CallTo(() => ((TypeWithDummyFactory)fake).WasConfigured).Returns(true));
            }
Exemple #11
0
            protected override void BuildOptions(IFakeOptions <SomeClass> options)
            {
                if (options == null)
                {
                    throw new ArgumentNullException(nameof(options));
                }

                options.ConfigureFake(fake => fake.IsConfigured = true);
            }
Exemple #12
0
            public void BuildOptions(Type typeOfFake, IFakeOptions options)
            {
                if (options == null)
                {
                    return;
                }

                options.ConfigureFake(fake => ((TypeWithOptionsBuilders)fake).WasConfigured = true);
            }
Exemple #13
0
        /// <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));
            }));
        }
Exemple #14
0
        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());
            }));
        }
Exemple #16
0
        /// <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);
        }
Exemple #18
0
        /// <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)));
        }
Exemple #19
0
        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>
        /// 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);
            }
        }
        /// <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)));
        }
Exemple #22
0
        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=>)
            }
        }
Exemple #23
0
        private void ApplyOptions <T>(IFakeOptions <T> options)
        {
            if (this._strict)
            {
                options.Strict();
            }

            if (this._configureFake != null)
            {
                options.ConfigureFake(x => this._configureFake(x));
            }
        }
Exemple #24
0
        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);
        }
Exemple #25
0
        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;
            });
        }
Exemple #26
0
        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);
        }
Exemple #27
0
        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();
            }
        }
Exemple #28
0
        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>();
        }
Exemple #30
0
        /// <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)
 {
 }
            public void BuildOptions(Type typeOfFake, IFakeOptions options)
            {
                if (options == null)
                {
                    return;
                }

                options.ConfigureFake(fake => ((TypeWithOptionsBuilders)fake).WasConfigured = true);
            }
 /// <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);