C# – How to unit test console output

There’s two ways to unit test code that writes to the console (Console.WriteLine() / Console.Write()): In this article, I’ll show how to do both options. Option 1 – Capture the output with Console.SetOut() Let’s say you want to unit test the following code that outputs to the console with Console.WriteLine(): You can unit test this … Read more

C# – Using XmlSerializer to serialize

Here’s how to serialize an object into XML using XmlSerializer: You must add the [Serializable] attribute to the class you want to serialize: Here’s an example of creating an Author object and feeding it to the serializer: This outputs the following XML: This example showed how to use XmlSerializer with all the default settings. In … Read more