so finally we are working on the delete function, when a user clicks on on delete check box’s in the grid, and then clicks update button, the selected items should be deleted. writing a test for this is difficult, as we need to fill the grid with the correct items, this means setting it up correctly in code.
After much playing around, it dawned on me that I have the settings on the main form, and all I had to do was create the form within the code, then I can access the filled grid and test the delete, at least that’s the theory.
so the test ended up looking like this
[Test] public void DeleteTransactions() { frmMain mainForm = new frmMain(); DataGridView transGrid = mainForm.TransactionGrid; MoneyEngine.MoneyTransaction transaction =
(MoneyEngine.MoneyTransaction)transGrid.Rows[0].DataBoundItem; transaction.ToDelete = true; // get the original count in rows, delete the first row, rebind the grid to update, int originalCount = transGrid.Rows.Count; _Controller.DeleteTransactions(transGrid); _Controller.BindDataGrid(transGrid); // and check the resulting row count. Assert.AreEqual(originalCount - 1, transGrid.Rows.Count); }
and the delete transaction method looks like
public void DeleteTransactions(DataGridView gridView) { bool hasDeletions = false; foreach (DataGridViewRow datarow in gridView.Rows) { MoneyEngine.MoneyTransaction trans = (MoneyEngine.MoneyTransaction)datarow.DataBoundItem; if (trans.ToDelete) if (trans.Update()) hasDeletions = true; } if (hasDeletions) { _Engine.History.Clear(); _Engine.LoadTransarctions(); } }
I added a call to the delete transactions method in the update click method of the form, and attempted to add and delete rows from the grid as a user test, it all seams to work correctly and as I expected, all there is now is to create a rollout version using one click deployment, once I get a web site up and running a version of this will be available for those who want it. next I am off to think about the shopping version of this which will be my next project.
Before then I will have a look at the completed code and do a bit of refactoring. and tidying up ready, so when I do the shopping program I can integrate the data, also I am thinking of the mobile version and a wpf version of this.