public async Task SetIsReadOnlyAsync(ITableColumn column, TaskContext context) { var authentication = context.Authentication; if (column.IsKey == false || RandomUtility.Within(55) == true) { var isReadOnly = RandomUtility.NextBoolean(); await column.SetIsReadOnlyAsync(authentication, isReadOnly); } }
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); } }
private static async Task SetFieldsAsync(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column) { if (column.Name != item.Name) { await column.SetNameAsync(authentication, item.Name); } if (column.DataType != item.DataType) { await column.SetDataTypeAsync(authentication, item.DataType); } if (column.Comment != item.Comment) { await column.SetCommentAsync(authentication, item.Comment); } if (column.Tags != (TagInfo)item.Tags) { await column.SetTagsAsync(authentication, (TagInfo)item.Tags); } if (column.IsReadOnly != item.IsReadOnly) { await column.SetIsReadOnlyAsync(authentication, item.IsReadOnly); } if (column.IsUnique != item.IsUnique) { await column.SetIsUniqueAsync(authentication, item.IsUnique); } if (column.AutoIncrement != item.AutoIncrement) { await column.SetAutoIncrementAsync(authentication, item.AutoIncrement); } if (column.DefaultValue != item.DefaultValue) { await column.SetDefaultValueAsync(authentication, item.DefaultValue); } if (column.AllowNull != !item.DisallowNull) { await column.SetAllowNullAsync(authentication, !item.DisallowNull); } }
private static async Task <JsonColumnInfos.ItemInfo> InitializeFieldsAsync(Authentication authentication, JsonColumnInfos.ItemInfo item, ITableColumn column) { await column.SetNameAsync(authentication, item.Name); await column.SetDataTypeAsync(authentication, item.DataType); await column.SetCommentAsync(authentication, item.Comment); await column.SetTagsAsync(authentication, (TagInfo)item.Tags); await column.SetIsReadOnlyAsync(authentication, item.IsReadOnly); await column.SetIsUniqueAsync(authentication, item.IsUnique); await column.SetAutoIncrementAsync(authentication, item.AutoIncrement); await column.SetDefaultValueAsync(authentication, item.DefaultValue); await column.SetAllowNullAsync(authentication, !item.DisallowNull); return(item); }