JetBrains Rider Live Templates

Someone today during my talk on TDD for Blazor on a JetBrains Webinar asked me for what live templates I was using.

 

What are Live Templates?

Live templates are ways of quickly adding code. Usually you have 1-5 characters you type and then you hit “tab” and it will generate you lots more code. Sometimes these are called “snippets.”

If you want to see me using one from the webinar today check this out at around the 44:08 mark.

 

What Live Templates do I have?

I have four Live Templates related to testing:

  • xf which generates an xUnit Fact without async
  • xfa which generates an async xUnit Fact
  • xt which generates an xUnit Theory without async
  • xta which generates async xUnit Theory

To add these to JetBrains Rider, you can open up your settings, go under Live Templates, then C#, and then you can add a new live template. Here are the settings.

 

xf for adding an xUnit Fact without async

Note: the words between $$ means your cursor will end up there and you can tab your way through those.

 

xfa for adding an async xUnit Fact

 

xt for adding an xUnit Theory without async

 

xta for adding an async xUnit Theory

Renaming Git Default Branch to Main Fails

I recently created a new project and noticed that my git init created the default branch as master. I wanted to rename this to main.

So I typed the simple git branch -m master main but then I got this error:

error: refname refs/heads/master not found
fatal: Branch rename failed

I was confused, but then it hit me… I hadn’t actually committed anything yet so my branch didn’t actually exist! As soon as I committed something, my branch rename worked fine.

Hope this helps someone else.