How to refactor and unit test this method. - C#