Introduction A lot of developers do not like to write unit tests. Generative AI tools like GitHub Copilot can help you write unit tests. At least that is what these tools promise. In this blog post, I will write some unit tests using Github Copilot (with Chat) for a simple example to check if the promise is kept and what kind of changes to the generated code I have to make as a developer to get decent unit tests. Example For this blog post, I will use a probably familiar example of order and orderline items. First tests This code does not have a lot of logic to test. So let's add some logic to the order class. I ask GitHub Copilot to generate the code for calculating the total price for an order. In this code, I also changed the public list into a private one. I can now ask Copilot to generate a unit test for this code using the prompt: "Can you generate a xunit test for the order and orderlineitem class where the order has 2 orderlineitems". Three unit tests were gen
If you are building a modern web application, you will often need a frontend and a web API. I always want to keep these projects apart to maintain separation of concerns but to enable easy code sharing and developer focus, I also like to keep the projects in one solution. I love to use Azure DevOps for my CI/CD work, so I want to deploy these artifacts with one pipeline. In this post, I will show you, how you can do this. I do expect some basic knowledge about setting up a build and release pipeline in Azure DevOps. Visual Studio Solution For this blog post, I created the following solution. The solution contains a web application and a WebAPI. Both projects share the Domain class library. Build pipeline The solution can be built with the classic workflow or using the new yaml templates. For this post, I use the classic editor with the template for ASP.NET Core. The default settings for the build can be used. By default, all projects will be built and all p
Using pictures in ASP.NET Core MVC is not always very straightforward. A lot of articles you find simply upload the pictures to a www-folder and use them from there. This may work if you host your own website. This approach will give problems when using a cloud service. A cloud service may terminate your deployed version and may spin up a new fresh version to replace the old one. All pictures uploaded to the www-folder will then be lost and your database will have references to resources on the file system that do not exist anymore. In this post, I will show you how to store the images in your database and use them from there. The code for this blog post can be found here . For this example, I create a simple application to upload a profile to a website. I deliberately don't pay attention to the layout of the site, because it will only distract you from the meaningful code. I have created a regular ASP.NET Core MVC 6 application using the templates available in Visual Studio 2022.