Red-Green-Code

Deliberate practice techniques for software developers

  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter

Time Tortoise: Using SystemWrapper for Unit Testing, Part 2

By Duncan Smith Nov 30 0

Wrapped System

This is one in a series of articles about Time Tortoise, a Universal Windows Platform app for planning and tracking your work schedule. For more on the development of this app and the ideas behind it, see my Time Tortoise category page.

With unit testing and code coverage back up and running after my work of the past two weeks, it’s time to update unit tests to get full coverage of recent functional changes. As I mentioned in an earlier post, the SystemWrapper project provides a starting point for mocking system classes when that is required by unit tests. To best use SystemWrapper, this would be a good time to upgrade Time Tortoise to .NET Standard 2.0.

.NET Standard 2.0

When I did my initial .NET Standard upgrade, UWP only supported .NET Standard 1.4. With the release of the Windows 10 Fall Creators Update, UWP now supports .NET Standard 2.0. This greatly increases the number of APIs available, which means that tools like SystemWrapper that were designed for the full .NET Framework will require fewer changes to work with .NET Core.

Since the Time Tortoise projects were already on .NET Standard, moving to .NET Standard 2.0 was fairly straightforward:

  • In the Project Properties for TimeTortoise.UWP, change both the Min version and Target version to Windows 10 Fall Creators Update (10.0; Build 16299). This means that the app will only be available to users on the most recent version of Windows 10. This reduces the potential user base, but one advantage of developing for Windows 10 is that users are encouraged to rapidly adopt new releases.
  • In the Project Properties for all of the .NET Standard class libraries, change the Target framework from .NET Standard 1.4 to .NET Standard 2.0.
  • In NuGet Package Manager, update all NuGet packages. Some packages have new versions that require .NET Standard 2.0.
  • Rebuild the Time Tortoise solution.

Unit Tests

In a perfect world, the upgrade would be complete after the previous steps. But as I have documented at length: using Visual Studio, .NET Core/.NET Standard, and xUnit.NET requires periodic manual attention to keep things running. So I wasn’t surprised that after the .NET Standard upgrade, none of my .NET Core unit tests were discovered.

Fortunately, I now have a tool that speeds up many of the manual steps required to get unit tests working after dependency changes. Using that tool, I made the DLL updates that were required as a result of the framework upgrade.

SystemWrapper

SystemWrapper targets the traditional .NET Framework 4.x. With the Time Tortoise projects targeting .NET Core 2.0, it should be easier to create a “SystemWrapperCore” that can be referenced from Time Tortoise.

Unfortunately, it’s not as easy as creating a few .NET Core 2.0 projects and copying over the SystemWrapper code. There are still .NET Framework APIs that don’t exist in .NET Core 2.0. So there would be some manual work involved in creating a SystemWrapperCore solution.

Rather than do all of the manual work at once, I have decided to start with an empty project and convert classes as I need them. For example, to write a proper unit test for the Daily Summary File feature, I need a mock version of System.IO.FileInfo. SystemWrapper has the appropriate interface, IFileInfo. That interface references IDirectoryInfo, so I had to add that one as well. But IDirectoryInfo uses System.Runtime.Remoting, which is not available in .NET Core. So I had to comment out the using statement, as well as one method definition, CreateObjRef.

I continued that process with IFileStream, IStream, IStreamReader, IStreamWriter, and a few others, before I got to the point where I could compile my minimal version of SystemWrapper. With luck, I’ll be able to gradually add interfaces without running into an object graph that wants to pull in most of the SystemWrapper solution.

(Image credit: Juhan Sonin)

Categories: TT

Prev
Next

Stay in the Know

I'm trying out the latest learning techniques on software development concepts, and writing about what works best. Sound interesting? Subscribe to my free newsletter to keep up to date. Learn More
Unsubscribing is easy, and I'll keep your email address private.

Getting Started

Are you new here? Check out my review posts for a tour of the archives:

  • 2023 in Review: 50 LeetCode Tips
  • 2022 in Review: Content Bots
  • 2021 in Review: Thoughts on Solving Programming Puzzles
  • Lessons from the 2020 LeetCode Monthly Challenges
  • 2019 in Review
  • Competitive Programming Frequently Asked Questions: 2018 In Review
  • What I Learned Working On Time Tortoise in 2017
  • 2016 in Review
  • 2015 in Review
  • 2015 Summer Review

Archives

Recent Posts

  • Do Coding Bots Mean the End of Coding Interviews? December 31, 2024
  • Another Project for 2024 May 8, 2024
  • Dynamic Programming Wrap-Up May 1, 2024
  • LeetCode 91: Decode Ways April 24, 2024
  • LeetCode 70: Climbing Stairs April 17, 2024
  • LeetCode 221: Maximal Square April 10, 2024
  • Using Dynamic Programming for Maximum Product Subarray April 3, 2024
  • LeetCode 62: Unique Paths March 27, 2024
  • LeetCode 416: Partition Equal Subset Sum March 20, 2024
  • LeetCode 1143: Longest Common Subsequence March 13, 2024
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2025 Duncan Smith