Ejemplo n.º 1
0
        public void IsNarrowerThan_should_return_true_when_max_length_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                                   {
                                       MaxLength = 1
                                   };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                                   {
                                       MaxLength = 2
                                   };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                               {
                                   MaxLength = 1
                               };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                               {
                                   MaxLength = 1
                               };

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
Ejemplo n.º 2
0
        public void IsNarrowerThan_should_return_true_when_nullable_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                                   {
                                       IsNullable = false
                                   };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                                   {
                                       IsNullable = true
                                   };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                               {
                                   IsNullable = false
                               };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                               {
                                   IsNullable = false
                               };

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
Ejemplo n.º 3
0
        public void IsNarrowerThan_should_return_true_when_scale_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal)
                                   {
                                       Scale = 1
                                   };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal)
                                   {
                                       Scale = 2
                                   };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal)
                               {
                                   Scale = 1
                               };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal);

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal)
                               {
                                   Scale = 1
                               };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
        public void IsNarrowerThan_should_return_true_when_max_length_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 2
                };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines if this column is a narrower data type than another column.
        /// Used to determine if altering the supplied column definition to this definition will result in data loss.
        /// </summary>
        /// <param name="column"> The column to compare to. </param>
        /// <param name="providerManifest"> Details of the database provider being used. </param>
        /// <returns> True if this column is of a narrower data type. </returns>
        public bool IsNarrowerThan(ColumnModel column, DbProviderManifest providerManifest)
        {
            Check.NotNull <ColumnModel>(column, nameof(column));
            Check.NotNull <DbProviderManifest>(providerManifest, nameof(providerManifest));
            TypeUsage storeType1 = providerManifest.GetStoreType(this.TypeUsage);
            TypeUsage storeType2 = providerManifest.GetStoreType(column.TypeUsage);

            if (ColumnModel._typeSize[this.Type] >= ColumnModel._typeSize[column.Type])
            {
                bool?isUnicode1 = this.IsUnicode;
                if ((isUnicode1.HasValue ? (isUnicode1.GetValueOrDefault() ? 1 : 0) : 1) == 0)
                {
                    bool?isUnicode2 = column.IsUnicode;
                    if ((isUnicode2.HasValue ? (isUnicode2.GetValueOrDefault() ? 1 : 0) : 1) != 0)
                    {
                        goto label_6;
                    }
                }
                bool?isNullable1 = this.IsNullable;
                if ((isNullable1.HasValue ? (isNullable1.GetValueOrDefault() ? 1 : 0) : 1) == 0)
                {
                    bool?isNullable2 = column.IsNullable;
                    if ((isNullable2.HasValue ? (isNullable2.GetValueOrDefault() ? 1 : 0) : 1) != 0)
                    {
                        goto label_6;
                    }
                }
                return(ColumnModel.IsNarrowerThan(storeType1, storeType2));
            }
label_6:
            return(true);
        }
 [Fact] // CodePlex 478
 public void IsNarrowerThan_should_handle_every_supported_primitive_type()
 {
     var booleanColumnModel = new ColumnModel(PrimitiveTypeKind.Boolean);
     foreach (var typeKind in Enum.GetValues(typeof(PrimitiveTypeKind))
                                  .OfType<PrimitiveTypeKind>()
                                  .Where(t => t != PrimitiveTypeKind.SByte))
     {
         booleanColumnModel.IsNarrowerThan(new ColumnModel(typeKind), _providerManifest);
     }
 }
Ejemplo n.º 7
0
        public void IsNarrowerThan_should_return_true_when_type_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.Int16);
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.Int32);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Int16);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Int64);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Int32);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Int16);

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
        public void IsNarrowerThan_should_return_true_when_unicode_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String) { IsUnicode = false };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String) { IsUnicode = true };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String) { IsUnicode = false };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String) { IsUnicode = false };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
        public void IsNarrowerThan_should_return_true_when_type_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.Int16);
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.Int32);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Int16);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Int64);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Int32);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Int16);

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
        public void IsNarrowerThan_should_return_true_when_scale_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal) { Scale = 1 };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal) { Scale = 2 };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal) { Scale = 1 };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal);

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.Decimal);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.Decimal) { Scale = 1 };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
 [Fact] // CodePlex 478
 public void IsNarrowerThan_should_handle_every_supported_primitive_type()
 {
     var booleanColumnModel = new ColumnModel(PrimitiveTypeKind.Boolean);
     foreach (var typeKind in Enum.GetValues(typeof(PrimitiveTypeKind))
                                  .OfType<PrimitiveTypeKind>()
                                  .Where(t => t != PrimitiveTypeKind.SByte))
     {
         booleanColumnModel.IsNarrowerThan(new ColumnModel(typeKind), _providerManifest);
     }
 }