コード例 #1
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));
                    }
                }
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public void Discovers_Quoted_Table_Name()
        {
            string tableName = AutoDiscover.TableName <MyTestClass>(true);

            StringAssert.StartsWith(tableName, "[");
            StringAssert.EndsWith(tableName, "]");
        }