Ejemplo n.º 1
0
        public void AddFile_ShouldCreateNewFileInProjectFolderAndNotifyWithEvent()
        {
            // Arrange
            var fileContent = Guid.NewGuid().ToString();

            object?eventSender = null;
            ProjectFileAddedEventArgs?eventArgs = null;

            _folder.FileAdded += (sender, args) =>
            {
                eventSender = sender;
                eventArgs   = args;
            };

            // Act
            IProjectFile newFile;

            using (var stream = fileContent.ToStream())
            {
                newFile = _folder.AddFile("SomeFile.txt", stream);
            }

            // Assert
            Assert.That(_folder.Files, Has.Count.EqualTo(1));
            Assert.That(newFile, Is.EqualTo(_folder.Files.Single()));
            Assert.That(newFile.Name, Is.EqualTo("SomeFile.txt"));
            Assert.That(newFile.Extension, Is.EqualTo(".txt"));
            Assert.That(newFile.Path, Is.EqualTo(Path.Combine(_folder.FolderPath, "SomeFile.txt")));
            Assert.That(newFile.ParentFolder, Is.EqualTo(_folder));
            Assert.That(File.Exists(newFile.Path), Is.True, "File was not created.");
            Assert.That(File.ReadAllText(newFile.Path), Is.EqualTo(fileContent));
            Assert.That(eventSender, Is.EqualTo(_folder));
            Debug.Assert(eventArgs != null, nameof(eventArgs) + " != null");
            Assert.That(eventArgs.File, Is.EqualTo(newFile));
        }
Ejemplo n.º 2
0
 private void RecurseReadFolders(XmlTextReader reader, ref IProjectFolder folder)
 {
     if (reader.IsEmptyElement)
     {
         return;
     }
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.EndElement)
         {
             return;
         }
         if (reader.Name == "Folder")
         {
             IProjectFolder subFolder = new ProjectFolder(this, reader.GetAttribute("Name"));
             folder.AddFolder(subFolder);
             RecurseReadFolders(reader, ref subFolder);
         }
         else if (reader.Name == "File")
         {
             IProjectFile file = new ProjectFile(this, reader.GetAttribute("Path"));
             folder.AddFile(file);
         }
         else
         {
             return;
         }
     }
 }
Ejemplo n.º 3
0
        public IProjectFile AddFile(IProjectFolder parentFolder, string fullPath)
        {
            IProjectFile file = new ProjectFile(this, fullPath);

            parentFolder.AddFile(file);
            return(file);
        }
 public void CreateEmptyScene(string name, IProjectFolder folder)
 {
     CreateEmptyScene(name, (fileName, stream) => folder.AddFile(fileName, stream));
 }