.NET

Unit testing is usually used for testing public types and members. However, there are cases when you might need to test types or members that are not public. These could be internal classes or private helper methods, for instance. Whether that is proper unit testing or beyond its scope is not a discussion that I want to get into here. However, in this post, I will show how you can unit test non-public types and members from .NET assemblies.

When faced with the need for testing non-public types and members you can use several approaches:

  • change the accessibility to public; you can do that perhaps only for debug builds and keep the intended accessibility in release builds by using conditional compilation.
  • provide public members of a class that invoke private ones;
  • use reflection.

The first solutions involve changing the API only for the sake of the testing. The last solution avoids that but requires more work. To help with that, the Visual Studio unit testing framework provides some helper types that enable you to focus on the actual testing and be less concerned about the reflection details.

Read More Unit testing non-public types and members for .NET projects

You may have multiple versions of the .NET framework installed and used on your machine. The framework has two components: the set of assemblies that provide functionalities for your application, and the common language runtime (CLR) that handles the execution of the application. These two components are versioned separately. If you what to see what…

Read More How to determine what CLR versions are installed using C++

Last week I have attended ITCamp in Cluj-Napoca, Romania. The conference has already established itself as the most important community-driven technology conference in Romania and lately, as the organizers put it, its focus has shifted from being a Microsoft-centric conference to a technology-centric conference. And this year it has been larger than ever before: 600…

Read More Field trip report from ITCamp 2016

In WPF, Silverlight and Windows Phone it is possible to render a visual object into a bitmap using the RenderTargetBitmap. This functionality, that I find pretty basic, was not available for Windows Store applications. Fortunately, Windows 8.1 provides that functionality for Windows Store applications too, through the same RenderTargetBitmap class. There are some limitations though:…

Read More Render the screen of a Windows Store App to a bitmap in Windows 8.1

A WinForms DataGridView control has the ability to automatically generate its columns and populate from a specified data source (which can be a DataSet, a simple list or something else). All you have to do is something like this:

When you do the same in MFC, it doesn’t work (supposing that you followed all…

Read More Bindings for DataGridView hosted in an MFC application

Problem I have recently migrated a C# 2.0 project registered for COM interop to .NET 4.5 and when I imported the type library in a C++ project with no_registry, suddenly I got some errors because the type library could not be imported. Here are the steps to reproduce: create a .NET Class Library project and…

Read More error C3510: cannot locate dependent type library ” {bed7f4ea-1a96-11d2-8f08-00a0c9a6186d} v.2.4

The Problem You install a .NET redistributable package and want to reference the assemblies in your project. However, though everything is correctly installed to GAC, the assemblies don’t show up in Visual Studio’s Add Reference dialog in the .NET tab (regardless of what version of Visual Studio you have). The Cause Redistributable assemblies are intended…

Read More Why won’t my .NET redistributable assemblies show up in Visual Studio’s ‘Add Reference’ dialog?

Windows Runtime, or shortly WinRT, is a new runtime (siting on top of the Windows kernel) that allows developers to write Metro style applications for Windows 8, using a variety of languages including C/C++, C#, VB.NET or JavaScript/HTML5. Microsoft has started rolling out information about Windows 8 and the new runtime at BUILD. WinRT is…

Read More Windows Runtime