public void DeletionOfLocalFilesSkippedIfItemNotDeleted()
        {
            MockVssItems items = new MockVssItems();

            items.Add(_normalItem);
            _project.SetItems(items);

            _getTask.RemoveDeletedFromLocalImage();

            Assert.IsTrue(File.Exists(_localNormalItemPath), "Normal file should still exist");
        }
        public void Setup()
        {
            //create base folder for "project"'s local copy
            _workingFolder = Path.Combine(Path.GetTempPath(), "FROM_VSS");
            Directory.CreateDirectory(_workingFolder);

            //This item represents the base project item
            _project      = new MockVssItem();
            _project.Name = "TEMPVSSPROJECT";
            _project.SetType((int)VSSItemType.VSSITEM_PROJECT);
            string localProjectPath = _workingFolder;

            Directory.CreateDirectory(localProjectPath);

            //a normal file item whose local copy is in the project's local folder;
            _normalItem      = new MockVssItem();
            _normalItem.Name = "normalItem.txt";
            _normalItem.SetType((int)VSSItemType.VSSITEM_FILE);
            _normalItem.Deleted  = false;
            _localNormalItemPath = Path.Combine(localProjectPath, _normalItem.Name);
            StreamWriter s = File.CreateText(_localNormalItemPath);

            s.Close();

            //a deleted file item that represents an earlier, deleted version of the normal file item
            _normalItemDeleted      = new MockVssItem();
            _normalItemDeleted.Name = "normalItem.txt";
            _normalItemDeleted.SetType((int)VSSItemType.VSSITEM_FILE);
            _normalItemDeleted.Deleted = true;

            //a deleted file item whose local copy is located under the base project's local folder
            _item      = new MockVssItem();
            _item.Name = "tempVSSItem.txt";
            _item.SetType((int)VSSItemType.VSSITEM_FILE);
            _item.Deleted  = true;
            _localItemPath = Path.Combine(localProjectPath, _item.Name);
            s = File.CreateText(_localItemPath);
            s.Close();

            //a deleted file item with *no* local copy
            _alreadyGoneItem      = new MockVssItem();
            _alreadyGoneItem.Name = "notthere.txt";
            _alreadyGoneItem.SetType((int)VSSItemType.VSSITEM_FILE);
            _alreadyGoneItem.Deleted = true;

            //a deleted file item whose local copy is located under the base project's local folder and read-only
            _readOnlyItem      = new MockVssItem();
            _readOnlyItem.Name = "readOnlyTempVSSItem.txt";
            _readOnlyItem.SetType((int)VSSItemType.VSSITEM_FILE);
            _readOnlyItem.Deleted  = true;
            _localReadOnlyItemPath = Path.Combine(localProjectPath, _readOnlyItem.Name);
            s = File.CreateText(_localReadOnlyItemPath);
            s.Close();
            File.SetAttributes(_localReadOnlyItemPath, FileAttributes.ReadOnly);

            //a deleted project item whose local copy is located under the base project's local folder and read-only
            _readOnlySubProject      = new MockVssItem();
            _readOnlySubProject.Name = "READONLYSUBPROJECT";
            _readOnlySubProject.SetType((int)VSSItemType.VSSITEM_PROJECT);
            _readOnlySubProject.Deleted  = true;
            _localReadOnlySubProjectPath = Path.Combine(localProjectPath, _readOnlySubProject.Name);
            Directory.CreateDirectory(_localReadOnlySubProjectPath);
            File.SetAttributes(_localReadOnlySubProjectPath, FileAttributes.ReadOnly);

            //a deleted file item whose local copy is located under the read-only sub project's local folder
            //is itself read-only
            _readOnlySubItem      = new MockVssItem();
            _readOnlySubItem.Name = "readOnlySubItem.txt";
            _readOnlySubItem.SetType((int)VSSItemType.VSSITEM_FILE);
            _readOnlySubItem.Deleted  = true;
            _localReadOnlySubItemPath = Path.Combine(_localReadOnlySubProjectPath, _readOnlySubItem.Name);
            s = File.CreateText(_localReadOnlySubItemPath);
            s.Close();
            File.SetAttributes(_localReadOnlySubItemPath, FileAttributes.ReadOnly);

            //a deleted project item whose local copy is in the base project's local folder
            _subProject      = new MockVssItem();
            _subProject.Name = "SUBPROJECT";
            _subProject.SetType((int)VSSItemType.VSSITEM_PROJECT);
            _subProject.Deleted  = true;
            _localSubProjectPath = Path.Combine(localProjectPath, _subProject.Name);
            Directory.CreateDirectory(_localSubProjectPath);

            //a deleted file item whose local copy is in the sub-project's local folder
            _subItem      = new MockVssItem();
            _subItem.Name = "tempVSSSubItem.txt";
            _subItem.SetType((int)VSSItemType.VSSITEM_FILE);
            _subItem.Deleted  = true;
            _localSubItemPath = Path.Combine(_localSubProjectPath, _subItem.Name);
            s = File.CreateText(_localSubItemPath);
            s.Close();

            //add the sub file item to the sub project's items collection
            MockVssItems items = new MockVssItems();

            items.Add(_subItem);
            _subProject.SetItems(items);

            //add the read-only sub file item to read-only sub-project's items collection
            items = new MockVssItems();
            items.Add(_readOnlySubItem);
            _readOnlySubProject.SetItems(items);

            //create the instance of the GetTask that we will use in the tests
            _getTask               = new GetTask();
            _getTask.Item          = _project;
            _getTask.LocalPath     = new DirectoryInfo(_workingFolder);
            _getTask.RemoveDeleted = true;

            //make the GetTask happy by giving it a dummy project file to reference
            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<project name='test'/>");
            _getTask.Project = new Project(doc, Level.Info, 0);
        }
Exemple #3
0
        public void Setup() {
            //create base folder for "project"'s local copy
            _workingFolder = Path.Combine(Path.GetTempPath(), "FROM_VSS");
            Directory.CreateDirectory(_workingFolder);

            //This item represents the base project item
            _project = new MockVssItem();
            _project.Name = "TEMPVSSPROJECT";
            _project.SetType((int) VSSItemType.VSSITEM_PROJECT);
            string localProjectPath = _workingFolder;
            Directory.CreateDirectory(localProjectPath);

            //a normal file item whose local copy is in the project's local folder;
            _normalItem = new MockVssItem();
            _normalItem.Name = "normalItem.txt";
            _normalItem.SetType((int) VSSItemType.VSSITEM_FILE);
            _normalItem.Deleted = false;
            _localNormalItemPath = Path.Combine(localProjectPath, _normalItem.Name);
            StreamWriter s = File.CreateText(_localNormalItemPath);
            s.Close();

            //a deleted file item that represents an earlier, deleted version of the normal file item
            _normalItemDeleted = new MockVssItem();
            _normalItemDeleted.Name = "normalItem.txt";
            _normalItemDeleted.SetType((int) VSSItemType.VSSITEM_FILE);
            _normalItemDeleted.Deleted = true;

            //a deleted file item whose local copy is located under the base project's local folder
            _item = new MockVssItem();
            _item.Name = "tempVSSItem.txt";
            _item.SetType((int) VSSItemType.VSSITEM_FILE);
            _item.Deleted = true;
            _localItemPath = Path.Combine(localProjectPath, _item.Name);
            s = File.CreateText(_localItemPath);
            s.Close();

            //a deleted file item with *no* local copy
            _alreadyGoneItem = new MockVssItem();
            _alreadyGoneItem.Name = "notthere.txt";
            _alreadyGoneItem.SetType((int) VSSItemType.VSSITEM_FILE);
            _alreadyGoneItem.Deleted = true;

            //a deleted file item whose local copy is located under the base project's local folder and read-only
            _readOnlyItem = new MockVssItem();
            _readOnlyItem.Name = "readOnlyTempVSSItem.txt";
            _readOnlyItem.SetType((int) VSSItemType.VSSITEM_FILE);
            _readOnlyItem.Deleted = true;
            _localReadOnlyItemPath = Path.Combine(localProjectPath, _readOnlyItem.Name);
            s = File.CreateText(_localReadOnlyItemPath);
            s.Close();
            File.SetAttributes(_localReadOnlyItemPath, FileAttributes.ReadOnly);

            //a deleted project item whose local copy is located under the base project's local folder and read-only
            _readOnlySubProject = new MockVssItem();
            _readOnlySubProject.Name = "READONLYSUBPROJECT";
            _readOnlySubProject.SetType((int) VSSItemType.VSSITEM_PROJECT);
            _readOnlySubProject.Deleted = true;
            _localReadOnlySubProjectPath = Path.Combine(localProjectPath, _readOnlySubProject.Name);
            Directory.CreateDirectory(_localReadOnlySubProjectPath);
            File.SetAttributes(_localReadOnlySubProjectPath, FileAttributes.ReadOnly);

            //a deleted file item whose local copy is located under the read-only sub project's local folder 
            //is itself read-only
            _readOnlySubItem = new MockVssItem();
            _readOnlySubItem.Name = "readOnlySubItem.txt";
            _readOnlySubItem.SetType((int) VSSItemType.VSSITEM_FILE);
            _readOnlySubItem.Deleted = true;
            _localReadOnlySubItemPath = Path.Combine(_localReadOnlySubProjectPath, _readOnlySubItem.Name);
            s = File.CreateText(_localReadOnlySubItemPath);
            s.Close();
            File.SetAttributes(_localReadOnlySubItemPath, FileAttributes.ReadOnly);

            //a deleted project item whose local copy is in the base project's local folder
            _subProject = new MockVssItem();
            _subProject.Name = "SUBPROJECT";
            _subProject.SetType((int) VSSItemType.VSSITEM_PROJECT);
            _subProject.Deleted = true;
            _localSubProjectPath = Path.Combine(localProjectPath, _subProject.Name);
            Directory.CreateDirectory(_localSubProjectPath);

            //a deleted file item whose local copy is in the sub-project's local folder
            _subItem = new MockVssItem();
            _subItem.Name = "tempVSSSubItem.txt";
            _subItem.SetType((int) VSSItemType.VSSITEM_FILE);
            _subItem.Deleted = true;
            _localSubItemPath = Path.Combine(_localSubProjectPath, _subItem.Name);
            s = File.CreateText(_localSubItemPath);
            s.Close();

            //add the sub file item to the sub project's items collection
            MockVssItems items = new MockVssItems();
            items.Add(_subItem);
            _subProject.SetItems(items);

            //add the read-only sub file item to read-only sub-project's items collection
            items = new MockVssItems();
            items.Add(_readOnlySubItem);
            _readOnlySubProject.SetItems(items);

            //create the instance of the GetTask that we will use in the tests
            _getTask = new GetTask();
            _getTask.Item = _project;
            _getTask.LocalPath = new DirectoryInfo(_workingFolder);
            _getTask.RemoveDeleted = true;

            //make the GetTask happy by giving it a dummy project file to reference
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<project name='test'/>");
            _getTask.Project = new Project(doc, Level.Info, 0);
        }