/// <summary>
        /// Initializes a new instance of the <see cref="DummyValueCreationSession"/> class.
        /// </summary>
        /// <param name="dummyFactory">The dummy factory.</param>
        /// <param name="fakeObjectCreator">The fake object creator.</param>
        public DummyValueCreationSession(DynamicDummyFactory dummyFactory, IFakeObjectCreator fakeObjectCreator)
        {
            this.typesCurrentlyBeingResolved = new HashSet <Type>();
            this.strategyCache = new Dictionary <Type, ResolveStrategy>();
            this.strategies    = new ResolveStrategy[]
            {
                new ResolveFromDummyFactoryStrategy {
                    DummyFactory = dummyFactory
                },
#if NET40
                new ResolveByCreatingTaskStrategy {
                    Session = this
                },
                new ResolveByCreatingLazyStrategy {
                    Session = this
                },
#endif
                new ResolveByCreatingFakeStrategy {
                    FakeCreator = fakeObjectCreator, Session = this
                },
                new ResolveByActivatingValueTypeStrategy(),
                new ResolveByInstantiatingClassUsingDummyValuesAsConstructorArgumentsStrategy {
                    Session = this
                }
            };
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DummyValueResolver"/> class.
 /// </summary>
 /// <param name="dummyFactory">The dummy factory.</param>
 /// <param name="fakeObjectCreator">The fake object creator.</param>
 public DummyValueResolver(DynamicDummyFactory dummyFactory, IFakeObjectCreator fakeObjectCreator)
 {
     this.strategyCache = new ConcurrentDictionary <Type, ResolveStrategy>();
     this.strategies    = new ResolveStrategy[]
     {
         new ResolveFromDummyFactoryStrategy(dummyFactory),
         new ResolveByCreatingTaskStrategy(),
         new ResolveByCreatingLazyStrategy(),
         new ResolveByActivatingValueTypeStrategy(),
         new ResolveByCreatingFakeStrategy(fakeObjectCreator),
         new ResolveByInstantiatingClassUsingDummyValuesAsConstructorArgumentsStrategy()
     };
 }
Пример #3
0
 public ResolveFromDummyFactoryStrategy(DynamicDummyFactory dummyFactory)
 {
     this.DummyFactory = dummyFactory;
 }
Пример #4
0
        public static void RegisterDependencies(DictionaryContainer container)
        {
            container.RegisterSingleton(c =>
                                        new DynamicOptionsBuilder(
                                            c.Resolve <IEnumerable <IFakeOptionsBuilder> >()));

            container.RegisterSingleton <IExpressionCallMatcherFactory>(c => new ExpressionCallMatcherFactory(c));

            container.RegisterSingleton(c =>
                                        new ExpressionArgumentConstraintFactory(c.Resolve <IArgumentConstraintTrapper>()));

            container.RegisterSingleton <ExpressionCallRule.Factory>(c =>
                                                                     callSpecification => new ExpressionCallRule(new ExpressionCallMatcher(callSpecification, c.Resolve <ExpressionArgumentConstraintFactory>(), c.Resolve <MethodInfoManager>())));

            container.RegisterSingleton(c =>
                                        new MethodInfoManager());

            container.Register <FakeAsserter.Factory>(c => calls => new FakeAsserter(calls, c.Resolve <CallWriter>(), c.Resolve <StringBuilderOutputWriter.Factory>()));

            container.RegisterSingleton <FakeManager.Factory>(c =>
                                                              (fakeObjectType, proxy) => new FakeManager(fakeObjectType, proxy, c.Resolve <IFakeManagerAccessor>()));

            container.RegisterSingleton <FakeCallProcessorProvider.Factory>(c =>
                                                                            (typeOfFake, proxyOptions) =>
                                                                            new FakeManagerProvider(c.Resolve <FakeManager.Factory>(), c.Resolve <IFakeManagerAccessor>(), typeOfFake, proxyOptions));

            container.RegisterSingleton <IFakeObjectCallFormatter>(c =>
                                                                   new DefaultFakeObjectCallFormatter(c.Resolve <ArgumentValueFormatter>(), c.Resolve <IFakeManagerAccessor>()));

            container.RegisterSingleton(c =>
                                        new ArgumentValueFormatter(c.Resolve <IEnumerable <IArgumentValueFormatter> >(), c.Resolve <StringBuilderOutputWriter.Factory>()));

            container.RegisterSingleton(c =>
                                        new CallWriter(c.Resolve <IFakeObjectCallFormatter>(), c.Resolve <IEqualityComparer <IFakeObjectCall> >()));

            container.RegisterSingleton <ICallExpressionParser>(c =>
                                                                new CallExpressionParser());

            container.RegisterSingleton(c => new FakeObjectCreator(
                                            container.Resolve <FakeCallProcessorProvider.Factory>(),
                                            container.Resolve <CastleDynamicProxyInterceptionValidator>(),
                                            container.Resolve <DelegateProxyInterceptionValidator>()));
            container.RegisterSingleton <IFakeObjectCreator>(c => c.Resolve <FakeObjectCreator>());
            container.RegisterSingleton <IMethodInterceptionValidator>(c => c.Resolve <FakeObjectCreator>());

            container.RegisterSingleton <IFakeAndDummyManager>(c =>
            {
                var fakeCreator      = c.Resolve <IFakeObjectCreator>();
                var fakeConfigurator = c.Resolve <DynamicOptionsBuilder>();

                var dynamicDummyFactory = new DynamicDummyFactory(c.Resolve <IEnumerable <IDummyFactory> >());
                var dummyValueResolver  = new DummyValueResolver(dynamicDummyFactory, fakeCreator);

                return(new DefaultFakeAndDummyManager(
                           dummyValueResolver,
                           fakeCreator,
                           fakeConfigurator));
            });

            container.RegisterSingleton(c => new CastleDynamicProxyInterceptionValidator(c.Resolve <MethodInfoManager>()));

            container.RegisterSingleton(c => new DelegateProxyInterceptionValidator());

            container.RegisterSingleton <IFakeManagerAccessor>(c => new DefaultFakeManagerAccessor());

            container.Register(c => new FakeFacade(c.Resolve <IFakeManagerAccessor>()));

            container.RegisterSingleton <IEqualityComparer <IFakeObjectCall> >(c => new FakeCallEqualityComparer());

            container.Register <IInterceptionAsserter>(c => new DefaultInterceptionAsserter(c.Resolve <IMethodInterceptionValidator>()));

            container.Register <IArgumentConstraintTrapper>(c => new ArgumentConstraintTrap());

            container.Register <IArgumentConstraintManagerFactory>(c => new ArgumentConstraintManagerFactory());

            container.RegisterSingleton <IOutputWriter>(c => new DefaultOutputWriter(Console.Write, c.Resolve <ArgumentValueFormatter>()));

            container.RegisterSingleton <StringBuilderOutputWriter.Factory>(c => builder => new StringBuilderOutputWriter(builder, c.Resolve <ArgumentValueFormatter>()));

            container.Register(c => c.Resolve <StringBuilderOutputWriter.Factory>().Invoke(new StringBuilder()));

            container.RegisterSingleton(c => new EventHandlerArgumentProviderMap());

            container.Register(c => new SequentialCallContext(c.Resolve <CallWriter>(), c.Resolve <StringBuilderOutputWriter.Factory>()));
        }