public void DeletesTxtFilesOlderDateButKeepsBakFilesWithSameDate() { AssertEmptyTestDirectory(); var txtFileInfo = new FileInfo(_testFilePath + "\\test.txt"); using (txtFileInfo.Create()) { } var bakFileInfo = new FileInfo(_testFilePath + "\\test.bak"); using (bakFileInfo.Create()) { } var directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); var service = new Blockbuster(); var dynamicConfiguration = MockRepository.GenerateStub <IDynamicConfiguration>(); Thread.Sleep(1000); //Sleep for one second to force files to be older dynamicConfiguration.Stub(x => x.GetCommandConfigurations()).Return(new[] { string.Format("CommandName='FileExtension'; FileExtension='txt'; Directory='{0}'", _testFilePath), string.Format("CommandName='IsOlder'; IsOlder='{0}'; Directory='{1}'", DateTime.Now, _testFilePath) }); service.CleanUp(dynamicConfiguration, true); Assert.That(!txtFileInfo.Exists); Assert.That(bakFileInfo.Exists); }
private void AssertEmptyTestDirectory() { var service = new Blockbuster(); service.CleanUp(_testFilePath); var directoryInfo = new DirectoryInfo(_testFilePath); Assert.AreEqual(0, directoryInfo.GetFiles().Count()); Assert.AreEqual(0, directoryInfo.GetDirectories().Count()); }
public void DeletesCompleteDirectory() { TestFileGenerator.Generate(_testFilePath, 3, 2); DirectoryInfo directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); Blockbuster service = new Blockbuster(); service.CleanUp(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() == 0); }
public void DeletesOnlyFiles() { TestFileGenerator.Generate(_testFilePath, 3, 2); DirectoryInfo directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); AbstractCommand[] commands = { new FilesOnly() }; Blockbuster service = new Blockbuster(); service.CleanUp(_testFilePath, commands); Assert.That(directory.GetFiles().Count <FileInfo>() == 0); }
public void DeletesFilesOnly() { AssertEmptyTestDirectory(); TestFileGenerator.Generate(_testFilePath, 3, 2); var directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); var service = new Blockbuster(); var dynamicConfiguration = MockRepository.GenerateStub <IDynamicConfiguration>(); dynamicConfiguration.Stub(x => x.GetCommandConfigurations()).Return(new[] { string.Format("CommandName='FilesOnly'; Directory='{0}'", _testFilePath) }); service.CleanUp(dynamicConfiguration, false); Assert.That(directory.GetFiles().Count <FileInfo>() == 0); }
static void Main(string[] args) { var blockbuster = new Blockbuster(); try { blockbuster.CleanUp(new XmlConfigurationReader(), IsDebug(args)); } catch (Exception e) { if (IsDebug(args)) { Console.WriteLine(e.Message); Console.ReadLine(); } } }
public void DeletesFilesInBetweenSpecificTimeRangeButKeepsOthers() { AssertEmptyTestDirectory(); var txtFileInfo = new FileInfo(_testFilePath + "\\test.txt"); using (txtFileInfo.Create()) { } var dateTimeTimeRangeStart = DateTime.Now; Thread.Sleep(1000); var txtFileInfo2 = new FileInfo(_testFilePath + "\\test2.txt"); using (txtFileInfo2.Create()) { } Thread.Sleep(1000); var dateTimeTimeRangeStop = DateTime.Now; var txtFileInfo3 = new FileInfo(_testFilePath + "\\test3.txt"); using (txtFileInfo3.Create()) { } var directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); var service = new Blockbuster(); var dynamicConfiguration = MockRepository.GenerateStub <IDynamicConfiguration>(); Thread.Sleep(1000); //Sleep for one second to force files to be older dynamicConfiguration.Stub(x => x.GetCommandConfigurations()).Return(new[] { string.Format("CommandName='FileExtension'; FileExtension='txt'; Directory='{0}'", _testFilePath), string.Format("CommandName='IsNewer'; IsNewer='{0}'; Directory='{1}'", dateTimeTimeRangeStart, _testFilePath), string.Format("CommandName='IsOlder'; IsOlder='{0}'; Directory='{1}'", dateTimeTimeRangeStop, _testFilePath) }); service.CleanUp(dynamicConfiguration, true); Assert.That(txtFileInfo.Exists); Assert.That(!txtFileInfo2.Exists); Assert.That(txtFileInfo3.Exists); }
public void DeletesTxtFilesButKeepsBakFiles() { AssertEmptyTestDirectory(); var txtFileInfo = new FileInfo(_testFilePath + "\\test.txt"); using (txtFileInfo.Create()) { } var bakFileInfo = new FileInfo(_testFilePath + "\\test.bak"); using (bakFileInfo.Create()) { } var directory = new DirectoryInfo(_testFilePath); Assert.That(directory.GetFiles().Count <FileInfo>() > 0, "no testfiles present"); var service = new Blockbuster(); var dynamicConfiguration = MockRepository.GenerateStub <IDynamicConfiguration>(); dynamicConfiguration.Stub(x => x.GetCommandConfigurations()).Return(new[] { string.Format("CommandName='FileExtension'; FileExtension='txt'; Directory='{0}'", _testFilePath) }); service.CleanUp(dynamicConfiguration, true); Assert.That(!txtFileInfo.Exists); Assert.That(bakFileInfo.Exists); }
static void Main(string[] args) { var store = new Blockbuster("Calgary, Alberta, Canada."); string command = ""; while (command != "exit") { command = Console.ReadLine(); var cmdArgs = command.Split(); if (cmdArgs.Length == 0) { continue; } if (cmdArgs[0] == "add") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 2)); var length = float.Parse(cmdArgs.Last()); var tape = new VHSTape(name, length); store.AddMovie(tape); } else if (cmdArgs[0] == "find") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 1)); bool hasMovie = store.HasMovie(name); if (hasMovie) { Console.WriteLine("Store has " + name); } else { Console.WriteLine("Store does not have " + name); } } else if (cmdArgs[0] == "available") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 1)); bool available = store.IsMovieAvailable(name); if (available) { Console.WriteLine(name + " is available"); } else { Console.WriteLine(name + " is rented"); } } else if (cmdArgs[0] == "rent") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 1)); VHSTape movie = store.Rent(name); Console.WriteLine(name + ": " + (movie.Rented ? "rented" : "available")); } else if (cmdArgs[0] == "play") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 2)); var duration = float.Parse(cmdArgs.Last()); var movie = store.GetRented(name); movie.Play(duration); Console.WriteLine(movie.Name + ": " + movie.Progress); } else if (cmdArgs[0] == "rewind") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 2)); var duration = float.Parse(cmdArgs.Last()); var movie = store.GetRented(name); movie.Rewind(duration); Console.WriteLine(movie.Name + ": " + movie.Progress); } else if (cmdArgs[0] == "return") { var name = string.Join(" ", cmdArgs.Skip(1).Take(cmdArgs.Length - 1)); var movie = store.GetRented(name); store.Return(name); Console.WriteLine(name + ": " + (movie.Rented ? "rented" : "available")); } } }
public StoreService(string address, string hours) { Store = new Blockbuster(address, hours); }