• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Csharp

Logging in a .NET Core 3 SignalR client

October 18, 2019 by Robert Leave a Comment

SignalR is part of the .NET Core framework that allows for real-time communication between a server and any number of clients.  The traditional example is a JavaScript client that can receive updates directly from a web server asynchronously, but you can also connect to a SignalR hub with a C# client. via GIPHY HubConnectionBuilder To … [Read more…]

Posted in: .NET Core, ASP.NET, C#, SignalR, Web Development Tagged: C#, Csharp, DotNetCore, DotNetCore3, SignalR

Unit Testing bit fields

August 9, 2019 by Robert Leave a Comment

Last week I wrote about bit fields and how they can be used to easily track boolean values.  Unit testing is pretty important to me, because I make mistakes a lot.  By writing tests, I can have a little bit of confidence in the code that I wrote. via GIPHY Bit Fields Knowing how bit … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: Bitwise, Csharp, enum, Flags, Testing

ASP.NET Core Unit Testing – Setting the request body

June 28, 2019 by Robert Leave a Comment

Every now and again I find it necessary to set up the request body manually (as opposed to using the [FromBody] tag).  In the controller you can read from the request body easily enough: via GIPHY Testing How do you test this?  Normally I would just create a controller, call the method, and check the … [Read more…]

Posted in: .NET Core, ASP.NET, C#, MVC, Unit Testing, Web API, Web Development Tagged: ASP.NET, ASP.NET Core, Csharp, unit testing, Web Development

Autofac–Automatically registering generics via constructors

May 17, 2019 by Robert Leave a Comment

Recently I had a situation where I had a class and interface to make a generic service which would do something based on whatever type is provided.  (Obviously, it was not so contrived…) These would then get injected to other classes to be used as necessary: Which works fine… as long as you remember to … [Read more…]

Posted in: .NET Core, C#, Reflection Tagged: .NET, AutoFac, C#, Csharp, DependencyInjection, Generics, IoC, Reflection

Serializing XUnit test cases

April 12, 2019 by Robert Leave a Comment

XUnit has some cool stuff like Theory, which lets you write multiple test cases to run against the same test code.  This lets you test multiple paths with different inputs without having to write multiple tests.  This can save you a lot of time as you can cover a lot of ground with a single … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: C#, Csharp, IXunitSerializable, unit testing, XUnit

C# overwriting a static field with reflection

April 5, 2019 by Robert Leave a Comment

Imagine that you have a NuGet package containing a bunch of static strings.  These fields are intended to be used instead of magic strings, making it so anything that takes a dependency on this NuGet package will all be on the same page about these unique keys. Now suppose that these keys also represent the … [Read more…]

Posted in: .NET Core, C#, Reflection, Unit Testing Tagged: Csharp, Reflection, Static, Testing

Colorful Console App

February 15, 2019 by Robert Leave a Comment

In a C# console application, you can change the color of the text emitted by Console.WriteLine by setting Console.ForegroundColor and Console.BackgroundColor.  It’s pretty straightforward, but if you want to make the output have different colors to denote different things, its kind of cumbersome to have to set the color and then write the output, and … [Read more…]

Posted in: C#, Generic Tagged: C#, Colors, Console, Csharp, Terminal

C# Unit Testing object equality without implementing .Equals

August 24, 2018 by Robert Leave a Comment

Recently I was trying to write a unit test testing to see if one object was equal to another.  The objects themselves were simple, just a collection of built-in types, so it should be easy to test. .Equals However, since I didn’t implement .Equals, C# doesn’t natively know how to check if the objects are … [Read more…]

Posted in: C#, Reflection, Unit Testing Tagged: C#, Csharp, Equals, PixieDust, Reflection, Testing, UnitTesting

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall