Beispiel #1
0
        private static IHistoryRepository CreateHistoryRepository(string schema = null)
        {
            var sqlGenerator = new SqlCeSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies());
            var typeMapper   = new SqlCeTypeMapper(new RelationalTypeMapperDependencies());

            var commandBuilderFactory = new RelationalCommandBuilderFactory(
                new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>(),
                typeMapper);

            return(new SqlCeHistoryRepository(
                       new HistoryRepositoryDependencies(
                           Mock.Of <IRelationalDatabaseCreator>(),
                           Mock.Of <IRawSqlCommandBuilder>(),
                           Mock.Of <ISqlCeDatabaseConnection>(),
                           new DbContextOptions <DbContext>(
                               new Dictionary <Type, IDbContextOptionsExtension>
            {
                {
                    typeof(SqlCeOptionsExtension),
                    new SqlCeOptionsExtension().WithMigrationsHistoryTableSchema(schema)
                }
            }),
                           new MigrationsModelDiffer(
                               new SqlCeTypeMapper(new RelationalTypeMapperDependencies()),
                               new SqlCeMigrationsAnnotationProvider(new MigrationsAnnotationProviderDependencies())),
                           new SqlCeMigrationsSqlGenerator(
                               new MigrationsSqlGeneratorDependencies(
                                   commandBuilderFactory,
                                   new SqlCeSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies()),
                                   typeMapper),
                               new SqlCeMigrationsAnnotationProvider(new MigrationsAnnotationProviderDependencies())),
                           sqlGenerator)));
        }
Beispiel #2
0
        private static IHistoryRepository CreateHistoryRepository()
        {
            var annotationsProvider = new SqlCeAnnotationProvider();
            var sqlGenerator        = new SqlCeSqlGenerationHelper();
            var typeMapper          = new SqlCeTypeMapper();

            var commandBuilderFactory = new RelationalCommandBuilderFactory(
                new FakeSensitiveDataLogger <RelationalCommandBuilderFactory>(),
                new DiagnosticListener("Fake"),
                typeMapper);

            return(new SqlCeHistoryRepository(
                       Mock.Of <IRelationalDatabaseCreator>(),
                       Mock.Of <IRawSqlCommandBuilder>(),
                       Mock.Of <ISqlCeDatabaseConnection>(),
                       new DbContextOptions <DbContext>(
                           new Dictionary <Type, IDbContextOptionsExtension>
            {
                { typeof(SqlCeOptionsExtension), new SqlCeOptionsExtension() }
            }),
                       new MigrationsModelDiffer(
                           new SqlCeTypeMapper(),
                           annotationsProvider,
                           new SqlCeMigrationsAnnotationProvider()),
                       new SqlCeMigrationsSqlGenerator(
                           commandBuilderFactory,
                           new SqlCeSqlGenerationHelper(),
                           typeMapper,
                           annotationsProvider),
                       annotationsProvider,
                       sqlGenerator));
        }
Beispiel #3
0
        public void GenerateLiteral_returns_DateTime_literal()
        {
            var value   = new DateTime(2015, 3, 12, 13, 36, 37, 371);
            var literal = new SqlCeTypeMapper(new RelationalTypeMapperDependencies())
                          .GetMapping(typeof(DateTime)).GenerateSqlLiteral(value);

            Assert.Equal("'2015-03-12T13:36:37.371'", literal);
        }
Beispiel #4
0
        public void GenerateLiteral_returns_ByteArray_literal()
        {
            var value   = new byte[] { 0xDA, 0x7A };
            var literal = new SqlCeTypeMapper(new RelationalTypeMapperDependencies())
                          .GetMapping(typeof(byte[])).GenerateSqlLiteral(value);

            Assert.Equal("0xDA7A", literal);
        }
        public void Does_non_key_SQL_Server_rowversion_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(byte[]));

            property.IsConcurrencyToken = true;
            property.ValueGenerated     = ValueGenerated.OnAddOrUpdate;

            var typeMapping = new SqlCeTypeMapper().GetMapping(property);

            Assert.Equal(DbType.Binary, typeMapping.StoreType);
            Assert.Equal("rowversion", typeMapping.DefaultTypeName);
        }
Beispiel #6
0
        public static ConventionSet Build()
        {
            var sqlCeTypeMapper = new SqlCeTypeMapper(new RelationalTypeMapperDependencies());

            return(new SqlCeConventionSetBuilder(
                       new RelationalConventionSetBuilderDependencies(sqlCeTypeMapper, null, null),
                       new SqlCeSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies()))
                   .AddConventions(
                       new CoreConventionSetBuilder(
                           new CoreConventionSetBuilderDependencies(sqlCeTypeMapper))
                       .CreateConventionSet()));
        }
        public void Does_indexed_column_SQL_Server_binary_mapping()
        {
            var entityType = CreateEntityType();
            var property   = entityType.AddProperty("MyProp", typeof(byte[]));

            entityType.AddIndex(property);

            var typeMapping = new SqlCeTypeMapper().GetMapping(property);

            Assert.Equal(DbType.Binary, typeMapping.StoreType);
            Assert.Equal("varbinary(512)", typeMapping.DefaultTypeName);
            Assert.Equal(0, typeMapping.CreateParameter(new TestCommand(), "Name", "Value").Size);
        }
        public void Does_key_SQL_Server_binary_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(byte[]));

            property.IsNullable = false;
            property.DeclaringEntityType.SetPrimaryKey(property);

            var typeMapping = new SqlCeTypeMapper().GetMapping(property);

            Assert.Equal(DbType.Binary, typeMapping.StoreType);
            Assert.Equal("varbinary(512)", typeMapping.DefaultTypeName);
            Assert.Equal(0, typeMapping.CreateParameter(new TestCommand(), "Name", new byte[3]).Size);
        }
        public void Does_indexed_column_SQL_Server_string_mapping()
        {
            var entityType = CreateEntityType();
            var property   = entityType.AddProperty("MyProp", typeof(string));

            entityType.AddIndex(property);

            var typeMapping = new SqlCeTypeMapper().GetMapping(property);

            Assert.Equal(DbType.String, typeMapping.StoreType);
            Assert.Equal("nvarchar(256)", typeMapping.DefaultTypeName);
            Assert.Equal(0, typeMapping.CreateParameter(new TestCommand(), "Name", "Value").Size);
        }
        public void Does_key_SQL_Server_string_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(string));

            property.IsNullable = false;
            property.DeclaringEntityType.SetPrimaryKey(property);

            var typeMapping = new SqlCeTypeMapper().GetMapping(property);

            Assert.Equal(DbType.String, typeMapping.StoreType);
            Assert.Equal("nvarchar(256)", typeMapping.DefaultTypeName);
            Assert.Equal(0, typeMapping.CreateParameter(new TestCommand(), "Name", "Value").Size);
        }
        public void Does_indexed_column_SQL_Server_binary_mapping()
        {
            var entityType = CreateEntityType();
            var property   = entityType.AddProperty("MyProp", typeof(byte[]));

            entityType.AddIndex(property);

            var typeMapping = new SqlCeTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(property);

            Assert.Equal(DbType.Binary, typeMapping.DbType);
            Assert.Equal("varbinary(512)", typeMapping.StoreType);
            Assert.Equal(512, typeMapping.CreateParameter(new TestCommand(), "Name", new byte[3]).Size);
        }
        public void Does_non_key_SQL_Server_rowversion_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(byte[]));

            property.IsConcurrencyToken = true;
            property.ValueGenerated     = ValueGenerated.OnAddOrUpdate;

            var typeMapping = new SqlCeTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(property);

            Assert.Equal(DbType.Binary, typeMapping.DbType);
            Assert.Equal("rowversion", typeMapping.StoreType);
            Assert.Equal(8, typeMapping.Size);
            Assert.Equal(8, typeMapping.CreateParameter(new TestCommand(), "Name", new byte[8]).Size);
        }
        public void Does_indexed_column_SQL_Server_string_mapping()
        {
            var entityType = CreateEntityType();
            var property   = entityType.AddProperty("MyProp", typeof(string));

            entityType.AddIndex(property);

            var typeMapping = new SqlCeTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(property);

            Assert.Equal(DbType.String, typeMapping.DbType);
            Assert.Equal("nvarchar(256)", typeMapping.StoreType);
            Assert.Equal(256, typeMapping.Size);
            Assert.True(typeMapping.IsUnicode);
            Assert.Equal(256, typeMapping.CreateParameter(new TestCommand(), "Name", "Value").Size);
        }
        public void Does_foreign_key_SQL_Server_binary_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(byte[]));

            property.IsNullable = false;
            var fkProperty = property.DeclaringEntityType.AddProperty("FK", typeof(byte[]));
            var pk         = property.DeclaringEntityType.SetPrimaryKey(property);

            property.DeclaringEntityType.AddForeignKey(fkProperty, pk, property.DeclaringEntityType);

            var typeMapping = new SqlCeTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(fkProperty);

            Assert.Equal(DbType.Binary, typeMapping.DbType);
            Assert.Equal("varbinary(512)", typeMapping.StoreType);
            Assert.Equal(512, typeMapping.CreateParameter(new TestCommand(), "Name", new byte[3]).Size);
        }
        public void Does_foreign_key_SQL_Server_string_mapping()
        {
            var property = CreateEntityType().AddProperty("MyProp", typeof(string));

            property.IsNullable = false;
            var fkProperty = property.DeclaringEntityType.AddProperty("FK", typeof(string));
            var pk         = property.DeclaringEntityType.SetPrimaryKey(property);

            property.DeclaringEntityType.AddForeignKey(fkProperty, pk, property.DeclaringEntityType);

            var typeMapping = new SqlCeTypeMapper(new RelationalTypeMapperDependencies()).GetMapping(fkProperty);

            Assert.Equal(DbType.String, typeMapping.DbType);
            Assert.Equal("nvarchar(256)", typeMapping.StoreType);
            Assert.Equal(256, typeMapping.Size);
            Assert.True(typeMapping.IsUnicode);
            Assert.Equal(256, typeMapping.CreateParameter(new TestCommand(), "Name", "Value").Size);
        }