“Inconclusive” error in ReSharper unit test runner caused by “async void”

The ReSharper unit test runner doesn’t like test methods which are declared as “async void”.

Unfortunately you won’t get any compiler or intellisense warning to tell you. When trying to run the test in ResSharper unit test runner it will first get a blue question-mark icon and when you run it individually it will get the test result Inconclusive.

Example of an “conclusive” test result and a good one.

Code:

[TestMethod]
public async void This_Test_Will_Cause_Inconclusive_Message()
{
    // tests
}

[TestMethod]
public async Task This_Test_Will_Run_Ok()
{
 // tests
}

 

How to reset a SQL Server LocalDB instance in Visual Studio

Many Visual Studio project-templates configure a SQL Server LocalDB instance for development on your local machine. For example the ASP.NET with Identity template.

But what to do if that database gets corrupted or you need a clean one for testing your Entity Framework Migrations, for example?

One solution is this:

  1. Open up the Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console). Make sure to select the project containing your database in the DefaultProject dropdown.
  2. Enter the command sqllocaldb infoat the prompt. The result is the name of your SQL Server LocalDB instance.
  3. Enter the command sqllocaldb stop InstanceName. Replace “InstanceName” with the name you got from the previous command.
  4. Enter the command sqllocaldb delete InstanceName. Replace “InstanceName” as in the command before.

    Commands to stop and delete the LocalDB database.
  5. Open the folder where the database files (*.mdf) are stored.

    Open App-data folder in Windows Explorer
  6. Delete the two *.mdf files in the folder.

Depending on your configuration your database will be re-created automatically when you execute your application or running Update-Databasein the Package Manager Console.

 

Show PDF in browser instead of downloading (ASP.NET MVC) without JavaScript

If I want to display a PDF file in the browser instead of downloading a copy, I can tell the browser via an additional Content-Disposition response header.

This code example assumes that the file content is available as byte-array, reading the content from a database, for example.

// Get action method that tries to show a PDF file in the browser (inline)
public ActionResult ShowPdfInBrowser()
{
  byte[] pdfContent = CodeThatRetrievesMyFilesContent();

  if (pdfContent == null)
  {
    return null;
  }

  var contentDispositionHeader = new System.Net.Mime.ContentDisposition
  {
    Inline = true,
    FileName = "someFilename.pdf"
  };

  Response.Headers.Add("Content-Disposition", contentDispositionHeader.ToString());
  return File(pdfContent, System.Net.Mime.MediaTypeNames.Application.Pdf);
}

Please keep in mind that ultimately we don’t have control over the browser. We can politely request to show the PDF inline, but this can be overridden by a user configuration, for example.