public void WhenFileDoesNotExist_FileNotFoundExceptionShouldBeThrown() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"c:\myfile.txt", new MockFileData("Testing is meh.") }, { @"c:\demo\jQuery.js", new MockFileData("some js") }, { @"c:\demo\image.gif", new MockFileData(new byte[] { 0x12, 0x34, 0x56, 0xd2 }) } }); StockQuoteProcessor sqp = new StockQuoteProcessor(fileSystem); Assert.Throws <FileNotFoundException>(() => sqp.CheckFileExists(@"c:\data\stock-data.csv")); }
public void WhenFileExist_NoExceptionShouldBeThrown() { // Arrange String datafileName = @"c:\data\stock-data.csv"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { datafileName, new MockFileData("Testing is meh.") } }); // Act StockQuoteProcessor sqp = new StockQuoteProcessor(fileSystem); sqp.CheckFileExists(@"c:\data\stock-data.csv"); }
public void WhenFileExistWithZeroBytes_IOExceptionShouldBeThrown() { // Arrange String datafileName = @"c:\data\stock-data.csv"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { datafileName, new MockFileData("") } }); // Act StockQuoteProcessor sqp = new StockQuoteProcessor(fileSystem); Assert.Throws <IOException>(() => sqp.CheckFileHasData(@"c:\data\stock-data.csv")); }
public void ArchiveProcessWillCreateArchiveDirectoryIfItDoesNotExist() { // Arrange String datafileName = @"c:\data\stock-data.csv"; String archiveDirectory = @"C:\archive"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { datafileName, new MockFileData(VALID_DATA) } }); // Act StockQuoteProcessor sqp = new StockQuoteProcessor(fileSystem); sqp.ArchiveFile(@"c:\data\stock-data.csv", archiveDirectory); // Assert Assert.True(fileSystem.Directory.Exists(archiveDirectory)); }
public void ReadFileProcessIsAbleToHandleCommentsCorrectly() { // Arrange DateTime dateTime = new DateTime(2018, 5, 30, 21, 30, 17); String datafileName = @"c:\data\stock-data.csv"; String archiveDirectory = @"C:\archive"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { datafileName, new MockFileData(VALID_DATA_WITH_COMMENT_LINE) } }); fileSystem.Directory.CreateDirectory(archiveDirectory); // Act StockQuoteProcessor sqp = new StockQuoteProcessor(fileSystem); var data = sqp.ReadStockQuoteFile(datafileName); // Assert Assert.Equal(9, data.Count); Assert.True(data.Count(x => x.Ticker == "INTC") == 0); // Intel should be commented out }