public DefaultOutputWriter(Action <char> output, ArgumentValueFormatter argumentValueFormatter)
 {
     this.output = output;
     this.argumentValueFormatter = argumentValueFormatter;
     this.currentIndent          = string.Empty;
     this.writerState            = new DefaultWriterState(this);
 }
 public StringBuilderOutputWriter(StringBuilder builder, ArgumentValueFormatter argumentValueFormatter)
     : base(c => builder.Append(c), argumentValueFormatter)
 {
     this.Builder = builder;
 }
 public StringBuilderOutputWriter(ArgumentValueFormatter argumentValueFormatter)
     : this(new StringBuilder(), argumentValueFormatter)
 {
 }
        public static void RegisterDependencies(IServiceRegistrar registrar)
        {
            var bootstrapper = BootstrapperLocator.FindBootstrapper();

            var typeCatalogue      = new TypeCatalogue();
            var assemblyFilesNames = bootstrapper.GetAssemblyFileNamesToScanForExtensions()
                                     ?? throw new InvalidOperationException(ExceptionMessages.GetAssemblyFileNamesToScanForExtensionsShouldntReturnNull);

            typeCatalogue.Load(assemblyFilesNames);
            var typeCatalogueInstanceProvider = new TypeCatalogueInstanceProvider(typeCatalogue);

            var argumentValueFormatters = typeCatalogueInstanceProvider.InstantiateAllOfType <IArgumentValueFormatter>();
            var dummyFactories          = typeCatalogueInstanceProvider.InstantiateAllOfType <IDummyFactory>();
            var fakeOptionsBuilders     = typeCatalogueInstanceProvider.InstantiateAllOfType <IFakeOptionsBuilder>();

            var implicitOptionsBuilderCatalogue = new ImplicitOptionsBuilderCatalogue(fakeOptionsBuilders);

            var methodInfoManager      = new MethodInfoManager();
            var argumentConstraintTrap = new ArgumentConstraintTrap();
            var expressionArgumentConstraintFactory = new ExpressionArgumentConstraintFactory(argumentConstraintTrap);

            var fakeManagerAccessor = new DefaultFakeManagerAccessor();

            var fakeObjectCreator = new FakeObjectCreator(
                FakeCallProcessorProviderFactory,
                new CastleDynamicProxyInterceptionValidator(methodInfoManager),
                new DelegateProxyInterceptionValidator());

            var callExpressionParser = new CallExpressionParser();

            var interceptionAsserter = new DefaultInterceptionAsserter(fakeObjectCreator);

            var argumentValueFormatter = new ArgumentValueFormatter(argumentValueFormatters);

            var fakeObjectCallFormatter = new DefaultFakeObjectCallFormatter(argumentValueFormatter, fakeManagerAccessor);

            var callWriter = new CallWriter(fakeObjectCallFormatter, new FakeCallEqualityComparer());

            var configurationFactory = new ConfigurationFactory(RuleBuilderFactory);

            registrar.Register <IExpressionCallMatcherFactory>(new ExpressionCallMatcherFactory(expressionArgumentConstraintFactory, methodInfoManager));

            registrar.Register(expressionArgumentConstraintFactory);

            registrar.Register <FakeAndDummyManager>(
                new FakeAndDummyManager(
                    new DummyValueResolver(new DynamicDummyFactory(dummyFactories), fakeObjectCreator),
                    fakeObjectCreator,
                    implicitOptionsBuilderCatalogue));

            registrar.Register <IArgumentConstraintManagerFactory>(new ArgumentConstraintManagerFactory());

            registrar.Register(new EventHandlerArgumentProviderMap());

            registrar.Register <SequentialCallContext.Factory>(SequentialCallContextFactory);

            registrar.Register <IStartConfigurationFactory>(
                new StartConfigurationFactory(ExpressionCallRuleFactory, configurationFactory, callExpressionParser, interceptionAsserter));

            registrar.Register <IFakeConfigurationManager>(
                new FakeConfigurationManager(configurationFactory, ExpressionCallRuleFactory, callExpressionParser, interceptionAsserter));

            registrar.Register <IFakeManagerAccessor>(fakeManagerAccessor);

            registrar.Register <ICallExpressionParser>(callExpressionParser);

            registrar.Register((StringBuilderOutputWriter.Factory)StringBuilderOutputWriterFactory);

            registrar.Register <IFakeObjectCallFormatter>(fakeObjectCallFormatter);

            StringBuilderOutputWriter StringBuilderOutputWriterFactory() =>
            new StringBuilderOutputWriter(argumentValueFormatter !);

            FakeManager FakeManagerFactory(Type fakeObjectType, object proxy, string?name) =>
            new FakeManager(fakeObjectType, proxy, name);

            IFakeCallProcessorProvider FakeCallProcessorProviderFactory(Type typeOfFake, IProxyOptions proxyOptions) =>
            new FakeManagerProvider(FakeManagerFactory, fakeManagerAccessor, typeOfFake, proxyOptions);

            ExpressionCallRule ExpressionCallRuleFactory(ParsedCallExpression callSpecification) =>
            new ExpressionCallRule(new ExpressionCallMatcher(callSpecification, expressionArgumentConstraintFactory, methodInfoManager));

            IFakeAsserter FakeAsserterFactory(IEnumerable <CompletedFakeObjectCall> calls, int lastSequenceNumber) =>
            new FakeAsserter(calls, lastSequenceNumber, callWriter, StringBuilderOutputWriterFactory);

            SequentialCallContext SequentialCallContextFactory() =>
            new SequentialCallContext(callWriter, StringBuilderOutputWriterFactory);

            RuleBuilder RuleBuilderFactory(BuildableCallRule rule, FakeManager fake) =>
            new RuleBuilder(rule, fake, FakeAsserterFactory);
        }