December 9, 2015

A Short and Easy Introduction to .NET's Task Class

Task.Run You can use Task.Run to schedule a delegate to run on the thread pool. The method returns a new task, and if the work is complete, the result will be available via Task.Result. If not, Task.Result will block until it is complete. 1 2 3 4 5 6 7 8 9 10 11 12 private void button_Click(object sender, EventArgs e) { Task<DateTime> task = Task.Run(() => GetDateTime()); lblDateTime.Text = task. Read more

October 26, 2015

SpecFlow Tags Done Right

In a previous post, I covered scoped bindings in SpecFlow and ended with an example of how not to use tags. In this post, I’ll cover the “right way” and demonstrate how to avoid coupling features to step definitions. But first, a quick primer on tags. What Are Tags? Tags are used in Gherkin to mark features or scenarios. They begin with the @ character in Gherkin, but in step definitions the @ is removed. Read more

October 22, 2015

An Introduction to Scoped Bindings in SpecFlow

One nice aspect of SpecFlow is the ability to scope bindings by feature title, scenario title, or tag. Normally bindings are global to the project, but a binding’s scope can be restricted using the Scope attribute. I like to think of it as similar to the private and public class modifiers in C#. Consider the Gherkin below. It is a single feature with one scenario and two tags. One tag is at the feature level and the other at the scenario level. Read more

September 22, 2015

Refactoring to Composable SpecFlow Steps

I’ve seen some pretty bad SpecFlow code. Code that seems to violate every good practice out there. Poor reuse. Copy and paste everywhere. Test code is the hotel room of the software world. People are sloppier and more careless than they otherwise would be. I’m not sure why that is. Perhaps because tests are not seen as “real code”. But as a testing code base grows from dozens to hundreds to even a thousand or more test cases, having well-factored composable SpecFlow steps becomes critical. Read more

August 18, 2015

Tidying Up Code with C#'s Using Alias Directives

The C# language’s using alias directives or namespace and type aliases provide a way to disambiguate between namespaces or types with the same name. For example, both the System.Net and Nancy libraries have a type named HttpStatusCode. If you happen to import both namespaces in a file, then the types need to be fully qualified or else the compiler will fail with the error: ‘HttpStatusCode’ is an ambiguous reference between ‘Nancy. Read more

August 14, 2015

This Week in Programming Gotchas

We all have those days where we spend hours trying to solve a seemingly simple problem only to smack ourselves in the head when we finally figure it out. Missing quotes, forgetting to flush a StreamWriter, etc. If only we could get back all the wasted time. Well, this week I wrestled with more gotchas than usual. Below are the ones that burned most of my time. Streams Don’t forget to flush a StreamWriter when you’re done. Read more

© Joe Buschmann 2020