Archive for category CSharp
Replacing simple factories with Func<TResult> delegate
Posted by Christopher J. McClellan in CSharp, Programming on September 20, 2015
I’ve recently noticed the emergence of a recurring pattern in my code. Each project has the same class in it, and this duplication has really been bothering me. The solution to this repetition just hit me this morning while I was reading Jon Skeet’s “C# In Depth.”
First, let me illustrate the pattern I was using and why it’s a problem.
I’ve been refactoring 1-tiered legacy code into something testable. This has involved creating a data layer class, typically called DataProvider
which implements an IDataProvider
interface so that I can easily mock out the data access. Now, because any kind of data access is extremely likely to have unmanaged resources, IDataProvider
extends IDisposable
.
Mocking the VBA Editor: Moq an IEnumerable that Works with Linq
Posted by Christopher J. McClellan in .NET, CSharp, Programming, Rubberduck, VBA on June 14, 2015
It’s been a rough morning here. I’ve just spent six hours trying to properly create a mock for the VBProject interface. There’s very little information out there about this, so I thought I’d take a moment to jot this down and save someone else the headache. For all the grief this gave me, the solution is amazing simple.
Using Hampers Testing: Enter the Factory
Posted by Christopher J. McClellan in .NET, CSharp, Programming on June 9, 2015
I’ve been writing a lot of C# lately, and paying a lot of attention to my test coverage while I’m at it. Everything was going great until I wanted to use the FolderDialogBrowser to let my users select a directory.
FolderDialogBrowser implements IDisposable, so I naturally reached for a Using block.
using (var folderPicker = new FolderBrowserDialog) { if (folderPicker.ShowDialog() != DialogResult.OK) { return; } //... }
Then I stopped dead. I can’t do that. This will display a GUI and any hope of running automated tests against this method is lost. Read the rest of this entry »