示例#1
0
        public void Fails_On_MisMatch_Column_Manual_Map()
        {
            const string connectionString = "Data Source=(local);Initial Catalog=BulkWriterTest;Integrated Security=SSPI";
            string       tableName        = AutoDiscover.TableName <MyTestClass>(false);

            TestHelpers.ExecuteNonQuery(connectionString,
                                        "CREATE TABLE [dbo].[" + tableName + "](" +
                                        "[Id] [int] IDENTITY(1,1) NOT NULL," +
                                        "[Name] [nvarchar](50) NULL," +
                                        "CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED ([Id] ASC)" +
                                        ")");

            var mapping = MapBuilder
                          .MapAllProperties <MyTestClass>()
                          .MapProperty(x => x.Name, x => x.ToColumnName("MisMatchColumn"));

            IEnumerable <PropertyMapping> propertyMappings = ((MapBuilderContext <MyTestClass>)mapping).GetPropertyMappings();

            try
            {
                AutoDiscover.Mappings(connectionString, tableName, propertyMappings);
            }
            finally
            {
                TestHelpers.ExecuteNonQuery(connectionString, "DROP TABLE " + tableName);
            }
        }
示例#2
0
        public void Maps_Only_Appropriate_Properties()
        {
            const string connectionString = "Data Source=(local);Initial Catalog=BulkWriterTest;Integrated Security=SSPI";
            string       tableName        = AutoDiscover.TableName <MyTestClass>(false);

            TestHelpers.ExecuteNonQuery(connectionString,
                                        "CREATE TABLE [dbo].[" + tableName + "](" +
                                        "[Id] [int] IDENTITY(1,1) NOT NULL," +
                                        "[Name] [nvarchar](50) NULL," +
                                        "CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED ([Id] ASC)" +
                                        ")");

            IMapBuilderContext <MyTestClass> mapping = MapBuilder
                                                       .MapAllProperties <MyTestClass>()
                                                       .MapProperty(x => x.Id, x => x.DoNotMap()); // Do not map this property

            IEnumerable <PropertyMapping> propertyMappings = ((MapBuilderContext <MyTestClass>)mapping).GetPropertyMappings();

            AutoDiscover.Mappings(connectionString, tableName, propertyMappings);

            TestHelpers.ExecuteNonQuery(connectionString, "DROP TABLE " + tableName);

            foreach (PropertyMapping propertyMapping in propertyMappings)
            {
                if (propertyMapping.ShouldMap)
                {
                    for (int i = 0; i < MappingDestination.PropertyIndexCount; i++)
                    {
                        Assert.IsTrue(propertyMapping.Destination.IsPropertySet((MappingProperty)i));
                    }
                }
            }
        }
        public void Fails_On_MisMatch_Column_Manual_Map()
        {
            string connectionString = TestHelpers.ConnectionString;
            string tableName        = BulkWriter.AutoDiscover.TableName <MyTestClass>(false);

            TestHelpers.ExecuteNonQuery(connectionString,
                                        "CREATE TABLE [dbo].[" + tableName + "](" +
                                        "[Id] [int] IDENTITY(1,1) NOT NULL," +
                                        "[Name] [nvarchar](50) NULL," +
                                        "CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED ([Id] ASC)" +
                                        ")");

            var mapping = MapBuilder
                          .MapAllProperties <MyTestClass>()
                          .MapProperty(x => x.Name, x => x.ToColumnName("MisMatchColumn"));

            IEnumerable <BulkWriter.PropertyMapping> propertyMappings = ((BulkWriter.MapBuilderContext <MyTestClass>)mapping).GetPropertyMappings();

            try
            {
                Assert.Throws <InvalidOperationException>(() => AutoDiscover.Mappings(connectionString, tableName, propertyMappings));
            }
            finally
            {
                TestHelpers.ExecuteNonQuery(connectionString, "DROP TABLE " + tableName);
            }
        }
        public void Initialize_Test()
        {
            this.enumerable = new[] { new MyTestClass() };

            TestHelpers.ExecuteNonQuery(connectionString,
                                        "CREATE TABLE [dbo].[" + tableName + "](" +
                                        "[Id] [int] IDENTITY(1,1) NOT NULL," +
                                        "[Name] [nvarchar](50) NULL," +
                                        "CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED ([Id] ASC)" +
                                        ")");

            var mapping          = MapBuilder.MapAllProperties <MyTestClass>();
            var propertyMappings = ((MapBuilderContext <MyTestClass>)mapping).GetPropertyMappings();

            AutoDiscover.Mappings(connectionString, tableName, propertyMappings);

            this.dataReader = new EnumerableDataReader <MyTestClass>(enumerable, propertyMappings);
            dataReader.Read();
        }
示例#5
0
        public void Can_Find_Column_Manual_Map()
        {
            const string connectionString = "Data Source=(local);Initial Catalog=BulkWriterTest;Integrated Security=SSPI";
            const string tableName        = "TempTestTable";

            TestHelpers.ExecuteNonQuery(connectionString,
                                        "CREATE TABLE [dbo].[" + tableName + "](" +
                                        "[Id] [int] IDENTITY(1,1) NOT NULL," +
                                        "[ManualColumnName] [nvarchar](50) NULL," +
                                        "CONSTRAINT [PK_" + tableName + "] PRIMARY KEY CLUSTERED ([Id] ASC)" +
                                        ")");

            IMapBuilderContext <MyTestClass> mapping = MapBuilder
                                                       .MapAllProperties <MyTestClass>()
                                                       .DestinationTable(tableName)
                                                       .MapProperty(x => x.Name, x => x.ToColumnName("ManualColumnName"));

            IEnumerable <PropertyMapping> propertyMappings = ((MapBuilderContext <MyTestClass>)mapping).GetPropertyMappings();

            AutoDiscover.Mappings(connectionString, tableName, propertyMappings);

            TestHelpers.ExecuteNonQuery(connectionString, "DROP TABLE " + tableName);

            foreach (PropertyMapping propertyMapping in propertyMappings)
            {
                Assert.IsTrue(propertyMapping.ShouldMap);

                if (propertyMapping.ShouldMap)
                {
                    for (int i = 0; i < MappingDestination.PropertyIndexCount; i++)
                    {
                        Assert.IsTrue(propertyMapping.Destination.IsPropertySet((MappingProperty)i));
                    }
                }
            }
        }