public void DisplaySize_FileIsMaximumMBytes_DisplayGbFormat()
    {
      var fileElement = new FileElement("file1.text", 1024*1024*1024 - 1);

      var actual = fileElement.DisplaySize;
      Assert.AreEqual("1.0 G", actual);
    }
    public void DisplaySize_FileIs1023Bytes_Display1023bytes()
    {
      var fileElement = new FileElement("file1.text", 1023);

      var actual = fileElement.DisplaySize;
      Assert.AreEqual("1023 Byte(s)", actual);
    }
    public void DisplaySize_FileIs1025Bytes_DisplayKbFormat()
    {
      var fileElement = new FileElement("file1.text", 1025);

      var actual = fileElement.DisplaySize;
      Assert.AreEqual("1.0 K", actual);
    }
    private static FileElement AddNewFile(FolderElement folderElement, string fileName, int fileSize)
    {
      var fileElement = new FileElement(fileName, fileSize);
      folderElement.Add(fileElement);

      return fileElement;
    }
    public void ShortName_NormalFullPath_OnlyReturnTheFileName()
    {
      var fileElement = new FileElement(@"C:\folder1\1.txt", 100);
      var expected = "1.txt";
      var actual = fileElement.ShortName;

      Assert.AreEqual(expected, actual);
    }
        private FolderElement InspectDirectory()
        {
            Stack <FolderElement> stack = new Stack <FolderElement>();
            var rootElement             = new FolderElement(TargetDirectory);

            stack.Push(rootElement);
            var errors = new StringBuilder();

            while (stack.Count > 0)
            {
                try
                {
                    var currentFolderElement = stack.Pop();
                    var directoryName        = currentFolderElement.Name;

                    var fileEntries = Directory.EnumerateFiles(directoryName);
                    foreach (var fileName in fileEntries)
                    {
                        var fileInfo    = new FileInfo(fileName);
                        var fileElement = new FileElement(fileName, fileInfo.Length);
                        currentFolderElement.Add(fileElement);

                        _BusyWindow.ShowCurrentInspectingElement(fileName);
                    }

                    var subDirectoryEntries = Directory.EnumerateDirectories(directoryName);
                    foreach (var subDirectory in subDirectoryEntries)
                    {
                        var folderElement = new FolderElement(subDirectory);
                        currentFolderElement.Add(folderElement);

                        _BusyWindow.ShowCurrentInspectingElement(subDirectory);

                        stack.Push(folderElement);
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    errors.AppendLine(ex.Message);
                }
                catch (FileNotFoundException ex)
                {
                    errors.AppendLine(ex.Message);
                }
                catch (Exception ex)
                {
                    errors.AppendLine(ex.Message);
                }
            }

            ProcessDetailedErrors = errors.ToString();

            return(rootElement);
        }
Пример #7
0
 public void Size_IncreseElementSize_ParentSizeAlsoIncreased()
 {
   var folderElement = new FolderElement("root");
   var fileElement1 = new FileElement("file1.txt", 10);
   var fileElement2 = new FileElement("file2.txt", 50);
   folderElement.Add(fileElement1);
   folderElement.Add(fileElement2);
   // change the size from 10 to 100
   fileElement1.Size = 100;
   Assert.AreEqual(150, folderElement.Size);
 }
    // Initialize the directories as below
    // - root
    //    - root-file1.text
    //    - root-file2.text
    //    - sub
    //        - sub file1.txt
    //        - sub file2.txt
    private void InitTheElementsList()
    {
      var rootFolder = new FolderElement("root");
      var rootFile1 = new FileElement("root-file1.text", 100);
      var rootFile2 = new FileElement("root-file1.text", 100);
      var subFolder = new FolderElement("sub");
      var subFile1 = new FileElement("sub file1.txt", 300);
      var subFile2 = new FileElement("sub file2.txt", 400);
      
      rootFolder.Add(rootFile1);
      rootFolder.Add(rootFile2);
      rootFolder.Add(subFolder);

      subFolder.Add(subFile1);
      subFolder.Add(subFile2);

      _SizeCounterViewModel.ElementList.Add(rootFolder);
    }
Пример #9
0
 public void DisplayString_FileNameIsFullPath_DisplayFormatIsCorrect()
 {
   var fileElement = new FileElement(@"c:\folder1\file1.txt", 1024);
   var actualDisplayString = fileElement.DisplayString;
   Assert.AreEqual("file1.txt [1.0 K]", actualDisplayString);
 }
    private void ParseDirectory(string directory, FolderElement currentFolderElement)
    {
      //TODO: change the recursive to do-while
      var fileEntries = Directory.GetFiles(directory);
      foreach (var fileName in fileEntries)
      {
        var fileInfo = new FileInfo(fileName);
        var fileElement = new FileElement(fileName, fileInfo.Length);
        currentFolderElement.Add(fileElement);
      }

      var subDirectoryEntries = Directory.GetDirectories(directory);
      foreach (var subDirectory in subDirectoryEntries)
      {
        var folderElement = new FolderElement(subDirectory);
        currentFolderElement.Add(folderElement);
        ParseDirectory(subDirectory, folderElement);
      }
    }