Exemplo n.º 1
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)
                    }
                }
            });
        }
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual void OnIndexRemoved([NotNull] InternalEntityTypeBuilder entityTypeBuilder, [NotNull] Index index)
 => _scope.OnIndexRemoved(entityTypeBuilder, index);