public SubstituteState(ISubstitutionContext substitutionContext)
        {
            SubstitutionContext = substitutionContext;
            SequenceNumberGenerator = substitutionContext.SequenceNumberGenerator;
            var substituteFactory = substitutionContext.SubstituteFactory;
            var callInfoFactory = new CallInfoFactory();
            var callStack = new CallStack();
            CallStack = callStack;
            ReceivedCalls = callStack;
            PendingSpecification = new PendingSpecification();
            CallResults = new CallResults(callInfoFactory);
            CallSpecificationFactory = CallSpecificationFactoryFactoryYesThatsRight.CreateCallSpecFactory();
            CallActions = new CallActions(callInfoFactory);

            var getCallSpec = new GetCallSpec(callStack, PendingSpecification, CallSpecificationFactory, CallActions);

            ConfigureCall = new ConfigureCall(CallResults, CallActions, getCallSpec);
            EventHandlerRegistry = new EventHandlerRegistry();
            AutoValueProviders = new IAutoValueProvider[] {
                new AutoSubstituteProvider(substituteFactory),
                new AutoStringProvider(),
                new AutoArrayProvider(),
            #if NET4
                new AutoTaskProvider(() => AutoValueProviders),
            #endif
            };
        }
Exemplo n.º 2
0
        public SubstituteState(ISubstitutionContext substitutionContext, SubstituteConfig option)
        {
            SubstitutionContext = substitutionContext;
            SubstituteConfig = option;
            SequenceNumberGenerator = substitutionContext.SequenceNumberGenerator;
            var substituteFactory = substitutionContext.SubstituteFactory;
            var callInfoFactory = new CallInfoFactory();
            var callStack = new CallStack();
            CallStack = callStack;
            ReceivedCalls = callStack;
            PendingSpecification = new PendingSpecification();
            CallResults = new CallResults(callInfoFactory);
            CallSpecificationFactory = CallSpecificationFactoryFactoryYesThatsRight.CreateCallSpecFactory();
            CallActions = new CallActions(callInfoFactory);
            CallBaseExclusions = new CallBaseExclusions();
            ResultsForType = new ResultsForType(callInfoFactory);

            var getCallSpec = new GetCallSpec(callStack, PendingSpecification, CallSpecificationFactory, CallActions);

            ConfigureCall = new ConfigureCall(CallResults, CallActions, getCallSpec);
            EventHandlerRegistry = new EventHandlerRegistry();
            AutoValueProviders = new IAutoValueProvider[] { 
#if NET45 || NETSTANDARD1_5
                new AutoObservableProvider(() => AutoValueProviders),
                new AutoQueryableProvider(),
#endif
                new AutoSubstituteProvider(substituteFactory), 
                new AutoStringProvider(), 
                new AutoArrayProvider(),
#if (NET4 || NET45 || NETSTANDARD1_5)
                new AutoTaskProvider(() => AutoValueProviders),
#endif
            };
        }
Exemplo n.º 3
0
        public SubstituteState(ISubstitutionContext substitutionContext)
        {
            SubstitutionContext = substitutionContext;
            SubstituteFactory = substitutionContext.SubstituteFactory;
            SequenceNumberGenerator = substitutionContext.SequenceNumberGenerator;
            CallInfoFactory = new CallInfoFactory();
            var callStack = new CallStack();
            CallStack = callStack;
            ReceivedCalls = callStack;
            PendingSpecification = new PendingSpecification();
            CallResults = new CallResults(CallInfoFactory);
            CallSpecificationFactory = NewCallSpecificationFactory();
            CallActions = new CallActions(CallInfoFactory);

            PropertyHelper = new PropertyHelper();
            ResultSetter = new ResultSetter(CallStack, PendingSpecification, CallResults, CallSpecificationFactory, CallActions);
            EventHandlerRegistry = new EventHandlerRegistry();
            ReceivedCallsExceptionThrower = new ReceivedCallsExceptionThrower();
            DefaultForType = new DefaultForType();
            AutoValueProviders = new IAutoValueProvider[] {
                new AutoSubstituteProvider(SubstituteFactory),
                new AutoStringProvider(),
                new AutoArrayProvider(),
            #if NET4
                new AutoTaskProvider(() => AutoValueProviders),
            #endif
            };
        }
Exemplo n.º 4
0
 public SubstituteFactory(ISubstitutionContext context, ICallRouterFactory callRouterFactory, IProxyFactory proxyFactory, ICallRouterResolver callRouterResolver)
 {
     _context = context;
     _callRouterFactory = callRouterFactory;
     _proxyFactory = proxyFactory;
     _callRouterResolver = callRouterResolver;
 }
Exemplo n.º 5
0
        public static SubstituteState Create(ISubstitutionContext substitutionContext)
        {
            var substituteFactory = substitutionContext.SubstituteFactory;
            var callInfoFactory = new CallInfoFactory();
            var callStack = new CallStack();
            var pendingSpecification = new PendingSpecification();
            var callResults = new CallResults(callInfoFactory);
            var callSpecificationFactory = NewCallSpecificationFactory();
            var callActions = new CallActions(callInfoFactory);

            var callFormatter = new CallFormatter(new ArgumentsFormatter(new ArgumentFormatter()), new ArgumentFormatInfoFactory());

            var state = new object[]
            {
                callInfoFactory,
                callStack,
                pendingSpecification,
                callResults,
                callSpecificationFactory,
                substituteFactory,
                callActions,
                new PropertyHelper(),
                new ResultSetter(callStack, pendingSpecification, callResults, callSpecificationFactory, callActions),
                new EventHandlerRegistry(),
                new ReceivedCallsExceptionThrower(callFormatter),
                new DefaultForType(),
                new IAutoValueProvider[] { new AutoSubstituteProvider(substituteFactory), new AutoStringProvider(), new AutoArrayProvider()}
            };

            return new SubstituteState(state);
        }
Exemplo n.º 6
0
 public override void Context()
 {
     base.Context();
     _context            = mock <ISubstitutionContext>();
     _callRouterFactory  = mock <ICallRouterFactory>();
     _proxyFactory       = mock <IProxyFactory>();
     _callRouterResolver = mock <ICallRouterResolver>();
 }
Exemplo n.º 7
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context = context;
            _routeFactory = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 8
0
 public WhenCalled(ISubstitutionContext context, T substitute, Action <T> call, MatchArgs matchArgs)
 {
     _substitute   = substitute;
     _call         = call;
     _matchArgs    = matchArgs;
     _callRouter   = context.GetCallRouterFor(substitute);
     _routeFactory = context.GetRouteFactory();
 }
Exemplo n.º 9
0
 public override void Context()
 {
     value = new object();
     substitutionContext = mock<ISubstitutionContext>();
     temporarilyChange(SubstitutionContext.Current)
         .to(substitutionContext)
         .via(x => SubstitutionContext.Current = x);
 }
Exemplo n.º 10
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context         = context;
            _routeFactory    = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 11
0
 public ICallRouter Create(ISubstitutionContext substitutionContext)
 {
     var substituteState = SubstituteState.Create(substitutionContext);
     var receivedCalls = (IReceivedCalls) substituteState.FindInstanceFor(typeof(IReceivedCalls), null);
     var resultsSetter = (IResultSetter) substituteState.FindInstanceFor(typeof(IResultSetter), null);
     var callHandlerFactory = new CallHandlerFactory();
     return new CallRouter(substitutionContext, receivedCalls, resultsSetter, new RouteFactory(substituteState, callHandlerFactory));
 }
Exemplo n.º 12
0
 public override void Context()
 {
     _substitute = mock<Foo>();
     _substituteFactory = mock<ISubstituteFactory>();
     _substituteFactory.stub(x => x.Create<Foo>()).Return(_substitute);
     _context = mock<ISubstitutionContext>();
     _context.stub(x => x.GetSubstituteFactory()).Return(_substituteFactory);
     temporarilyChange(() => SubstitutionContext.Current).to(_context);
 }
Exemplo n.º 13
0
        public CallRouter(ISubstitutionContext context, IReceivedCalls receivedCalls, IResultSetter resultSetter, IRouteFactory routeFactory)
        {
            _context       = context;
            _receivedCalls = receivedCalls;
            _resultSetter  = resultSetter;
            _routeFactory  = routeFactory;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 14
0
        public ICallRouter Create(ISubstitutionContext substitutionContext)
        {
            var substituteState    = SubstituteState.Create(substitutionContext);
            var receivedCalls      = (IReceivedCalls)substituteState.FindInstanceFor(typeof(IReceivedCalls), null);
            var resultsSetter      = (IResultSetter)substituteState.FindInstanceFor(typeof(IResultSetter), null);
            var callHandlerFactory = new CallHandlerFactory();

            return(new CallRouter(substitutionContext, receivedCalls, resultsSetter, new RouteFactory(substituteState, callHandlerFactory)));
        }
 /// <summary>
 /// Creates an new <see cref="NSubstituteRegisterCallHandlerCommand"/> instance.
 /// </summary>
 public NSubstituteRegisterCallHandlerCommand(
     ISubstitutionContext substitutionContext,
     ICallResultCacheFactory callResultCacheFactory,
     ICallResultResolverFactory callResultResolverFactory)
 {
     this.SubstitutionContext       = substitutionContext ?? throw new ArgumentNullException(nameof(substitutionContext));
     this.CallResultCacheFactory    = callResultCacheFactory ?? throw new ArgumentNullException(nameof(callResultCacheFactory));
     this.CallResultResolverFactory = callResultResolverFactory ?? throw new ArgumentNullException(nameof(callResultResolverFactory));
 }
Exemplo n.º 16
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context = context;
            _routeFactory = routeFactory;
            _receivedCalls = substituteState.ReceivedCalls;
            ConfigureCall = substituteState.ConfigureCall;

            UseDefaultRouteForNextCall();
        }
        public override void Context()
        {
            _routerForSubstitute = mock<ICallRouter>();
                _substitute = mock<IFoo>();
                _context = mock<ISubstitutionContext>();

                _context.stub(x => x.GetCallRouterFor(_substitute)).Return(_routerForSubstitute);

                temporarilyChange(() => SubstitutionContext.Current).to(_context);
        }
Exemplo n.º 18
0
 public override void Context()
 {
     _value = new object();
     _substitutionContext = mock<ISubstitutionContext>();
     _substitutionContext
         .stub(x => x.LastCallShouldReturn(It.IsAny<IReturn>(), It.IsAny<MatchArgs>()))
         .IgnoreArguments()
         .WhenCalled(x => _returnValueSet = (IReturn) x.Arguments[0]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
        public override void Context()
        {
            _routerForSubstitute = mock <ICallRouter>();
            _substitute          = mock <IFoo>();
            _context             = mock <ISubstitutionContext>();

            _context.stub(x => x.GetCallRouterFor(_substitute)).Return(_routerForSubstitute);

            temporarilyChange(() => SubstitutionContext.Current).to(_context);
        }
Exemplo n.º 20
0
        public CallRouter(ISubstituteState substituteState, ISubstitutionContext context, IRouteFactory routeFactory)
        {
            _substituteState = substituteState;
            _context         = context;
            _routeFactory    = routeFactory;
            _receivedCalls   = substituteState.ReceivedCalls;
            ConfigureCall    = substituteState.ConfigureCall;

            UseDefaultRouteForNextCall();
        }
Exemplo n.º 21
0
 public override void Context()
 {
     _value = new object();
     _substitutionContext = mock <ISubstitutionContext>();
     _substitutionContext
     .stub(x => x.LastCallShouldReturn(It.IsAny <IReturn>(), It.IsAny <MatchArgs>()))
     .IgnoreArguments()
     .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[0]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
Exemplo n.º 22
0
            public override void Context()
            {
                _callSpec        = mock <ICallSpecification>();
                _call            = mock <ICall>();
                _callSpecFactory = mock <ICallSpecificationFactory>();
                _context         = mock <ISubstitutionContext>();

                _call.stub(x => x.Target()).Return(_target);
                _callSpecFactory.stub(x => x.CreateFrom(_call, MatchArgs.AsSpecifiedInCall)).Return(_callSpec);
            }
Exemplo n.º 23
0
 public override string Process(string text, ISubstitutionContext context)
 {
     if (!string.IsNullOrEmpty(text))
     {
         return(text.Replace(Environment.NewLine, ""));
     }
     else
     {
         return(text);
     }
 }
Exemplo n.º 24
0
 public override void Context()
 {
     _types             = new[] { typeof(Foo) };
     _constructorArgs   = new[] { new object() };
     _substitute        = mock <Foo>();
     _substituteFactory = mock <ISubstituteFactory>();
     _substituteFactory.stub(x => x.Create(_types, _constructorArgs)).Return(_substitute);
     _context = mock <ISubstitutionContext>();
     _context.stub(x => x.SubstituteFactory).Return(_substituteFactory);
     temporarilyChange(() => SubstitutionContext.Current).to(_context);
 }
Exemplo n.º 25
0
 public override void Context()
 {
     _types = new[] { typeof(Foo) };
     _constructorArgs = new[] { new object() };
     _substitute = mock<Foo>();
     _substituteFactory = mock<ISubstituteFactory>();
     _substituteFactory.stub(x => x.Create(_types, _constructorArgs)).Return(_substitute);
     _context = mock<ISubstitutionContext>();
     _context.stub(x => x.GetSubstituteFactory()).Return(_substituteFactory);
     temporarilyChange(() => SubstitutionContext.Current).to(_context);
 }
 public override void Context()
 {
     _context                  = mock <ISubstitutionContext>();
     _receivedCalls            = mock <IReceivedCalls>();
     _call                     = mock <ICall>();
     _callSpecFromCall         = mock <ICallSpecification>();
     _callSpecificationFactory = mock <ICallSpecificationFactory>();
     _exceptionThrower         = new FakeExceptionThrower();
     _callSpecFromCall.stub(x => x.IsSatisfiedBy(_call)).Return(true);
     _callSpecificationFactory.stub(x => x.CreateFrom(_call, _argMatching)).Return(_callSpecFromCall);
 }
Exemplo n.º 27
0
 public override void Context()
 {
     substitute = mock<Foo>();
     substituteFactory = mock<ISubstituteFactory>();
     substituteFactory.stub(x => x.Create<Foo>()).Return(substitute);
     context = mock<ISubstitutionContext>();
     context.stub(x => x.GetSubstituteFactory()).Return(substituteFactory);
     temporarilyChange(SubstitutionContext.Current)
         .to(context)
         .via(x => SubstitutionContext.Current = x);
 }
        public FluentQuerySubstitutionContext(ISubstitutionContext innerContext)
        {
            this.innerContext = innerContext;

            var callRouterFactory = new FluentCallRouterFactory();
            var dynamicProxyFactory = new CastleDynamicProxyFactory();
            var delegateFactory = new DelegateProxyFactory();
            var proxyFactory = new ProxyFactory(delegateFactory, dynamicProxyFactory);
            var callRouteResolver = new CallRouterResolver();

            this.substituteFactory = new SubstituteFactory(this, callRouterFactory, proxyFactory, callRouteResolver);
        }
Exemplo n.º 29
0
            public override void Context()
            {
                _call = mock <Action <IFoo> >();
                _callbackWithArguments = args => { };
                _matchArgs             = MatchArgs.AsSpecifiedInCall;

                _context    = mock <ISubstitutionContext>();
                _substitute = mock <IFoo>();
                _callRouter = mock <ICallRouter>();

                _context.stub(x => x.GetCallRouterFor(_substitute)).Return(_callRouter);
            }
Exemplo n.º 30
0
        private string GetProcessedItem(ISubstitutionContext context, string input, MessageFieldType itemType)
        {
            Logger.WriteTrace(string.Format("{0} processing ", itemType), SeverityEnum.Trace);
            var worker         = SubstitutionManager.GetWorker(context, itemType);
            var res            = worker.PreProcess(input, context);
            var transformation = TransformationManager.GetTransformation(itemType, context);

            res = transformation.Transform(input, context, worker.OnPartLoaded);
            res = worker.PostProcess(input, context);
            Logger.WriteTrace(string.Format("{0} result: {1}", itemType, res), SeverityEnum.Trace);
            return(res);
        }
Exemplo n.º 31
0
            public Resolver(ISubstitutionContext context, string tempXslt, Func <string, string> processIncludes)
            {
                Logger = Application.Current.Logger;

                if (Logger == null)
                {
                    throw new InvalidProgramException("No logger configured");
                }
                this.tempXslt        = tempXslt;
                this.processIncludes = processIncludes;
                this.m_context       = context;
            }
 public override void Context()
 {
     _sub = mock<IFoo>();
     _substitutionContext = mock<ISubstitutionContext>();
     _callRouter = mock<ICallRouter>();
     _substitutionContext.stub(x => x.GetCallRouterFor(_sub))
                         .IgnoreArguments()
                         .Return(_callRouter);
     _callRouter.stub(x => x.SetReturnForType(It.IsAny<Type>(), It.IsAny<IReturn>()))
                .IgnoreArguments()
                .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[1]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
 public override string Process(string text, ISubstitutionContext context)
 {
     try
     {
         var doc = XDocument.Parse(text);
         return(doc.Root.Value);
     }
     catch (Exception ex)
     {
         Logger.WriteTrace("Cannot remove tags. maybe they are not existed" + ex.Message, SeverityEnum.Verbose);
         return(text);
     }
 }
Exemplo n.º 34
0
    /// Switches the SubstitutionContext to use the custom substitution context that supports monobehaviours.
    /// The same context MUST be used for the entirety of a test,
    /// so this should be called once at the start of the Setup function.
    public static void BeginComponentContext()
    {
        if (SubstitutionContext.Current == componentSubstitutionContext)
        {
            Debug.LogError("Cannot call BeginComponentContext. It has already begun.");
            return;
        }

        CreateContext();

        originalSubstitutionContext = SubstitutionContext.Current;
        SubstitutionContext.Current = componentSubstitutionContext;
    }
 public override void Context()
 {
     _sub = mock <IFoo>();
     _substitutionContext = mock <ISubstitutionContext>();
     _callRouter          = mock <ICallRouter>();
     _substitutionContext.stub(x => x.GetCallRouterFor(_sub))
     .IgnoreArguments()
     .Return(_callRouter);
     _callRouter.stub(x => x.SetReturnForType(It.IsAny <Type>(), It.IsAny <IReturn>()))
     .IgnoreArguments()
     .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[1]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
            public override void Context()
            {
                _context       = mock <ISubstitutionContext>();
                _call          = mock <ICall>();
                _state         = mock <ISubstituteState>();
                _receivedCalls = mock <IReceivedCalls>();
                ConfigureCall  = mock <IConfigureCall>();
                _routeFactory  = mock <IRouteFactory>();
                _state.stub(x => x.ReceivedCalls).Return(_receivedCalls);
                _state.stub(x => x.ConfigureCall).Return(ConfigureCall);

                var recordReplayRoute = CreateRouteThatReturns(_returnValueFromRecordReplayRoute);

                recordReplayRoute.stub(x => x.IsRecordReplayRoute).Return(true);
                _routeFactory.stub(x => x.RecordReplay(_state)).Return(recordReplayRoute);
            }
Exemplo n.º 37
0
        private static void UninstallDiagContext(ISubstitutionContext originalCtx, IDiagnosticsLogger logger)
        {
            var current = SubstitutionContext.Current;

            if (!IsDiagContext(current))
            {
                throw new InvalidOperationException(
                          "You are trying to uninstall diagnostics context while current context is not diagnostics. " +
                          "This is clear indication that something goes wrong." +
                          Environment.NewLine +
                          "Notice, the issue might also happen due to concurrency if you run multiple tests with diagnostics in parallel. " +
                          "In that case please ensure that you run tests sequentially or install the hook globally on an assembly level.");
            }

            SubstitutionContext.Current = originalCtx;
            Log("Restored normal context", logger);
        }
Exemplo n.º 38
0
        public ISubstitutionWorker GetWorker(ISubstitutionContext context, MessageFieldType type)
        {
            switch (type)
            {
            case MessageFieldType.ForBody:
                return(new SubstitutionWorker(ClassContainer.Instance.Resolve <ILogger>(), new List <ISubstitution>
                {
                    new ResourceSubstitution(),
                    new FieldSubstitution(),
                    new ComplexSubstitution(),
                    new ContextVarsSubstitution(),
                },
                                              new List <ISubstitution>
                {
                }));

            case MessageFieldType.ForSubject:
                return(new SubstitutionWorker(ClassContainer.Instance.Resolve <ILogger>(), new List <ISubstitution>
                {
                    new ResourceSubstitution(),
                    new FieldSubstitution(),
                    new ContextVarsSubstitution(),
                },
                                              new List <ISubstitution>
                {
                    new RemoveXmlTagsSubstitution(),
                    new OneLineSubstitution()
                }));

            case MessageFieldType.ForFrom:
            case MessageFieldType.ForReplay:
                return(new SubstitutionWorker(ClassContainer.Instance.Resolve <ILogger>(), new List <ISubstitution>
                {
                    new ResourceSubstitution(),
                    new FieldSubstitution(),
                    new ContextVarsSubstitution(),
                },
                                              new List <ISubstitution>
                {
                    new RemoveXmlTagsSubstitution(),
                    new OneLineSubstitution()
                }));

            default: return(new SubstitutionWorker(ClassContainer.Instance.Resolve <ILogger>(), new List <ISubstitution>(), new List <ISubstitution>()));
            }
        }
Exemplo n.º 39
0
    private static void CreateContext()
    {
        if (componentSubstitutionContext != null)
        {
            return;
        }

        var callRouterFactory   = new CallRouterFactory();
        var dynamicProxyFactory = new ComponentDynamicProxyFactory();
        var delegateFactory     = new DelegateProxyFactory();
        var proxyFactory        = new ComponentProxyFactory(delegateFactory, dynamicProxyFactory);
        var callRouteResolver   = new CallRouterResolver();
        var substituteFactory   = new ComponentSubstituteFactory(callRouterFactory, proxyFactory, callRouteResolver);

        componentSubstitutionContext = new SubstitutionContext(substituteFactory);
        substituteFactory._context   = componentSubstitutionContext;
    }
Exemplo n.º 40
0
        internal static IDisposable Install(IDiagnosticsLogger logger)
        {
            ISubstitutionContext originalContext;

            lock (InstallLock)
            {
                ISubstitutionContext diagnosticsContext = CreateContext(logger);
                originalContext = InstallDiagContext(diagnosticsContext, logger);
            }

            return(new DelegatingDisposable(() =>
            {
                lock (InstallLock)
                {
                    UninstallDiagContext(originalContext, logger);
                }
            }));
        }
        public override string Process(string text, ISubstitutionContext context)
        {
            var res = text;

            foreach (Match m in Regex.Matches(text, Pattern))
            {
                try
                {
                    var value = context.GetContextValue(m.Groups[1].Value);
                    if (value != null)
                    {
                        res = res.Replace(m.Value, value);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteTrace(ex, SeverityEnum.Error);
                }
            }
            return(res);
        }
Exemplo n.º 42
0
        public SubstituteState(ISubstitutionContext substitutionContext, SubstituteConfig option)
        {
            SubstitutionContext     = substitutionContext;
            SubstituteConfig        = option;
            SequenceNumberGenerator = substitutionContext.SequenceNumberGenerator;
            var substituteFactory = substitutionContext.SubstituteFactory;
            var callInfoFactory   = new CallInfoFactory();

            var callCollection = new CallCollection();

            CallCollection = callCollection;
            ReceivedCalls  = callCollection;

            PendingSpecification     = new PendingSpecification(substitutionContext);
            CallResults              = new CallResults(callInfoFactory);
            AutoValuesCallResults    = new CallResults(callInfoFactory);
            CallSpecificationFactory = CallSpecificationFactoryFactoryYesThatsRight.CreateCallSpecFactory();
            CallActions              = new CallActions(callInfoFactory);
            CallBaseExclusions       = new CallBaseExclusions();
            ResultsForType           = new ResultsForType(callInfoFactory);
            CustomHandlers           = new CustomHandlers(this);
            var getCallSpec = new GetCallSpec(callCollection, PendingSpecification, CallSpecificationFactory, CallActions);

            ConfigureCall        = new ConfigureCall(CallResults, CallActions, getCallSpec);
            EventHandlerRegistry = new EventHandlerRegistry();

            AutoValueProviders = new IAutoValueProvider[] {
#if NET45 || NETSTANDARD1_5
                new AutoObservableProvider(() => AutoValueProviders),
                new AutoQueryableProvider(),
#endif
                new AutoSubstituteProvider(substituteFactory),
                new AutoStringProvider(),
                new AutoArrayProvider(),
#if (NET4 || NET45 || NETSTANDARD1_5)
                new AutoTaskProvider(() => AutoValueProviders),
#endif
            };
        }
Exemplo n.º 43
0
        public override string Process(string text, ISubstitutionContext context)
        {
            string res = text;

            foreach (Match m in Regex.Matches(res, Pattern))
            {
                try
                {
                    ModifiersCollection modifiers = ModifiersCollection.Parse(m.Groups[2].Value);
                    string fieldTextValue         = context.GetCurrentFieldValue(m.Groups[1].Value, modifiers);
                    if (fieldTextValue != null)
                    {
                        res = res.Replace(m.Value, fieldTextValue);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteTrace(ex, SeverityEnum.Error);
                }
            }
            return(res);
        }
Exemplo n.º 44
0
        public override string Transform(string template, ISubstitutionContext context, Func <string, string> partIncludedCallback)
        {
            try
            {
                string res = string.Empty;
                var    xml = GetTemplateData(context);
                var    log = new StringBuilder();
                log.AppendLine("Applying XSLT");
                log.AppendLine("Template:");
                log.AppendLine(template);


                if (!template.IsXslt())
                {
                    log.AppendLine("Template is not xslt");
                    res = template;
                }
                else
                {
                    log.AppendLine("Incoming XML");
                    log.AppendLine(xml);
                    res = xml.ApplyXslt(template, context, partIncludedCallback);
                    log.AppendLine("Result:");
                    log.AppendLine(res);
                }
                Logger.WriteTrace(log.ToString(), SeverityEnum.Verbose);
                return(res);
            }
            catch (XsltException ex)
            {
                Logger.WriteTrace("Cannot parse or transform template. maybe because it is not xslt template", ex, SeverityEnum.Warning);
                return(template);
            }
            catch (Exception ex)
            {
                Logger.WriteTrace("ERROR DURIN|G GEMERATING OUTPUT HTML", ex, SeverityEnum.CriticalError);
                return(template);
            }
        }
Exemplo n.º 45
0
        public override string Process(string text, ISubstitutionContext context)
        {
            var res = text;

            foreach (Match m in Regex.Matches(res, @"\{\$(.+)\}"))
            {
                try
                {
                    string value = null;
                    switch (m.Groups[1].Value.ToLower())
                    {
                    case "changes": value = GetGhanges(context); break;

                    default: value = "no " + m.Value; break;
                    }
                    res = res.Replace(m.Value, value);
                }
                catch (Exception ex)
                {
                    Logger.WriteTrace(ex, SeverityEnum.Error);
                }
            }
            return(res);
        }
Exemplo n.º 46
0
        private static ISubstitutionContext InstallDiagContext(ISubstitutionContext newCtx, IDiagnosticsLogger logger)
        {
            if (!IsDiagContext(newCtx))
            {
                throw new ArgumentException($"Diagnostics context is expected. Actual context type: {newCtx.GetType().FullName}");
            }

            var oldContext = SubstitutionContext.Current;

            if (IsDiagContext(oldContext))
            {
                throw new InvalidOperationException(
                          "You are trying to install diagnostics context while other diagnostics context is already installed. " +
                          "This scenario is not supported and might indicate that something is going wrong." +
                          Environment.NewLine +
                          "Notice, the issue might also happen due to concurrency if you run multiple tests with diagnostics in parallel. " +
                          "In that case please ensure that you run tests sequentially or install the hook globally on an assembly level.");
            }

            SubstitutionContext.Current = newCtx;
            Log("Installed diagnostics context", logger);

            return(oldContext);
        }
 public ICallRouter Create(ISubstitutionContext substitutionContext, SubstituteConfig config)
 {
     var state = new SubstituteState(substitutionContext, config);
     return new CallRouter(state, substitutionContext, new FluentQueryCompatibleRouteFactory());
 }
Exemplo n.º 48
0
 public override void Context()
 {
     _value = new object();
     _substitutionContext = mock<ISubstitutionContext>();
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
Exemplo n.º 49
0
 public CallFactory(ISubstitutionContext context)
 {
     _context = context;
 }
 public CallSpecificationFactory(ISubstitutionContext context)
 {
     _context = context;
 }
Exemplo n.º 51
0
 public ICallRouter Create(ISubstitutionContext substitutionContext)
 {
     var substituteState = new SubstituteState(substitutionContext);
     var routePartsFactory = new RoutePartsFactory(substituteState);
     return new CallRouter(substitutionContext, substituteState.ResultSetter, new RouteFactory(routePartsFactory));
 }
 public AddCallToQueryResultHandler(ISubstitutionContext context, ICallSpecificationFactory callSpecificationFactory)
 {
     _context = context;
     _callSpecificationFactory = callSpecificationFactory;
 }
Exemplo n.º 53
0
 public PendingSpecification(ISubstitutionContext substitutionContext)
 {
     _substitutionContext = substitutionContext;
 }
Exemplo n.º 54
0
 public ICallRouter Create(ISubstitutionContext substitutionContext, SubstituteConfig config)
 {
     var substituteState = new SubstituteState(substitutionContext, config);
     return new CallRouter(substituteState, substitutionContext, new RouteFactory());
 }
 public IInvocationHandler CreateInvocationHandler(ISubstitutionContext substitutionContext)
 {
     return new InvocationHandler(new InvocationStack(), new InvocationResults(null), substitutionContext);
 }
 public ClearLastCallRouterHandler(ISubstitutionContext context)
 {
     _context = context;
 }