コード例 #1
0
 public override IServiceCollection AddProviderServices(IServiceCollection services)
 => FakeRelationalOptionsExtension.AddEntityFrameworkRelationalDatabase(services);
コード例 #2
0
        public void Every_eventId_has_a_logger_method_and_logs_when_level_enabled()
        {
            var constantExpression = Expression.Constant("A");
            var model      = new Model();
            var entityType = new EntityType(typeof(object), model, ConfigurationSource.Convention);
            var property   = entityType.AddProperty("A", typeof(int), ConfigurationSource.Convention, ConfigurationSource.Convention);
            var key        = entityType.AddKey(property, ConfigurationSource.Convention);
            var foreignKey = new ForeignKey(new List <Property> {
                property
            }, key, entityType, entityType, ConfigurationSource.Convention);
            var index = new Index(new List <Property> {
                property
            }, "IndexName", entityType, ConfigurationSource.Convention);
            var contextServices = RelationalTestHelpers.Instance.CreateContextServices(model.FinalizeModel());

            var fakeFactories = new Dictionary <Type, Func <object> >
            {
                { typeof(string), () => "Fake" },
                { typeof(IList <string>), () => new List <string> {
                      "Fake1", "Fake2"
                  } },
                {
                    typeof(IEnumerable <IUpdateEntry>), () => new List <IUpdateEntry>
                    {
                        new InternalClrEntityEntry(
                            contextServices.GetRequiredService <IStateManager>(),
                            entityType,
                            new object())
                    }
                },
                { typeof(IRelationalConnection), () => new FakeRelationalConnection() },
                { typeof(LoggingDefinitions), () => new TestRelationalLoggingDefinitions() },
                { typeof(DbCommand), () => new FakeDbCommand() },
                { typeof(DbTransaction), () => new FakeDbTransaction() },
                { typeof(DbDataReader), () => new FakeDbDataReader() },
                { typeof(Transaction), () => new CommittableTransaction() },
                { typeof(IMigrator), () => new FakeMigrator() },
                { typeof(Migration), () => new FakeMigration() },
                { typeof(IMigrationsAssembly), () => new FakeMigrationsAssembly() },
                { typeof(MethodCallExpression), () => Expression.Call(constantExpression, typeof(object).GetMethod("ToString")) },
                { typeof(Expression), () => constantExpression },
                { typeof(IEntityType), () => entityType },
                { typeof(IProperty), () => property },
                { typeof(IKey), () => key },
                { typeof(IForeignKey), () => foreignKey },
                { typeof(IIndex), () => index },
                { typeof(TypeInfo), () => typeof(object).GetTypeInfo() },
                { typeof(Type), () => typeof(object) },
                { typeof(ValueConverter), () => new BoolToZeroOneConverter <int>() },
                { typeof(DbContext), () => new FakeDbContext() },
                { typeof(SqlExpression), () => new FakeSqlExpression() }
            };

            TestEventLogging(
                typeof(RelationalEventId),
                typeof(RelationalLoggerExtensions),
                new[]
            {
                typeof(IRelationalConnectionDiagnosticsLogger),
                typeof(IRelationalCommandDiagnosticsLogger)
            },
                new TestRelationalLoggingDefinitions(),
                fakeFactories,
                services => FakeRelationalOptionsExtension.AddEntityFrameworkRelationalDatabase(services),
                new Dictionary <string, IList <string> >
            {
                {
                    nameof(RelationalEventId.CommandExecuting),
                    new List <string>
                    {
                        nameof(IRelationalCommandDiagnosticsLogger.CommandReaderExecuting),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandScalarExecuting),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandNonQueryExecuting),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandReaderExecutingAsync),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandScalarExecutingAsync),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandNonQueryExecutingAsync)
                    }
                },
                {
                    nameof(RelationalEventId.CommandExecuted),
                    new List <string>
                    {
                        nameof(IRelationalCommandDiagnosticsLogger.CommandReaderExecutedAsync),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandScalarExecutedAsync),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandNonQueryExecutedAsync),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandReaderExecuted),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandScalarExecuted),
                        nameof(IRelationalCommandDiagnosticsLogger.CommandNonQueryExecuted)
                    }
                }
            });
        }
 public override IServiceCollection AddProviderServices(IServiceCollection services)
 {
     ConfigureServices?.Invoke(services);
     return(FakeRelationalOptionsExtension.AddEntityFrameworkRelationalDatabase(services));
 }