Contents tagged with C#

  • Testing Async Methods with Xunit

    Tags: C#, Unit Testing, Xunit

    Previously, when testing asynchronous methods such as the one below, I used synchronous tests and forced the method invocation to be synchronous by using .Result.

    public class AsyncTestClass … more

  • Null Reference Exceptions Should Not be Happening

    Tags: C#

    Null Reference Exceptions Should Not be Happening!  Errors like this - Object reference not set to an instance of an object - should never show up in your error logs.  These uninformative … more

  • Don't Kill Your Colleagues By Overusing Var

    Tags: C#

    With C# 3.0 came the keyword var.  It was a great forward leap for the language.  Unfortunately it’s become the lazy coder’s way of declaring a variable. It’s type … more

  • Setting a Default for FirstOrDefault

    Tags: Linq, C#

    The linq expression FirstOrDefault is nifty if you are trying to get the First value in a sequence and you don't want a pesky InvalidOperationException if there are no elements returned.   … more

  • Combining Tasks Using WhenAll

    Tags: TPL, ASP.NET, C#

    If you want to combine one or more Tasks into one Task and wait for all of them to complete you can use a ASP.NET 4.5 feature called WhenAll.  WhenAll takes a collection of tasks and returns one … more