Anduin Xue

let today = new Beginning();


Show .NET code coverage rate and unit test status with GitLab CI\CD pipeline

Before starting, you need to make sure you have your own GitLab instance or have registered Check in your .NET project. Make sure there is the .sln file in the root of the repository: file Add the following packages to all your unit test projects: coverlet.collector JunitXml.TestLogger Project Sdk=Microsoft.NET.Sdk PropertyGroup TargetFrameworknet6.0/TargetFramework  …

.NET Test Code coverage Continuous Integration GitLab junit YAML

Validate an object in any C# projects

Sometimes, we need to check if the input is valid. Usually, we may do this: if (string.IsNullOrWhiteSpace(InputArgument.TargetMachine) || string.IsNullOrWhiteSpace(InputArgument.PatchId)) { throw new ArgumentException($"Invalid input argument! Patch ID: '{InputArgument.PatchId}', Target Machine: '{InputArgument.TargetMachine}'!");  …

ASP.NET Core C# .NET Validation

C# Play with GZip.

A extension class for string to add GZip features. Copy the following code to your project first. using System; using System.IO; using System.IO.Compression; using System.Text; public static class GZipExtensions { private static byte[] Zip(string str) { var bytes = Encoding.UTF8.GetBytes(str); using (var msi = new MemoryStream(  …

C# .NET Compress GZip Base64

Retry with exponetial back-off on C#

Just built a simple retry engine in C#. /// /// Retry engine. /// public class RetryEngine { private static Random rnd = new Random(); private readonly ILogger logger; /// /// Creates new retry engine. /// /// Logger public RetryEngine(  …

C# .NET Retry

Build a common cache service for your C# app.

Recently, I found that almost every time I creates a new .NET app, I gonna need cache service. While Microsoft officially provides the IMemoryCache, I found that it is pretty complicated for you to use it. For it requires a lot of code. So I wrapped it to a more common one. Before starting, make sure the project references Microsoft.Extensions.Caching.Memory and Microsoft.Extensions.Logging.  …

ASP.NET Core C# .NET Core Performance Caching .NET Cache MemoryCache

Display code coverage information for .NET Core project using Azure DevOps.

Target. Display code coverage information on your own .NET Core project. First, create a build pipeline in your Azure DevOps. If you are using the classic designer, you need to add new .NET Core command line step. Make sure you publish the test result. As for the Arguments input, insert: --configuration $(buildConfiguration) --collect "Code coverage" Or if you are using YAML: Add  …

.NET Core Azure DevOps .NET Test MSTest Integration Test Code coverage GitHub

How to serialize JSON object in C# without Newtonsoft Json

In many cases, we may not be able to access Newtonsoft.Json package. Like sometime there might be different packages using different versions of it, which may cause version conflict via build. That usually happens in some projects really large. So how can we play with JSON as while without it? In pure C#? First, copy the following class to your project: public static class MyJsonConverter {  …

C# JSON .NET Newtonsoft.Json

  • 1