public void TestCommit2() { MakeTable(false); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager)bc[view]; ColumnPoker column = nameColumnStyle; DataGridTextBox tb = (DataGridTextBox)column.TextBox; Assert.AreEqual("", tb.Text, "1"); Assert.IsTrue(tb.IsInEditOrNavigateMode, "1.5"); column.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "hi there", true); Assert.AreEqual("hi there", tb.Text, "2"); Assert.AreEqual(new Rectangle(new Point(2, 2), new Size(97, 97)), tb.Bounds, "3"); Assert.IsFalse(tb.ReadOnly, "4"); Assert.IsFalse(tb.IsInEditOrNavigateMode, "5"); tb.Text = "yo"; column.DoEndEdit(); Assert.IsTrue(tb.IsInEditOrNavigateMode, "5.5"); bool rv = column.DoCommit(cm, cm.Position); Assert.IsTrue(rv, "6"); DataRowView v = (DataRowView)cm.Current; Assert.AreEqual("Miguel", v[0], "7"); /* try it again with the DoCommit before the DoEndEdit */ cm.Position = 0; column.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "hi there", true); Assert.AreEqual("hi there", tb.Text, "8"); Assert.AreEqual(new Rectangle(new Point(2, 2), new Size(97, 97)), tb.Bounds, "9"); Assert.IsFalse(tb.ReadOnly, "10"); Assert.IsFalse(tb.IsInEditOrNavigateMode, "11"); tb.Text = "yo"; rv = column.DoCommit(cm, cm.Position); column.DoEndEdit(); Assert.IsTrue(rv, "12"); v = (DataRowView)cm.Current; Assert.AreEqual("yo", v[0], "13"); }
public void NonStringConverterTest() { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); table = new DataTable(); view = table.DefaultView; table.Columns.Add(new DataColumn("Amount", typeof(MockNumericNonStringConvertable))); DataRow row = table.NewRow(); row ["Amount"] = new MockNumericNonStringConvertable(1); table.Rows.Add(row); row = table.NewRow(); row ["Amount"] = new MockNumericNonStringConvertable(2); table.Rows.Add(row); tableStyle = new DataGridTableStyle(); ColumnPoker amountColumnStyle = new ColumnPoker(); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add(amountColumnStyle); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager)bc [view]; TextBox tb = amountColumnStyle.TextBox; Assert.IsNotNull(tb, "#A1"); Assert.AreEqual(string.Empty, tb.Text, "#A2"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("uno", tb.Text, "#B1"); Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#B2"); amountColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("dos", tb.Text, "#C1"); Assert.AreEqual(new MockNumericStringConvertable(2), table.Rows [1] ["Amount"], "#C2"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "£3.00", true); Assert.AreEqual("£3.00", tb.Text, "#D1"); Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#D2"); Assert.IsTrue(amountColumnStyle.DoCommit(cm, cm.Position), "#E1"); Assert.AreEqual("£3.00", tb.Text, "#E2"); Assert.AreEqual("£3.00", table.Rows [0] ["Amount"], "#E3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void TestReadOnly_DataGrid() { MakeTable(false); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; dg.ReadOnly = true; CurrencyManager cm = (CurrencyManager)bc[view]; ColumnPoker column = nameColumnStyle; TextBox tb = nameColumnStyle.TextBox; Assert.IsNotNull(tb, "1"); Assert.AreEqual(typeof(DataGridTextBox), tb.GetType(), "2"); Assert.IsTrue(tb.Enabled, "3"); Assert.IsFalse(tb.Visible, "4"); Assert.AreEqual("", tb.Text, "5"); Assert.IsFalse(tb.ReadOnly, "6"); column.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "hi there", true); Assert.IsFalse(tb.ReadOnly, "7"); Assert.AreEqual("hi there", tb.Text, "8"); bool rv; rv = column.DoCommit(cm, cm.Position); column.DoEndEdit(); Assert.IsTrue(rv, "9"); DataRowView v = (DataRowView)cm.Current; Assert.AreEqual("hi there", v[0], "10"); }
public void NonStringConverterTest () { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB"); table = new DataTable (); view = table.DefaultView; table.Columns.Add (new DataColumn ("Amount", typeof (MockNumericNonStringConvertable))); DataRow row = table.NewRow (); row ["Amount"] = new MockNumericNonStringConvertable (1); table.Rows.Add (row); row = table.NewRow (); row ["Amount"] = new MockNumericNonStringConvertable (2); table.Rows.Add (row); tableStyle = new DataGridTableStyle (); ColumnPoker amountColumnStyle = new ColumnPoker (); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add (amountColumnStyle); BindingContext bc = new BindingContext (); DataGrid dg = new DataGrid (); dg.BindingContext = bc; dg.TableStyles.Add (tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager) bc [view]; TextBox tb = amountColumnStyle.TextBox; Assert.IsNotNull (tb, "#A1"); Assert.AreEqual (string.Empty, tb.Text, "#A2"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0, 0), new Size (100, 100)), false, null, true); Assert.AreEqual ("uno", tb.Text, "#B1"); Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#B2"); amountColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0, 0), new Size (100, 100)), false, null, true); Assert.AreEqual ("dos", tb.Text, "#C1"); Assert.AreEqual (new MockNumericStringConvertable (2), table.Rows [1] ["Amount"], "#C2"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0, 0), new Size (100, 100)), false, "£3.00", true); Assert.AreEqual ("£3.00", tb.Text, "#D1"); Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#D2"); Assert.IsFalse (amountColumnStyle.DoCommit (cm, cm.Position), "#E1"); Assert.AreEqual ("£3.00", tb.Text, "#E2"); //Assert.AreEqual ("£3.00", table.Rows [0] ["Amount"], "#E3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void StringConverterTest () { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB"); table = new DataTable (); view = table.DefaultView; table.Columns.Add (new DataColumn ("Amount", typeof (MockNumericStringConvertable))); DataRow row = table.NewRow (); row ["Amount"] = new MockNumericStringConvertable (1); table.Rows.Add (row); row = table.NewRow (); row ["Amount"] = new MockNumericStringConvertable (2); table.Rows.Add (row); tableStyle = new DataGridTableStyle (); ColumnPoker amountColumnStyle = new ColumnPoker (); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add (amountColumnStyle); BindingContext bc = new BindingContext (); DataGrid dg = new DataGrid (); dg.BindingContext = bc; dg.TableStyles.Add (tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager) bc [view]; DataGridTextBox tb = (DataGridTextBox) amountColumnStyle.TextBox; Assert.IsNotNull (tb, "#A1"); Assert.AreEqual (string.Empty, tb.Text, "#A2"); Assert.IsTrue (tb.IsInEditOrNavigateMode, "#A3"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("£1.00", tb.Text, "#B1"); Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#B2"); Assert.IsTrue (tb.IsInEditOrNavigateMode, "#B3"); amountColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("£2.00", tb.Text, "#C1"); Assert.AreEqual (new MockNumericStringConvertable (2), table.Rows [1] ["Amount"], "#C2"); Assert.IsTrue (tb.IsInEditOrNavigateMode, "#C3"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "£3.00", true); Assert.AreEqual ("£3.00", tb.Text, "#D1"); Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#D2"); Assert.IsFalse (tb.IsInEditOrNavigateMode, "#D3"); Assert.IsTrue (amountColumnStyle.DoCommit (cm, cm.Position), "#E1"); Assert.AreEqual ("£3.00", tb.Text, "#E2"); Assert.AreEqual (new MockNumericStringConvertable (3), table.Rows [0] ["Amount"], "#E3"); Assert.IsTrue (tb.IsInEditOrNavigateMode, "#E4"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "INVALID", true); Assert.IsFalse (amountColumnStyle.DoCommit (cm, cm.Position), "#F1"); Assert.AreEqual ("INVALID", tb.Text, "#F2"); Assert.AreEqual (new MockNumericStringConvertable (3), table.Rows [0] ["Amount"], "#F3"); Assert.IsFalse (tb.IsInEditOrNavigateMode, "#F4"); amountColumnStyle.Format = "whatever"; amountColumnStyle.FormatInfo = new CultureInfo ("en-US"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("£3.00", tb.Text, "#G1"); Assert.AreEqual (new MockNumericStringConvertable (3), table.Rows [0] ["Amount"], "#G2"); Assert.IsFalse (tb.IsInEditOrNavigateMode, "#G3"); tb.Text = "5"; Assert.IsTrue (amountColumnStyle.DoCommit (cm, cm.Position), "#H1"); Assert.AreEqual ("£5.00", tb.Text, "#H2"); Assert.AreEqual (new MockNumericStringConvertable (5), table.Rows [0] ["Amount"], "#H3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void IFormattable_DateTime () { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE"); DateTime today = DateTime.Today; DateTime now = DateTime.Now; table = new DataTable (); view = table.DefaultView; table.Columns.Add (new DataColumn ("Date", typeof (DateTime))); DataRow row = table.NewRow (); row ["Date"] = today; table.Rows.Add (row); row = table.NewRow (); row ["Date"] = now; table.Rows.Add (row); tableStyle = new DataGridTableStyle (); ColumnPoker dateColumnStyle = new ColumnPoker (); dateColumnStyle.MappingName = "Date"; tableStyle.GridColumnStyles.Add (dateColumnStyle); BindingContext bc = new BindingContext (); DataGrid dg = new DataGrid (); dg.BindingContext = bc; dg.TableStyles.Add (tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager) bc [view]; TextBox tb = dateColumnStyle.TextBox; DateTimeConverter converter = new DateTimeConverter (); Assert.IsNotNull (tb, "#A1"); Assert.AreEqual (string.Empty, tb.Text, "#A2"); dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual (converter.ConvertTo (null, CultureInfo.CurrentCulture, today, typeof (string)), tb.Text, "#B1"); Assert.AreEqual (today, table.Rows [0] ["Date"], "#B2"); dateColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual (converter.ConvertTo (null, CultureInfo.CurrentCulture, now, typeof (string)), tb.Text, "#C1"); Assert.AreEqual (now, table.Rows [1] ["Date"], "#C2"); dateColumnStyle.Format = "MM"; dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual (today.ToString ("MM", CultureInfo.CurrentCulture), tb.Text, "#D1"); Assert.AreEqual (today, table.Rows [0] ["Date"], "#D2"); dateColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual (now.ToString ("MM", CultureInfo.CurrentCulture), tb.Text, "#E1"); Assert.AreEqual (now, table.Rows [1] ["Date"], "#E2"); dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "INVALID", true); Assert.IsFalse (dateColumnStyle.DoCommit (cm, 0), "#F1"); Assert.AreEqual ("INVALID", tb.Text, "#F2"); Assert.AreEqual (today, table.Rows [0] ["Date"], "#F3"); dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "12", true); Assert.IsFalse (dateColumnStyle.DoCommit (cm, 0), "#G1"); Assert.AreEqual ("12", tb.Text, "#G2"); Assert.AreEqual (today, table.Rows [0] ["Date"], "#G3"); dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "07/09/2007", true); Assert.IsTrue (dateColumnStyle.DoCommit (cm, 0), "#H1"); Assert.AreEqual (converter.ConvertTo (null, CultureInfo.CurrentCulture, new DateTime (2007, 9, 7), typeof (string)), tb.Text, "#H2"); Assert.AreEqual (new DateTime (2007, 9, 7), table.Rows [0] ["Date"], "#H3"); dateColumnStyle.FormatInfo = CultureInfo.CurrentCulture; dateColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "08/06/2005", true); Assert.IsTrue (dateColumnStyle.DoCommit (cm, 0), "#I1"); Assert.AreEqual ("06", tb.Text, "#I2"); Assert.AreEqual (new DateTime (2005, 6, 8), table.Rows [0] ["Date"], "#I3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void IFormattable () { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB"); table = new DataTable (); view = table.DefaultView; table.Columns.Add (new DataColumn ("Amount", typeof (MockNumeric))); DataRow row = table.NewRow (); row ["Amount"] = new MockNumericFormattable (1); table.Rows.Add (row); row = table.NewRow (); row ["Amount"] = new MockNumericFormattable (2); table.Rows.Add (row); row = table.NewRow (); row ["Amount"] = new MockNumeric (3); table.Rows.Add (row); tableStyle = new DataGridTableStyle (); ColumnPoker amountColumnStyle = new ColumnPoker (); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add (amountColumnStyle); BindingContext bc = new BindingContext (); DataGrid dg = new DataGrid (); dg.BindingContext = bc; dg.TableStyles.Add (tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager) bc [view]; TextBox tb = amountColumnStyle.TextBox; Assert.IsNotNull (tb, "#A1"); Assert.AreEqual (string.Empty, tb.Text, "#A2"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("uno", tb.Text, "#B1"); Assert.AreEqual (new MockNumericFormattable (1), table.Rows [0] ["Amount"], "#B2"); amountColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("dos", tb.Text, "#C1"); Assert.AreEqual (new MockNumericFormattable (2), table.Rows [1] ["Amount"], "#C2"); amountColumnStyle.DoEdit (cm, 2, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("tres", tb.Text, "#D1"); Assert.AreEqual (new MockNumeric (3), table.Rows [2] ["Amount"], "#D2"); amountColumnStyle.Format = string.Empty; amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("uno", tb.Text, "#E1"); Assert.AreEqual (new MockNumericFormattable (1), table.Rows [0] ["Amount"], "#E2"); amountColumnStyle.Format = "currency"; amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("#£1.00", tb.Text, "#F1"); Assert.AreEqual (new MockNumericFormattable (1), table.Rows [0] ["Amount"], "#F2"); amountColumnStyle.DoEdit (cm, 2, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("tres", tb.Text, "#G1"); Assert.AreEqual (new MockNumeric (3), table.Rows [2] ["Amount"], "#G2"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "#£5.00", true); Assert.AreEqual ("#£5.00", tb.Text, "#H1"); Assert.AreEqual (new MockNumericFormattable (1), table.Rows [0] ["Amount"], "#H2"); amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0,0), new Size (100, 100)), false, "INVALID", true); Assert.IsFalse (amountColumnStyle.DoCommit (cm, 0), "#I1"); Assert.AreEqual ("INVALID", tb.Text, "#I2"); //Assert.AreEqual ("INVALID", table.Rows [0] ["Amount"], "#I3"); amountColumnStyle.FormatInfo = new CultureInfo ("en-US"); amountColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0,0), new Size (100, 100)), false, null, true); Assert.AreEqual ("#$2.00", tb.Text, "#J1"); Assert.AreEqual (new MockNumericFormattable (2), table.Rows [1] ["Amount"], "#J2"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void StringConverterTest() { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); table = new DataTable(); view = table.DefaultView; table.Columns.Add(new DataColumn("Amount", typeof(MockNumericStringConvertable))); DataRow row = table.NewRow(); row ["Amount"] = new MockNumericStringConvertable(1); table.Rows.Add(row); row = table.NewRow(); row ["Amount"] = new MockNumericStringConvertable(2); table.Rows.Add(row); tableStyle = new DataGridTableStyle(); ColumnPoker amountColumnStyle = new ColumnPoker(); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add(amountColumnStyle); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager)bc [view]; DataGridTextBox tb = (DataGridTextBox)amountColumnStyle.TextBox; Assert.IsNotNull(tb, "#A1"); Assert.AreEqual(string.Empty, tb.Text, "#A2"); Assert.IsTrue(tb.IsInEditOrNavigateMode, "#A3"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("£1.00", tb.Text, "#B1"); Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#B2"); Assert.IsTrue(tb.IsInEditOrNavigateMode, "#B3"); amountColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("£2.00", tb.Text, "#C1"); Assert.AreEqual(new MockNumericStringConvertable(2), table.Rows [1] ["Amount"], "#C2"); Assert.IsTrue(tb.IsInEditOrNavigateMode, "#C3"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "£3.00", true); Assert.AreEqual("£3.00", tb.Text, "#D1"); Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#D2"); Assert.IsFalse(tb.IsInEditOrNavigateMode, "#D3"); Assert.IsTrue(amountColumnStyle.DoCommit(cm, cm.Position), "#E1"); Assert.AreEqual("£3.00", tb.Text, "#E2"); Assert.AreEqual(new MockNumericStringConvertable(3), table.Rows [0] ["Amount"], "#E3"); Assert.IsTrue(tb.IsInEditOrNavigateMode, "#E4"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "INVALID", true); Assert.IsFalse(amountColumnStyle.DoCommit(cm, cm.Position), "#F1"); Assert.AreEqual("INVALID", tb.Text, "#F2"); Assert.AreEqual(new MockNumericStringConvertable(3), table.Rows [0] ["Amount"], "#F3"); Assert.IsFalse(tb.IsInEditOrNavigateMode, "#F4"); amountColumnStyle.Format = "whatever"; amountColumnStyle.FormatInfo = new CultureInfo("en-US"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("£3.00", tb.Text, "#G1"); Assert.AreEqual(new MockNumericStringConvertable(3), table.Rows [0] ["Amount"], "#G2"); Assert.IsFalse(tb.IsInEditOrNavigateMode, "#G3"); tb.Text = "5"; Assert.IsTrue(amountColumnStyle.DoCommit(cm, cm.Position), "#H1"); Assert.AreEqual("£5.00", tb.Text, "#H2"); Assert.AreEqual(new MockNumericStringConvertable(5), table.Rows [0] ["Amount"], "#H3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void IFormattable_DateTime() { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE"); DateTime today = DateTime.Today; DateTime now = DateTime.Now; table = new DataTable(); view = table.DefaultView; table.Columns.Add(new DataColumn("Date", typeof(DateTime))); DataRow row = table.NewRow(); row ["Date"] = today; table.Rows.Add(row); row = table.NewRow(); row ["Date"] = now; table.Rows.Add(row); tableStyle = new DataGridTableStyle(); ColumnPoker dateColumnStyle = new ColumnPoker(); dateColumnStyle.MappingName = "Date"; tableStyle.GridColumnStyles.Add(dateColumnStyle); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager)bc [view]; TextBox tb = dateColumnStyle.TextBox; DateTimeConverter converter = new DateTimeConverter(); Assert.IsNotNull(tb, "#A1"); Assert.AreEqual(string.Empty, tb.Text, "#A2"); dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual(converter.ConvertTo(null, CultureInfo.CurrentCulture, today, typeof(string)), tb.Text, "#B1"); Assert.AreEqual(today, table.Rows [0] ["Date"], "#B2"); dateColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual(converter.ConvertTo(null, CultureInfo.CurrentCulture, now, typeof(string)), tb.Text, "#C1"); Assert.AreEqual(now, table.Rows [1] ["Date"], "#C2"); dateColumnStyle.Format = "MM"; dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual(today.ToString("MM", CultureInfo.CurrentCulture), tb.Text, "#D1"); Assert.AreEqual(today, table.Rows [0] ["Date"], "#D2"); dateColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual(now.ToString("MM", CultureInfo.CurrentCulture), tb.Text, "#E1"); Assert.AreEqual(now, table.Rows [1] ["Date"], "#E2"); dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "INVALID", true); Assert.IsFalse(dateColumnStyle.DoCommit(cm, 0), "#F1"); Assert.AreEqual("INVALID", tb.Text, "#F2"); Assert.AreEqual(today, table.Rows [0] ["Date"], "#F3"); dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "12", true); Assert.IsFalse(dateColumnStyle.DoCommit(cm, 0), "#G1"); Assert.AreEqual("12", tb.Text, "#G2"); Assert.AreEqual(today, table.Rows [0] ["Date"], "#G3"); dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "07/09/2007", true); Assert.IsTrue(dateColumnStyle.DoCommit(cm, 0), "#H1"); Assert.AreEqual(converter.ConvertTo(null, CultureInfo.CurrentCulture, new DateTime(2007, 9, 7), typeof(string)), tb.Text, "#H2"); Assert.AreEqual(new DateTime(2007, 9, 7), table.Rows [0] ["Date"], "#H3"); dateColumnStyle.FormatInfo = CultureInfo.CurrentCulture; dateColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "08/06/2005", true); Assert.IsTrue(dateColumnStyle.DoCommit(cm, 0), "#I1"); Assert.AreEqual("06", tb.Text, "#I2"); Assert.AreEqual(new DateTime(2005, 6, 8), table.Rows [0] ["Date"], "#I3"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void IFormattable() { CultureInfo originalCulture = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); table = new DataTable(); view = table.DefaultView; table.Columns.Add(new DataColumn("Amount", typeof(MockNumericFormattable))); DataRow row = table.NewRow(); row ["Amount"] = new MockNumericFormattable(1); table.Rows.Add(row); row = table.NewRow(); row ["Amount"] = new MockNumericFormattable(2); table.Rows.Add(row); row = table.NewRow(); row ["Amount"] = new MockNumeric(3); table.Rows.Add(row); tableStyle = new DataGridTableStyle(); ColumnPoker amountColumnStyle = new ColumnPoker(); amountColumnStyle.MappingName = "Amount"; tableStyle.GridColumnStyles.Add(amountColumnStyle); BindingContext bc = new BindingContext(); DataGrid dg = new DataGrid(); dg.BindingContext = bc; dg.TableStyles.Add(tableStyle); dg.DataSource = table; CurrencyManager cm = (CurrencyManager)bc [view]; TextBox tb = amountColumnStyle.TextBox; Assert.IsNotNull(tb, "#A1"); Assert.AreEqual(string.Empty, tb.Text, "#A2"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("uno", tb.Text, "#B1"); Assert.AreEqual(new MockNumericFormattable(1), table.Rows [0] ["Amount"], "#B2"); amountColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("dos", tb.Text, "#C1"); Assert.AreEqual(new MockNumericFormattable(2), table.Rows [1] ["Amount"], "#C2"); amountColumnStyle.DoEdit(cm, 2, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("tres", tb.Text, "#D1"); Assert.AreEqual(new MockNumeric(3), table.Rows [2] ["Amount"], "#D2"); amountColumnStyle.Format = string.Empty; amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("uno", tb.Text, "#E1"); Assert.AreEqual(new MockNumericFormattable(1), table.Rows [0] ["Amount"], "#E2"); amountColumnStyle.Format = "currency"; amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("#£1.00", tb.Text, "#F1"); Assert.AreEqual(new MockNumericFormattable(1), table.Rows [0] ["Amount"], "#F2"); amountColumnStyle.DoEdit(cm, 2, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("tres", tb.Text, "#G1"); Assert.AreEqual(new MockNumeric(3), table.Rows [2] ["Amount"], "#G2"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "#£5.00", true); Assert.AreEqual("#£5.00", tb.Text, "#H1"); Assert.AreEqual(new MockNumericFormattable(1), table.Rows [0] ["Amount"], "#H2"); amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "INVALID", true); Assert.IsTrue(amountColumnStyle.DoCommit(cm, 0), "#I1"); Assert.AreEqual("INVALID", tb.Text, "#I2"); Assert.AreEqual("INVALID", table.Rows [0] ["Amount"], "#I3"); amountColumnStyle.FormatInfo = new CultureInfo("en-US"); amountColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true); Assert.AreEqual("#$2.00", tb.Text, "#J1"); Assert.AreEqual(new MockNumericFormattable(2), table.Rows [1] ["Amount"], "#J2"); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }