public void SetAutoIncrementTrue()
        {
            var column = this.RandomOrDefault(item => CremaDataTypeUtility.CanUseAutoIncrement(item.DataType) && item.AutoIncrement == false && item.DefaultValue == DBNull.Value);

            column.AutoIncrement = true;
            Assert.AreEqual(true, column.AutoIncrement);
        }
Example #2
0
        public void SetAutoIncrement(ITableColumn column, TaskContext context)
        {
            column.Dispatcher.Invoke(() =>
            {
                var autoIncrement = RandomUtility.NextBoolean();
                if (Verify(autoIncrement) == false)
                {
                    return;
                }
                column.SetAutoIncrement(context.Authentication, autoIncrement);
            });

            bool Verify(bool autoIncrement)
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (autoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false)
                {
                    return(false);
                }
                return(true);
            }
        }
        public void SetAutoIncrementToInvalidIncrementType()
        {
            var column = this.RandomOrDefault(item => CremaDataTypeUtility.CanUseAutoIncrement(item.DataType) == false && item.CremaType == null && item.DefaultValue == DBNull.Value);

            column.AutoIncrement = true;
            Assert.AreEqual(typeof(int), column.DataType);
            Assert.AreEqual(true, column.AutoIncrement);
        }
Example #4
0
        public static void InitializeRandom(this CremaDataColumn dataColumn)
        {
            var dataTable = dataColumn.Table;

            if (RandomUtility.Within(75) == true)
            {
                dataColumn.DataType = CremaDataTypeUtility.GetBaseTypes().Random();
            }
            else if (dataTable != null && dataTable.DataSet != null && dataTable.DataSet.Types.Any())
            {
                dataColumn.CremaType = dataTable.DataSet.Types.Random();
            }

            if (RandomUtility.Within(25) == true)
            {
                SetHopeType(dataColumn);
            }

            if (dataTable != null && dataTable.PrimaryKey.Any() == false)
            {
                dataColumn.IsKey = true;
            }
            else if (RandomUtility.Within(10) && dataColumn.DataType != typeof(bool))
            {
                dataColumn.IsKey  = true;
                dataColumn.Unique = RandomUtility.Within(75);
            }

            if (RandomUtility.Within(25) && dataColumn.DataType != typeof(bool))
            {
                var unique = RandomUtility.Within(75);
                if (unique != false || dataTable == null || dataTable.PrimaryKey.Count() != 1)
                {
                    dataColumn.Unique = unique;
                }
            }

            if (RandomUtility.Within(25) == true)
            {
                dataColumn.Comment = RandomUtility.NextString();
            }

            if (RandomUtility.Within(25) == true)
            {
                dataColumn.DefaultValue = dataColumn.GetRandomValue();
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(dataColumn.DataType) == true && dataColumn.DefaultValue == DBNull.Value)
            {
                dataColumn.AutoIncrement = RandomUtility.NextBoolean();
            }

            if (RandomUtility.Within(5) == true)
            {
                dataColumn.ReadOnly = true;
            }
        }
        public static async Task InitializeRandomAsync(this ITableColumn tableColumn, Authentication authentication)
        {
            var template = tableColumn.Template;
            var table    = tableColumn.Template.Target;

            if (RandomUtility.Within(75) == true)
            {
                await tableColumn.SetDataTypeAsync(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random(item => item != typeof(bool).GetTypeName()));
            }
            else
            {
                await tableColumn.SetDataTypeAsync(authentication, template.SelectableTypes.Random());
            }

            if (template.Count == 0)
            {
                await tableColumn.SetIsKeyAsync(authentication, true);
            }
            else if (RandomUtility.Within(10) && tableColumn.DataType != typeof(bool).GetTypeName())
            {
                await tableColumn.SetIsKeyAsync(authentication, true);

                await tableColumn.SetIsUniqueAsync(authentication, RandomUtility.Within(75));
            }

            if (RandomUtility.Within(25) && tableColumn.DataType != typeof(bool).GetTypeName())
            {
                var unique = RandomUtility.Within(75);
                if (unique != false || template.PrimaryKey.Count() != 1)
                {
                    await tableColumn.SetIsUniqueAsync(authentication, unique);
                }
            }

            if (RandomUtility.Within(25) == true)
            {
                await tableColumn.SetCommentAsync(authentication, RandomUtility.NextString());
            }

            if (RandomUtility.Within(25) == true)
            {
                await tableColumn.SetDefaultValueAsync(authentication, await tableColumn.GetRandomStringAsync());
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(tableColumn.DataType) == true && tableColumn.DefaultValue == null)
            {
                await tableColumn.SetAutoIncrementAsync(authentication, RandomUtility.NextBoolean());
            }

            if (RandomUtility.Within(5) == true)
            {
                await tableColumn.SetIsReadOnlyAsync(authentication, true);
            }
        }
Example #6
0
        public async Task SetAutoIncrementAsync(ITableColumn column, TaskContext context)
        {
            var authentication = context.Authentication;
            var autoIncrement  = RandomUtility.NextBoolean();

            if (context.AllowException == false)
            {
                if (autoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false)
                {
                    return;
                }
            }
            await column.SetAutoIncrementAsync(authentication, autoIncrement);
        }
Example #7
0
        public static void InitializeRandom(this CremaAttribute attribute)
        {
            attribute.DataType = CremaDataTypeUtility.GetBaseTypes().Random();

            if (RandomUtility.Within(25) == true)
            {
                attribute.Comment = RandomUtility.NextString();
            }

            if (RandomUtility.Within(25) == true)
            {
                attribute.DefaultValue = RandomUtility.Next(attribute.DataType);
            }

            if (RandomUtility.Within(25) == true && CremaDataTypeUtility.CanUseAutoIncrement(attribute.DataType) == true && attribute.DefaultValue == DBNull.Value)
            {
                attribute.AutoIncrement = RandomUtility.NextBoolean();
            }
        }
Example #8
0
        public static bool CreateColumn(this CremaDataTable dataTable)
        {
            var columnName = RandomUtility.NextIdentifier();

            if (dataTable.Columns.Contains(columnName) == true)
            {
                return(false);
            }

            var column = dataTable.Columns.Add(columnName);

            if (dataTable.PrimaryKey.Any() == false)
            {
                column.IsKey = true;
            }
            else if (RandomUtility.Within(10))
            {
                column.IsKey  = true;
                column.Unique = RandomUtility.Within(75);
            }

            if (RandomUtility.Within(75) == true)
            {
                column.DataType = CremaDataTypeUtility.GetType(CremaDataTypeUtility.GetBaseTypeNames().Random());
            }
            else if (dataTable.DataSet.Types.Any())
            {
                column.CremaType = dataTable.DataSet.Types.Random();
            }

            if (RandomUtility.Within(25) == true)
            {
                column.Comment = RandomUtility.NextString();
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == true)
            {
                column.AutoIncrement = RandomUtility.NextBoolean();
            }

            return(true);
        }
Example #9
0
        public void SetDataType(ITableColumn column, TaskContext context)
        {
            column.Dispatcher.Invoke(() =>
            {
                var template = column.Template;
                if (RandomUtility.Within(75) == true)
                {
                    var dataType = CremaDataTypeUtility.GetBaseTypeNames().Random();
                    if (Verify(dataType) == false)
                    {
                        return;
                    }
                    column.SetDataType(context.Authentication, dataType);
                }
                else
                {
                    var dataType = template.SelectableTypes.Random();
                    if (Verify(dataType) == false)
                    {
                        return;
                    }
                    column.SetDataType(context.Authentication, dataType);
                }
            });

            bool Verify(string dataType)
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (column.AutoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false)
                {
                    return(false);
                }
                return(true);
            }
        }
Example #10
0
        public async Task SetDataTypeAsync(ITableColumn column, TaskContext context)
        {
            var authentication = context.Authentication;
            var template       = column.Template;

            if (RandomUtility.Within(75) == true)
            {
                var dataType = CremaDataTypeUtility.GetBaseTypeNames().Random();
                if (Verify(dataType) == false)
                {
                    return;
                }
                await column.SetDataTypeAsync(authentication, dataType);
            }
            else
            {
                var dataType = template.SelectableTypes.Random();
                if (Verify(dataType) == false)
                {
                    return;
                }
                await column.SetDataTypeAsync(authentication, dataType);
            }

            bool Verify(string dataType)
            {
                if (context.AllowException == true)
                {
                    return(true);
                }
                if (column.AutoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false)
                {
                    return(false);
                }
                return(true);
            }
        }
        public void SetAutoIncrementTrueToDefaultValueColumn_Fail()
        {
            var column = this.RandomOrDefault(item => CremaDataTypeUtility.CanUseAutoIncrement(item.DataType) && item.AutoIncrement == false && item.DefaultValue != DBNull.Value);

            column.AutoIncrement = true;
        }
Example #12
0
        public static void RandomTask(CremaTemplate template, int tryCount)
        {
            for (int i = 0; i < tryCount; i++)
            {
                if (RandomUtility.Within(3) == true)
                {
                    var column = template.Columns.Random();
                    if (column.CanDelete == true)
                    {
                        column.Delete();
                    }
                }
                else if (RandomUtility.Within(5) == true)
                {
                    var column = template.NewColumn();
                    column.Name  = RandomUtility.NextIdentifier();
                    column.IsKey = RandomUtility.Within(5);
                    //column.IsUnique = RandomUtility.Within(10);
                    column.AutoIncrement = RandomUtility.Within(10);
                    column.DataTypeName  = template.Types.Random();

                    try
                    {
                        template.Columns.Add(column);
                    }
                    catch { }
                }
                else
                {
                    var column = template.Columns.Random();
                    column.Name  = RandomUtility.NextIdentifier();
                    column.Index = RandomUtility.Next(template.Columns.Count);

                    try
                    {
                        if (RandomUtility.Within(5) == true)
                        {
                            column.DataTypeName = template.Types.Random();
                        }
                    }
                    catch { }

                    try
                    {
                        if (RandomUtility.Within(5) == true && CremaDataTypeUtility.CanUseAutoIncrement(column.DataTypeName) == true)
                        {
                            column.AutoIncrement = RandomUtility.NextBoolean();
                        }
                    }
                    catch { }

                    try
                    {
                        if (RandomUtility.Within(5) == true)
                        {
                            column.Unique = RandomUtility.NextBoolean();
                        }
                    }
                    catch { }

                    if (RandomUtility.Within(5) == true)
                    {
                        column.Comment = RandomUtility.NextString();
                    }
                }
            }
        }
 public void SetAutoIncrementTrue()
 {
     this.column.DataType      = CremaDataTypeUtility.GetBaseTypes().Random(item => CremaDataTypeUtility.CanUseAutoIncrement(item));
     this.column.AutoIncrement = true;
     Assert.AreEqual(true, this.column.AutoIncrement);
 }
 public void SetAutoIncrementTrueToDefaultValueColumn_Fail()
 {
     this.column.DataType      = CremaDataTypeUtility.GetBaseTypes().Random(item => CremaDataTypeUtility.CanUseAutoIncrement(item));
     this.column.DefaultValue  = RandomUtility.Next(this.column.DataType);
     this.column.AutoIncrement = true;
 }
Example #15
0
 public void SetAutoIncrementFalse()
 {
     this.attribute.DataType      = CremaDataTypeUtility.GetBaseTypes().Random(item => CremaDataTypeUtility.CanUseAutoIncrement(item));
     this.attribute.AutoIncrement = true;
     this.attribute.AutoIncrement = false;
     Assert.AreEqual(false, this.attribute.AutoIncrement);
 }
Example #16
0
        public static bool CreateColumn(this ITableTemplate template, Authentication authentication)
        {
            var columnName = RandomUtility.NextIdentifier();

            if (template.Contains(columnName) == true)
            {
                return(false);
            }

            var column = template.AddNew(authentication);

            column.SetName(authentication, columnName);

            if (template.PrimaryKey.Any() == false)
            {
                column.SetIsKey(authentication, true);
            }
            else if (template.Count == 0 && RandomUtility.Within(10))
            {
                column.SetIsKey(authentication, true);
                column.SetIsUnique(authentication, RandomUtility.Within(75));
            }

            if (RandomUtility.Within(75) == true)
            {
                column.SetTags(authentication, TagInfo.All);
            }
            else
            {
                column.SetTags(authentication, tags.Random());
            }

            if (RandomUtility.Within(75) == true)
            {
                column.SetDataType(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random());
            }
            else
            {
                column.SetDataType(authentication, template.SelectableTypes.Random());
            }

            if (RandomUtility.Within(25) == true)
            {
                column.SetComment(authentication, RandomUtility.NextString());
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == true)
            {
                column.SetAutoIncrement(authentication, RandomUtility.NextBoolean());
            }

            try
            {
                template.EndNew(authentication, column);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Example #17
0
 public void SetAutoIncrementToInvalidIncrementType()
 {
     this.attribute.DataType      = CremaDataTypeUtility.GetBaseTypes().Random(item => CremaDataTypeUtility.CanUseAutoIncrement(item) == false);
     this.attribute.AutoIncrement = true;
     Assert.AreEqual(typeof(int), this.attribute.DataType);
     Assert.AreEqual(true, this.attribute.AutoIncrement);
 }
        public void SetDefaultValueToAutoIncrementColumn_Fail()
        {
            this.column.DataType      = CremaDataTypeUtility.GetBaseTypes().Random(item => CremaDataTypeUtility.CanUseAutoIncrement(item));
            this.column.AutoIncrement = true;
            var newDefaultValue = RandomUtility.Next(this.column.DataType);

            this.column.DefaultValue = newDefaultValue;
            Assert.AreEqual(newDefaultValue, this.column.DefaultValue);
        }