Search This Blog

Monday, August 31, 2020

Creating Unit Test Fact method code snippet in Visual Studio

Save the following xml file with the .snippet extension.

Afterwards, load it into the Code Snippet Manager in Visual Studio via 

Tools -> Code Snippet Manager -> Import

That's it. Type tt + Tab and the code block between CDATA[...] is inserted.


 <?xml version="1.0" encoding="utf-8"?>

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

<CodeSnippet Format="1.0.0">

<Header>

<Title>UT Fact</Title>

<Author>AYK</Author>

<Description>Add Unit Test Fact</Description>

<Shortcut>tt</Shortcut>

</Header>

<Snippet>

<Code Language="CSharp">

<![CDATA[

[Fact]

public async Task ObjectBeingTested_Action_ExpectedResult()

{

                                        //arrange

                                        //act

                                        //assert

}]]>

</Code>

</Snippet>

</CodeSnippet>

</CodeSnippets>

Monday, August 24, 2020

Auto generate class diagram in visual studio 2019

 From StackOverflow:

In Visual Studio 2019, dragging the whole project to an empty class diagram (add new item -> class diagram) will do the job.

Make sure you have the Visual Studio Class Designer component installed.


Why create a .NET Core Worker Service?

From Randy Patterson:

.NET Core 3 introduced a new project template called Worker Service. This template is designed to give you a starting point for cross-platform services. As an alternate use case, it sets up a very nice environment for general console applications that is perfect for containers and microservices.

From Steve J Gordon:

The simple answer is – when and if you need them! If you have a requirement to develop a microservice which has no user interface and which performs long-running work, then a worker service is very likely going to be a good fit.

Remember that a worker service is just a console application under the hood. That console application uses a host to turn the application into something which runs until it is signalled to stop. The host brings with it features like dependency injection that you’ll likely already familiar with. Using the same logging and configuration extensions available in ASP.NET Core makes it easy to develop worker services which should log information and which require some configuration. These requirements are nearly always present when building worker services that will run in the cloud. For example, you will likely need to provide configuration for any external services that your worker service will interact with. A queue URL for example.

Worker services can be used to extract responsibilities from existing ASP.NET Core applications (I cover this in my Pluralsight course) and to design new .NET Core based microservices.

Sunday, August 23, 2020

You are debugging a release build error

From StackOverflow

I went with Sam's suggestion, but after reading the docs here decided to try again. I spotted a build warning stating that some modules were optimized but I had Enable Just My Code set. I then reverted Supress JIT Optimization on module load to its original value (selected) but de-selected Enable Just My Code. I am able to debug now