Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A good TDD-Friendly .NET file IO library [closed]

As many of you know, the System.IO namespace is abysmally designed. I would like a free library that wraps the file IO functionality in a sane way (read: doesn't require you passing strings all over the place). I remember reading some time ago that there is a small handful of these libraries already written (and the author was surprised that there were not more). I think it was one of the guys on devlicious or codebetter or Los Techies that did one of them.

Does anyone know what I'm talking about or another good File IO wrapper?

Edit: I suppose I should specify that I do Test Driven Development and my concerns are largely (but not entirely) around System.IO's test friendliness.

like image 431
George Mauer Avatar asked Jul 07 '09 19:07

George Mauer


People also ask

What is TDD example?

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and ...

What is main focus of TDD Mcq?

The simple concept of TDD is to write and correct the failed tests before writing new code (before development). This helps to avoid duplication of code as we write a small amount of code at a time in order to pass tests.

What is TDD in C#?

TDD stands for test-driven development. It's a common misconception to think TDD is a testing technique, and the name certainly plays a part in that. Actually, TDD is a software development methodology in which you use unit tests to drive the development of the code.


1 Answers

What's wrong with System.IO.FileInfo?


I was curious, so started to create a set of wrappers using ReSharper. It took me 16 minutes, and I haven't tested it, and don't know if it meets your needs. Still, I thought I'd outline the process I used:

  1. Create a new class library project
  2. Make Class1 public and rename it to be FileSystemInfoWrapper
  3. Give it a private field _fsi of type FileSystemInfo (resolve the class to get the namespace imported)
  4. Click the field and choose to Initialize in Constructor
  5. Click the field again and use ReSharper -> Code -> Generate (Alt+Ins); Choose Generate Delegating Members; Click "Public" to get all public members
  6. Same for FileInfo, but also derive from FileSystemInfoWrapper and remove the duplicate members (ReSharper could have done better here)
  7. Same for DirectoryInfo, but also derive from FileSystemInfoWrapper and fix duplicates
  8. For each of the wrappers, click the class then use ReSharper->Refactor->Extract Interface
  9. Have IFileInfoWrapper and IDirectoryInfoWrapper derive from IFileSystemInfoWrapper, and remove duplicates.

The result is interfaces that include the methods and properties of the corresponding classes, and concrete classes that delegate to the original classes and implement the interfaces. You should then be able to create your own mock classes, and change your code to use the interfaces instead of directly using the System.IO concrete classes.

like image 192
John Saunders Avatar answered Oct 26 '22 16:10

John Saunders