Posts

Donate

Mocking Methods With Ref Arguments Using Moq Framework In C#

Image
Hello, Here's a straightforward post on how to mock methods with arguments that are passed by reference using the Moq framework. First, we need to create a C# Class Library and Xunit projects in Visual Studio. Create two folders in the class libary project specifically Infrastructure and Models. The structure of the application resembles the image below. Add a class to hold a person's information Person.cs inside the models folder with properties such as SocialSecurityID, FirstName and etc. Only the StatusUpdate property is used in the test project. public class Person { public int SocialSecurityID { get ; set ; } public string FirstName { get ; set ; } public string MiddleName { get ; set ; } public string LastName { get ; set ; } public string StatusUpdate { get ; set ; } public Person() { SocialSecurityID = 0; FirstName = string .Empty; MiddleName = string .Empty; LastName = string .E

How To Add Cell Borders Or Grid Lines To Filled Cells In Excel Using ClosedXML

Image
Hello, When dealing with filled cells or columns of an Excel workshet via ClosedXML, you may notice that after you produced the Excel file(s), the filled columns or cells don't have borders. This assume that your report does not apply borders to the used cells or columns such as the image below. To apply borders to certain columns within a range or not, you need to set both the Outside and Inside borders with Thin borderstyle. And then apply your preferred color to the top, bottom, left and right borders. row++; xlWSheet.Range( 1 , 1 , row, 7 ).Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin) .Border.SetInsideBorder(XLBorderStyleValues.Thin) .Border.SetTopBorderColor(XLColor.LightGray) .Border.SetBottomBorderColor(XLColor.LightGray) .Border.SetLeftBorderColor(XLColor.LightGray) .Border.SetRightBorderColor(XLColor.LightGray); Filled columns or cells with borders. Cheers!

Git Error - git is not recognized as an internal or external command

Image
Hello, After downloading and installing Git and some reason git commands don't work on the command prompt. This could be a case of git not added to the Environment variables path. This assumes that the Git software has been installed properly on your machine. So to fix this error, you need to open System Properties, click Environment Variables. Add the bin and cmd paths of the Git software similar to the picture below. Once they're added to the System variables, git commands will work as expected. Cheers!

LG 34" Ultrawide Monitor Hot Or Warm Temperature

Image
Hello, I've noticed in a while that my LG 34" Ultrawide Monitor is hotter when I switched the display modes thru the On-Screen Control software. As I researched thru the internet, I found an article from LG Support on why the LG Monitor screen seems so hot. A useful tip led me to check the brightness of my screen. And behold, it has a value of 100% that causes the temperature to be warmer compared to other monitors. After reducing the brightness and contrast, I felt like the monitor's temperature dropped significantly lower which is acceptable to me. The article can be found here LG Monitor - The Screen Feels Hot Cheers!

Docker Error - denied: requested access to the resource is denied.

Image
Good day gents! As I was about to push my docker image to Docker Hub, I was met with an error "denied: requested access to the resource is denied.". After searching the net, I found the solution that is to login your username using the command " docker login -u your_username " followed by your password using Windows Powershell. Once done logging in, push the image to the repository using docker push command "docker push your_username/dockerdemo". Reference: Docker Denied Requested Access To The Resource Cheers!

Docker ERROR: failed to solve: failed to compute cache key: failed to calculate checksum

Image
Hi all, Another issue that I encountered while learning Docker specifically build a docker image using .NET Core is the "ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 405e1ab5-1d6a-4b32-b558-cdcae05e5207::q4alx8yd9wbrz32p1zv7s1yg7: "/dockerdemo/dockerdemo.csproj": not found". My project is a simple ASP.NET Core Web API project. After doing some research, the solution that works for me is to cut the docker file "DockerFile" from the folder that contains the .csproj file. Then paste it to the root folder of the project that contains the solution file (.sln). Run again powershell and execute docker build command that points to the root folder of the project where the docker file is cut and pasted. That's it!

Docker Desktop Requires A Newer WSL Kernel Version Issue. Update the WSL kernel by running "wsl --update"

Image
Hello Team, I started familiarizing containerization concepts using Docker in .NET Core in the event that our team will embrace the application of containerization to our certain projects in the near future. When I installed the Docker desktop, it prompted an error "Docker Desktop Requires A Newer WSL Kernel Version Issue. Update the WSL kernel by running "wsl --update" or follow instructions at https://docs.microsoft.com/windows/wsl/wsl2-kernel." The fix to this issue is either running the "wsl --update" command similar to the screenshot below. Or download and install "wsl_update_x64" package from here Linux Kernel Update Package Cheers!

How To Extract The Node Name In The Self-Closing Tags Using Regular Expressions In C#

Image
Hello, In one of the parser that I made, I need to extract the node name which is in a self closing XML tag as part of the requirement for the output. In order to do that, you need to combine a positive lookbehind for the lesser than symbol (?<=<) and positive lookahead for the forward slash and greater than symbol (?=/>). And then perform a greedy search in between those groups. The complete pattern for that is presented on the code snippet below. var NodeValue = Regex.Match(lstTempNodes[i], @"(?<=<)(.*)(?=/>)" ).Value.Trim(); Here's the pattern matching of several self-closing XML tags. Source Code: How To Extract The Node Name In The Self-Closing Tags Using Regular Expressions In C#

How To Iterate Or Loop Through A C# Dictionary And Update It's Value

Hello, Most of us C# developers are working on Dictionaries to store multiple sets of data with unique keys. And in times that we need to modify our logic with the Dictionary object involved, we normally do that using looping construct. Given a simple Dictionary object below with int as key and string as value. Dictionary< int , string > styledLines = new Dictionary< int , string >(); We may thought that looping through this object with the code presented below may work. However, when running your app, this will cause a "Collection was modified; enumeration operation may not execute" issue. It's because we are using the collection's key directly. foreach ( var kvp in styledLines) { styledLines[kvp.key] = $ "Series# {seriesNum} "; } To fix that we have a couple of options. Given that our key is an integer type with values in sequential order such as 0...1000, we could use for loop to change the values such as below. var startI

BinaryFormatter Custom Binder Alternative Using Newtonsoft.Json.JsonSerializer In C#

Hello Everyone! In relation to the previous post on updating the serialization and deserialization using BinaryFormatter class to NewtonSoft's JsonSerializer, we also need to change the Binder functionality using NewtonSoft. The class below inherits the SerializationBinder and overrides the BindToType() function. sealed class HELPERSCustomBinder : SerializationBinder { public override Type BindToType( string assemblyName, string typeName) { if (!typeName.ToUpper().Contains( "SYSTEM.STRING" )) { throw new SerializationException( "Only List<string> is allowed" ); } return Assembly.Load(assemblyName).GetType(typeName); } } The class above will then be assigned to the Binder property of BinaryFormatter as shown from the code snippet below. public static T BuildFromSerializedBuffer<T>( byte [] buffer) where T : new () { MemoryStream MS; BinaryFormatter BF; T rtn; rtn = default (T); try { using (M

Donate