Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
joebuschmann / winforms_display_model_bad.cs
Created December 18, 2014 20:35
The wrong way to display a WinForms modal dialog
private void btnShowUserDialog_Click(object sender, EventArgs e)
{
var form = new SelectUserForm(); // Wrap in using block
form.SelectedUsers = SelectedUsers;
// Don't use a custom event.
// Instead get the selected users after the ShowDialog() method returns.
form.OkClick += SelectUserForm_OnOkClick;
@joebuschmann
joebuschmann / winforms_modal_form_good.cs
Last active August 29, 2015 14:11
The correct way to validate and close a modal form
private void btnOK_Click(object sender, EventArgs e)
{
if (Validate())
{
_selectedUsers.Clear();
foreach (var user in _allUsers.Where(u => u.Selected))
_selectedUsers.Add(user.UserId, user.UserName);
}
else
@joebuschmann
joebuschmann / winforms_modal_form_bad.cs
Created December 18, 2014 20:49
The wrong way to validate and close a modal form
public event EventHandler OkClick; // Eliminate custom event
public bool Success { get; set; } // Eliminate custom flag
private void btnOK_Click(object sender, EventArgs e)
{
if (Validate())
{
_selectedUsers.Clear();
@joebuschmann
joebuschmann / when_working_with_tables_code_this.cs
Last active August 29, 2015 14:12
When working with tables - code this
[Given(@"the following address")]
public void GivenTheFollowingAddress(Table table)
{
Address address = table.CreateInstance<Address>();
}
[Then(@"the following address should be returned by the service")]
public void ThenTheFollowingAddressShouldBeReturnedByTheService(Table table)
{
table.CompareToInstance(_address);
@joebuschmann
joebuschmann / when_working_with_tables_not_that.cs
Created December 29, 2014 18:44
When working with tables - not that
[Given(@"the following address")]
public void GivenTheFollowingAddress(Table table)
{
Address address = new Address();
address.Line1 = table.Rows[0]["Line 1"];
address.Line2 = table.Rows[0]["Line 2"];
address.City = table.Rows[0]["City"];
address.State = table.Rows[0]["State"];
address.Zipcode = table.Rows[0]["Zipcode"];
@joebuschmann
joebuschmann / when_building_complex_test_data_code_this.feature
Created December 29, 2014 18:47
When building complex test data - code this
Scenario: Build a customer
Given the customer
| First Name | Last Name | Salutation |
| Emilia | Buschmann | Miss |
And the address
| Line 1 | Line 2 | City | State | Zipcode |
| 905 West Dakin Street | Apt. 1 | Chicago | IL | 60613 |
@joebuschmann
joebuschmann / when_building_complex_test_data_code_this.cs
Created December 29, 2014 18:50
When building complex test data - code this
[Given(@"the customer")]
public void GivenTheCustomerFixed(Table table)
{
_customer = table.CreateInstance<Customer>();
}
[Given(@"the address")]
public void GivenTheAddress(Table table)
{
_customer.Address = table.CreateInstance<Address>();
@joebuschmann
joebuschmann / when_building_complex_test_data_not_that.feature
Created December 29, 2014 18:51
When building complex test data - not that
Scenario: Build a customer
Given the customer
| First Name | Last Name | Salutation | Address |
| Emilia | Buschmann | Miss | 905 West Dakin Street; Apt. 1; Chicago; IL; 60413 |
@joebuschmann
joebuschmann / when_building_complex_test_data_not_that.cs
Created December 29, 2014 18:52
When building complex test data - not that
[Given(@"the customer")]
public void GivenTheCustomer(Table table)
{
Customer customer = table.CreateInstance<Customer>();
string[] addressParts = table.Rows[0]["Address"].Split(';');
Address address = new Address();
address.Line1 = addressParts[0];
address.Line2 = addressParts[1];
@joebuschmann
joebuschmann / when_sharing_state_between_bindings_code_this.cs
Created December 29, 2014 18:56
When sharing state between bindings - code this
private Customer _customer;
private Response _response;
[Given(@"the new customer")]
public void GivenTheNewCustomer(Table table)
{
_customer = table.CreateInstance<Customer>();
}
[Given(@"the customer's address")]