Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AgentTesterBase"/> class.
        /// </summary>
        /// <param name="configureLocalRefData">Indicates whether the pre-set local <see cref="TestSetUp.SetDefaultLocalReferenceData{TRefService, TRefProvider, TRefAgentService, TRefAgent}">reference data</see> is configured.</param>
        protected TesterBase(bool configureLocalRefData = true)
        {
            _serviceCollection.AddLogging(configure => configure.AddTestContext());
            _serviceCollection.AddSingleton(_ => new CachePolicyManager());
            _serviceCollection.AddTransient <IWebApiAgentArgs, WebApiAgentArgs>();

            if (configureLocalRefData)
            {
                TestSetUp.ConfigureDefaultLocalReferenceData(_serviceCollection);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AgentTesterBase"/> class.
        /// </summary>
        /// <param name="configureLocalRefData">Indicates whether the pre-set local <see cref="TestSetUp.SetDefaultLocalReferenceData{TRefService, TRefProvider, TRefAgentService, TRefAgent}">reference data</see> is configured.</param>
        /// <param name="inheritServiceCollection">Indicates whether to use the inherit (copy) the tester <see cref="ServiceCollection"/> (advanced use only).</param>
        /// <param name="useCorrelationIdLogger">Indicates whether to use the <see cref="CorrelationIdLogger"/> versus defaulting to <see cref="TestContextLogger"/>.</param>
        /// <param name="includeLoggingScopesInOutput">Indicates whether to include scopes in log output.</param>
        protected TesterBase(bool configureLocalRefData = true, bool inheritServiceCollection = false, bool useCorrelationIdLogger = false, bool?includeLoggingScopesInOutput = null)
        {
            // Where inheriting then copy the service collection.
            if (inheritServiceCollection && ExecutionContext.HasCurrent && ExecutionContext.Current.Properties.TryGetValue(ServiceCollectionKey, out var sc))
            {
                var coll = (ICollection <ServiceDescriptor>)_serviceCollection;
                foreach (var sd in (ICollection <ServiceDescriptor>)sc)
                {
                    coll.Add(sd);
                }

                return;
            }

            // Where nothing to inherit then create from scratch.
            _serviceCollection.AddSingleton(_ => new CachePolicyManager());
            _serviceCollection.AddLogging(configure =>
            {
                if (useCorrelationIdLogger)
                {
                    configure.AddCorrelationId(includeLoggingScopesInOutput);
                }
                else
                {
                    configure.AddTestContext(includeLoggingScopesInOutput);
                }
            });

            _serviceCollection.AddTransient <IWebApiAgentArgs, WebApiAgentArgs>();
            foreach (var kvp in TestSetUp._webApiAgentArgsTypes)
            {
                _serviceCollection.AddTransient(kvp.Key, kvp.Value);
            }

            if (configureLocalRefData)
            {
                TestSetUp.ConfigureDefaultLocalReferenceData(_serviceCollection);
            }
        }