Skip to content

Visual Studio

Setting up an Arrange, Act, Assert comment template in Visual Studio 2022

To add a simple code snippet that allows a set of arrange, act and assert comments to be inserted using the short code of aaa, firstly, create a simple XML file with the following contents and save it as ArrangeActAssert.snippet:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Arrange Act Assert</Title>
            <Author>Neil Docherty</Author>
            <Description>Adds an arrange, act, assert to a test</Description>
            <HelpUrl />
            <Keywords />
            <SnippetTypes />
            <Shortcut>aaa</Shortcut>
        </Header>
        <Snippet>
            <Declarations />
            <References />
            <Code Kind="any" Language="CSharp"><![CDATA[// Arrange
$end$

// Act


// Assert]]></Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Then, to import it into Visual Studio, perform the following steps:

  1. Go to the Tools menu
  2. Select Code Snippets Manager
  3. Choose the Import button and locate and select your ArrangeActAssert.snippet file and click Open.

Now, when editing some C# code, typing aaa and hitting tab twice will create a block of text similar to:

// Arrange


// Act


// Assert

Bitbucket, SSH auth, Visual Studio and VS Code

To get SSH key authentication working with Bitbucket from with both Visual Studio 2019 (or earlier potentially) and VS Code can be challenging. Some commands I've used are below.

VS Code

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

Visual Studio

Visual Studio 2022 doesn't require additional changes but if running 2019 (i.e. 32-bit) or earlier, I had to run the following to get it to work but this then caused VS Code to stop authing properly.

git config --global core.sshCommand "\"C:\Program Files\Git\usr\bin\ssh.exe\""

This requires Git being installed from https://git-scm.com/.

Build container from Visual Studio built Dockerfile

If you need to build a project using the Visual Studio generated Dockerfile, you need to run docker build from the solution folder and specify the file.

Assuming the project you are working is called Your.Project.Api and this is the name of the project folder, run the following command from the root folder where the solution file and project folder(s) are located.

docker build -f Your.Project.Api/Dockerfile .

For Windows, you can use a forward or back slash but Linux must be a forward slash.