Shane, Thank you for the quick reply. If I understand this correctly the end result is that I have removed the file system dependency for all classes except for my wrapper and test it with an integration test. That works for me, I was just afraid I was missing the bigger picture.
Thank you! On Apr 30, 12:41 pm, Shane Courtrille <[email protected]> wrote: > To me it appears that your file system is a wrapper around the actual file > system. When testing classes that wrap external systems I wouldn't use > Rhino Mocks. I'd just write integration tests that verified things as you > are doing. > > Where Rhino Mocks comes into play is in testing any class that actually uses > MyFileSystem (recommendation would be to create an interface you mock > against). When testing those classes you would provide a mock of > MyFileSystem to verify calls against and/or provide required responses where > needed. > > > > On Thu, Apr 30, 2009 at 10:08 AM, chris <[email protected]> wrote: > > > All, > > > I am sure this is covered somewhere, but none of the information I > > have found seems to drive it home for me, I can be a little slow at > > times :) > > > Below is a simple example I am working on to better understand the > > interactions between Mocks and dependency injection. I am able to use > > Rhino.Mocks and successfully mock service classes and the like with no > > issue. However, I am attempting to mock the file system for an > > application I am working on and I can't quite see how to inject the > > filesysteminfo into the test. Here I have just created a test > > demonstrating how I would currently write a unit test in this > > scenario. I am just trying to fill in the gap on how I would remove > > this dependecy on the FileInfo Object. I imagine I need to pass an > > interface for the file system into the constructor of MyFileSystem, > > but I don't know how to turn that interface back into the actual file > > system. > > > Any guidance would be tremendously appreciated. > > > namespace Examples{ > > > public class MyFileSystem { > > private FileInfo _fileInfo; > > public void ArchiveFile(string sourceFilePath,string > > archiveFilePath){ > > _fileInfo =new FileInfo(sourceFilePath); > > _fileInfo.CopyTo(archiveFilePath); > > _fileInfo.Delete(); > > } > > } > > > [TestClass] > > public class MyFileSystemTest { > > [TestMethod] > > public void ArchiveFileTest() { > > // Arrange > > string sourceFilePath = @"c:\sourceFile.txt"; > > string archiveDirectory = @"c:\archives"; > > string archiveFilePath = string.Format > > (@"{0}\archiveFile.txt",archiveDirectory); > > File.Create(sourceFilePath).Close(); > > > Directory.CreateDirectory(archiveDirectory); > > > // Act > > MyFileSystem myFileSystem = new MyFileSystem(); > > myFileSystem.ArchiveFile(sourceFilePath,archiveFilePath); > > > // Assert > > Assert.IsTrue(File.Exists(archiveFilePath)); > > Assert.IsFalse(File.Exists(sourceFilePath)); > > > // Tear Down > > Directory.Delete(archiveDirectory,true); > > } > > > } > > > }- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/RhinoMocks?hl=en -~----------~----~----~----~------~----~------~--~---
