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]);
                    }
                }
            }
        }
        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("Select", expression.Method.Name);
                    Assert.Equal("h => new MigrationMetadata(h.MigrationId)", expression.Arguments[1].ToString());

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

                    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);
                }
            }
        }