public void Create_history_context_from_user_context()
        {
            var serviceProvider = TestHelpers.CreateServiceProvider();

            using (var context = new Context(serviceProvider))
            {
                var historyRepository = new HistoryRepository(
                    serviceProvider,
                    new DbContextService <IDbContextOptions>(new DbContextOptions()),
                    new DbContextService <DbContext>(context));

                using (var historyContext = historyRepository.CreateHistoryContext())
                {
                    Assert.Same(historyRepository.HistoryModel, historyContext.Model);

                    var options        = ((IDbContextServices)context).ScopedServiceProvider.GetRequiredService <DbContextService <IDbContextOptions> >();
                    var historyOptions = ((IDbContextServices)historyContext).ScopedServiceProvider.GetRequiredService <DbContextService <IDbContextOptions> >();

                    var extensions        = options.Service.Extensions;
                    var historyExtensions = historyOptions.Service.Extensions;

                    Assert.Equal(extensions.Count, historyExtensions.Count);

                    for (var i = 0; i < extensions.Count; i++)
                    {
                        Assert.Same(extensions[i], historyExtensions[i]);
                    }
                }
            }
        }
Esempio n. 2
0
        public void Get_migrations_query()
        {
            using (var context = new Context())
            {
                var historyRepository = new HistoryRepository(context.Configuration);

                using (var historyContext = historyRepository.CreateHistoryContext())
                {
                    var query = historyRepository.GetMigrationsQuery(historyContext);

                    var expression = (MethodCallExpression)query.Expression;

                    Assert.Equal("OrderBy", expression.Method.Name);
                    Assert.Equal("h => h.MigrationId", expression.Arguments[1].ToString());

                    expression = (MethodCallExpression)expression.Arguments[0];

                    Assert.Equal("Where", expression.Method.Name);
                    Assert.Equal(
                        "h => (h.ContextKey == value(Microsoft.Data.Entity.Migrations.Infrastructure.HistoryRepository).GetContextKey())",
                        expression.Arguments[1].ToString());

                    var queryableType = expression.Arguments[0].Type;

                    Assert.True(queryableType.IsGenericType);
                    Assert.Equal("EntityQueryable", queryableType.Name.Remove(queryableType.Name.IndexOf("`", StringComparison.Ordinal)));
                    Assert.Equal(1, queryableType.GenericTypeArguments.Length);
                    Assert.Equal("HistoryRow", queryableType.GenericTypeArguments[0].Name);
                }
            }
        }
        public void Create_history_context_from_user_context()
        {
            using (var context = new Context())
            {
                var historyRepository = new HistoryRepository(context.Configuration);

                using (var historyContext = historyRepository.CreateHistoryContext())
                {
                    Assert.Same(historyRepository.HistoryModel, historyContext.Model);

                    var extensions        = context.Configuration.ContextOptions.Extensions;
                    var historyExtensions = historyContext.Configuration.ContextOptions.Extensions;

                    Assert.Equal(extensions.Count, historyExtensions.Count);

                    for (var i = 0; i < extensions.Count; i++)
                    {
                        Assert.Same(extensions[i], historyExtensions[i]);
                    }
                }
            }
        }