示例#1
0
            protected TestModelBuilder(TestHelpers testHelpers)
            {
                var options = new LoggingOptions();

                options.Initialize(new DbContextOptionsBuilder().EnableSensitiveDataLogging(false).Options);
                ValidationLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Validation.Name);
                var validationLogger = new DiagnosticsLogger <DbLoggerCategory.Model.Validation>(
                    ValidationLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"));

                ModelLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Name);
                var modelLogger = new DiagnosticsLogger <DbLoggerCategory.Model>(
                    ModelLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"));

                var contextServices = testHelpers.CreateContextServices();

                var conventionSet = new CompositeConventionSetBuilder(
                    contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList())
                                    .AddConventions(
                    new CoreConventionSetBuilder(
                        contextServices.GetRequiredService <CoreConventionSetBuilderDependencies>().With(modelLogger))
                    .CreateConventionSet());

                conventionSet.ModelBuiltConventions.Add(
                    new ValidatingConvention(
                        new ModelValidator(new ModelValidatorDependencies(validationLogger, modelLogger))));

                ModelBuilder = new ModelBuilder(conventionSet);
            }
示例#2
0
    public ICommandBatchPreparer CreateCommandBatchPreparer(
        IModificationCommandBatchFactory modificationCommandBatchFactory = null,
        IUpdateAdapter updateAdapter = null,
        bool sensitiveLogging        = false)
    {
        modificationCommandBatchFactory ??=
        RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService <IModificationCommandBatchFactory>();

        var loggingOptions = new LoggingOptions();

        if (sensitiveLogging)
        {
            loggingOptions.Initialize(new DbContextOptionsBuilder <DbContext>().EnableSensitiveDataLogging().Options);
        }

        return(new CommandBatchPreparer(
                   new CommandBatchPreparerDependencies(
                       modificationCommandBatchFactory,
                       new ParameterNameGeneratorFactory(new ParameterNameGeneratorDependencies()),
                       new ModificationCommandComparer(),
                       new KeyValueIndexFactorySource(),
                       new ModificationCommandFactory(),
                       loggingOptions,
                       new FakeDiagnosticsLogger <DbLoggerCategory.Update>(),
                       new DbContextOptionsBuilder().Options)));
    }
        public ICommandBatchPreparer CreateCommandBatchPreparer(
            IModificationCommandBatchFactory modificationCommandBatchFactory = null,
            IStateManager stateManager = null,
            bool sensitiveLogging      = false)
        {
            modificationCommandBatchFactory =
                modificationCommandBatchFactory
                ?? Instance.CreateContextServices().GetRequiredService <IModificationCommandBatchFactory>();

            stateManager = stateManager
                           ?? Instance.CreateContextServices().GetRequiredService <IStateManager>();

            var loggingOptions = new LoggingOptions();

            if (sensitiveLogging)
            {
                loggingOptions.Initialize(new DbContextOptionsBuilder <DbContext>().EnableSensitiveDataLogging().Options);
            }

            return(new CommandBatchPreparer(new CommandBatchPreparerDependencies(
                                                modificationCommandBatchFactory,
                                                new ParameterNameGeneratorFactory(new ParameterNameGeneratorDependencies()),
                                                new ModificationCommandComparer(),
                                                new KeyValueIndexFactorySource(),
                                                () => stateManager,
                                                loggingOptions)));
        }
示例#4
0
            protected TestModelBuilder(TestHelpers testHelpers, Action <ModelConfigurationBuilder>?configure)
            {
                var options = new LoggingOptions();

                options.Initialize(new DbContextOptionsBuilder().EnableSensitiveDataLogging(false).Options);
                ValidationLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Validation.Name);
                ValidationLogger        = new DiagnosticsLogger <DbLoggerCategory.Model.Validation>(
                    ValidationLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"),
                    testHelpers.LoggingDefinitions,
                    new NullDbContextLogger());

                ModelLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Name);
                var modelLogger = new DiagnosticsLogger <DbLoggerCategory.Model>(
                    ModelLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"),
                    testHelpers.LoggingDefinitions,
                    new NullDbContextLogger());

                ModelBuilder = testHelpers.CreateConventionBuilder(
                    modelLogger,
                    ValidationLogger,
                    configure);
            }
        private static ICommandBatchPreparer CreateCommandBatchPreparer(
            IModificationCommandBatchFactory modificationCommandBatchFactory = null,
            ICurrentDbContext currentDbContext = null,
            bool sensitiveLogging = false)
        {
            modificationCommandBatchFactory =
                modificationCommandBatchFactory
                ?? RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService <IModificationCommandBatchFactory>();

            currentDbContext = currentDbContext
                               ?? RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService <ICurrentDbContext>();

            var loggingOptions = new LoggingOptions();

            if (sensitiveLogging)
            {
                loggingOptions.Initialize(new DbContextOptionsBuilder <DbContext>().EnableSensitiveDataLogging().Options);
            }

            return(new CommandBatchPreparer(modificationCommandBatchFactory,
                                            new ParameterNameGeneratorFactory(new ParameterNameGeneratorDependencies()),
                                            new ModificationCommandComparer(),
                                            new KeyValueIndexFactorySource(),
                                            currentDbContext,
                                            loggingOptions));
        }
示例#6
0
        private DiagnosticsLogger <DbLoggerCategory.Database.Transaction> CreateLogger()
        {
            var options = new LoggingOptions();

            options.Initialize(new DbContextOptionsBuilder().ConfigureWarnings(w => w.Default(WarningBehavior.Throw)).Options);
            var logger = new DiagnosticsLogger <DbLoggerCategory.Database.Transaction>(
                new ListLoggerFactory(l => false),
                options,
                new DiagnosticListener("Fake"));

            return(logger);
        }
        private DiagnosticsLogger <DbLoggerCategory.Model> CreateLogger()
        {
            ListLoggerFactory.Clear();
            var options = new LoggingOptions();

            options.Initialize(new DbContextOptionsBuilder().EnableSensitiveDataLogging(false).Options);
            var modelLogger = new DiagnosticsLogger <DbLoggerCategory.Model>(
                ListLoggerFactory,
                options,
                new DiagnosticListener("Fake"));

            return(modelLogger);
        }
            protected TestModelBuilder(TestHelpers testHelpers)
            {
                Log = new List <(LogLevel, EventId, string)>();
                var options = new LoggingOptions();

                options.Initialize(new DbContextOptionsBuilder().EnableSensitiveDataLogging(false).Options);
                var validationLogger = new DiagnosticsLogger <DbLoggerCategory.Model.Validation>(
                    new ListLoggerFactory(Log, l => l == DbLoggerCategory.Model.Validation.Name),
                    options,
                    new DiagnosticListener("Fake"));
                var modelLogger = new DiagnosticsLogger <DbLoggerCategory.Model>(
                    new ListLoggerFactory(Log, l => l == DbLoggerCategory.Model.Name),
                    options,
                    new DiagnosticListener("Fake"));

                var contextServices = testHelpers.CreateContextServices();

                ModelBuilder = new ModelBuilder(contextServices.GetRequiredService <IConventionSetBuilder>().AddConventions(new CoreConventionSetBuilder(
                                                                                                                                contextServices.GetRequiredService <CoreConventionSetBuilderDependencies>().With(modelLogger))
                                                                                                                            .CreateConventionSet()));

                ModelValidator = new ModelValidator(new ModelValidatorDependencies(validationLogger, modelLogger));
            }