0

I'm writing a Powershell script which is going to go out into a client's current source control system and do a mass rename on all of the files so that they follow a new naming convention.

Being the diligent TDD developer that I am, I started with putting together a PSUnit test case. At first I was thinking that I would pass in a string to my function for the file name (along with a couple of other relevant parameters) and then return a string. Then it occurred to me that I am going to need to break apart the file name into an extension and a base name. Since System.IO.FileInfo already has that functionality, I thought why not just pass in a file object instead of a string?

If I do that however, then I don't see how I can write my PSUnit test without it being reliant on an external resource (in this case, the file must exist for me to get the FileInfo object - or does it?).

Is there a "clean" way to handle this? How are others approaching these issues?

Thanks for any help or advice!

Tom H
  • 46,766
  • 14
  • 87
  • 128
  • darn it ;) I was answer that ClearCase question of yours on the 'setview' part. What did you actually found? – VonC Feb 28 '11 at 20:20
  • I found that I'm an idiot who changed a variable name in one place, but not another. ;) The setview thing I still didn't find a solution for though. That just fixed the problem of not being able to change the file name. – Tom H Feb 28 '11 at 20:39
  • but setview is just a way to have a shortcut for dynamic views on Unix. On Windows, you would use a drive letter by mapping a folder to it with the simple (non-ClearCase) Windows command `subst` (http://www.howtogeek.com/howto/windows-vista/map-a-drive-letter-to-a-folder-the-easy-way-in-windows/) – VonC Mar 01 '11 at 10:04

1 Answers1

1

My suggestion is: Be pragmatic and pass in the base name and extension as two separate strings. For convenience reasons, you can provide an overload that accepts a FileInfo.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443