public Maybe<Table> Display(string defaultTableName, Func<Table, Maybe<Exception>> createTable, Func<Table, Tuple<Maybe<Exception>, string>> previewOperation) { var tableDefinition = new Table(); switch (_operation) { case Operation.CreateTable: return createTable(tableDefinition).HasValue ? Maybe.Just(tableDefinition) : Maybe.Nothing<Table>(); case Operation.PreviewOperation: return previewOperation(tableDefinition).ToMaybe().Bind(x => x.Item1).HasValue ? Maybe.Just(tableDefinition) : Maybe.Nothing<Table>(); } return null; }
public void Properly_Convert_To_Dictionary() { var tableDefinition = new Table { Server = "localhost", Database = "somedatabase", Name = "sometable", Columns = new List<Column> { new Column { Name = "Name", SqlType = SqlTypes.NVarChar, DefaultValue = "''", Length = 500}, new Column { Name = "Age", SqlType = SqlTypes.Int, DefaultValue = "5", Length = 4} } }; var parameters = tableDefinition.ToDictionary(); parameters.Count.ShouldEqual(12); parameters["server"].ShouldEqual(tableDefinition.Server); parameters["database"].ShouldEqual(tableDefinition.Database); parameters["table"].ShouldEqual(tableDefinition.Name); parameters["columnNames"].Cast<string[]>().ElementAt(0).ShouldEqual("Name"); parameters["columnSqlTypes"].Cast<string[]>().ElementAt(0).ShouldEqual("nvarchar"); parameters["columnClrTypes"].Cast<Type[]>().ElementAt(0).ShouldEqual(typeof(String)); parameters["columnDefaults"].Cast<string[]>().ElementAt(0).ShouldEqual("''"); parameters["columnLengths"].Cast<int[]>().ElementAt(0).ShouldEqual(500); parameters["columnIsNullable"].Cast<bool[]>().ElementAt(0).ShouldEqual(false); parameters["columnIsIdentity"].Cast<bool[]>().ElementAt(0).ShouldEqual(false); parameters["columnIsAutoGenerated"].Cast<bool[]>().ElementAt(0).ShouldEqual(false); parameters["columnIsPrimaryKey"].Cast<bool[]>().ElementAt(0).ShouldEqual(false); parameters["columnNames"].Cast<string[]>().ElementAt(1).ShouldEqual("Age"); parameters["columnSqlTypes"].Cast<string[]>().ElementAt(1).ShouldEqual("int"); parameters["columnClrTypes"].Cast<Type[]>().ElementAt(1).ShouldEqual(typeof(int)); parameters["columnDefaults"].Cast<string[]>().ElementAt(1).ShouldEqual("5"); parameters["columnLengths"].Cast<int[]>().ElementAt(1).ShouldEqual(4); parameters["columnIsNullable"].Cast<bool[]>().ElementAt(1).ShouldEqual(false); parameters["columnIsIdentity"].Cast<bool[]>().ElementAt(1).ShouldEqual(false); parameters["columnIsAutoGenerated"].Cast<bool[]>().ElementAt(1).ShouldEqual(false); parameters["columnIsPrimaryKey"].Cast<bool[]>().ElementAt(1).ShouldEqual(false); }