Example #1
0
        private IProxyOptions BuildProxyOptions(Type typeOfFake, Action <IFakeOptions> optionsBuilder)
        {
            var implicitOptionsBuilder = this.implicitOptionsBuilderCatalogue.GetImplicitOptionsBuilder(typeOfFake);

            if (implicitOptionsBuilder is null && optionsBuilder == DefaultOptionsBuilder)
            {
                return(ProxyOptions.Default);
            }

            var proxyOptions = new ProxyOptions();
            var fakeOptions  = FakeOptionsFactoryCache.GetOrAdd(typeOfFake, GetFakeOptionsFactory).Invoke(proxyOptions);

            if (implicitOptionsBuilder is object)
            {
                try
                {
                    implicitOptionsBuilder.BuildOptions(typeOfFake, fakeOptions);
                }
                catch (Exception ex)
                {
                    throw new UserCallbackException(
                              ExceptionMessages.UserCallbackThrewAnException($"Fake options builder '{implicitOptionsBuilder.GetType()}'"),
                              ex);
                }
            }

            optionsBuilder?.Invoke(fakeOptions);

            return(proxyOptions);
        }
Example #2
0
        private static IFakeOptions CreateFakeOptions(Type typeOfFake, ProxyOptions proxyOptions)
        {
            var optionsConstructor = typeof(FakeOptions <>)
                                     .MakeGenericType(typeOfFake)
                                     .GetConstructor(new[] { typeof(ProxyOptions) });

            return((IFakeOptions)optionsConstructor.Invoke(new object[] { proxyOptions }));
        }
Example #3
0
        private IProxyOptions BuildProxyOptions(Type typeOfFake, Action <IFakeOptions> optionsBuilder)
        {
            var proxyOptions = new ProxyOptions();
            var options      = CreateFakeOptions(typeOfFake, proxyOptions);

            this.dynamicOptionsBuilder.BuildOptions(typeOfFake, options);
            optionsBuilder.Invoke(options);
            return(proxyOptions);
        }
Example #4
0
 public FakeOptions(ProxyOptions proxyOptions)
 {
     this.proxyOptions = proxyOptions;
 }
Example #5
0
 private static IFakeOptions CreateFakeOptions <T>(ProxyOptions proxyOptions) => new FakeOptions <T>(proxyOptions);
Example #6
0
 private static IFakeOptions CreateFakeOptions <T>(ProxyOptions proxyOptions) where T : class => new FakeOptions <T>(proxyOptions);
Example #7
0
 public FakeOptions()
 {
     this.proxyOptions = new ProxyOptions();
 }