Пример #1
0
    public void DoesMoveFileWorkBasic()
    {
        FileSystem fs = new FileSystem();

        Assert.IsNotNull(fs);

        EditableFile f   = fs.createFile("test.txt");
        Directory    dir = fs.createDirectory("testing");

        Assert.AreEqual(f.getParent(), fs.root);
        Assert.AreEqual(f.getPath(), "/test.txt");
        Assert.AreEqual(dir.getPath(), "/testing");

        fs.moveFile(f, dir);
        Assert.AreEqual(f.getParent(), dir);
        Assert.AreEqual(f.getPath(), dir.getPath() + "/" + f.getFullName());
        Assert.AreEqual("/testing/test.txt", dir.getPath() + "/" + f.getFullName());
    }
Пример #2
0
    public void BasicFileTest()
    {
        FileSystem fs = new FileSystem();

        Assert.IsNotNull(fs);

        EditableFile f = fs.createFile("test.txt");

        Assert.IsNotNull(f);
        Assert.AreEqual("test.txt", f.getFullName());
        Assert.AreEqual("test", f.getName());
        Assert.AreEqual("txt", f.getExtension());
        Assert.AreEqual("/test.txt", f.getPath());
        Assert.AreEqual(fs.root, f.getParent());
    }
Пример #3
0
        public override string execute(params string[] args)
        {
            NetworkNode node = GameManager.currentHost;

            if (!(node is IFileSystem))
            {
                throw new ExecutionException("The current node does not support a file system.");
            }
            FileSystem currentFileSystem = (node as IFileSystem).fileSystem;

            string currentPath = GameManager.currentPath;
            string filename    = args [1];
            File   newFile     = currentFileSystem.getFile(currentPath + "/" + filename);

            if (newFile == null)
            {
                throw new ExecutionException("File \"" + filename + "\" does not exist.");
            }

            if (newFile is Directory)
            {
                throw new ExecutionException("Can't cat file: is directory.");
            }

            if (!(newFile is EditableFile))
            {
                throw new ExecutionException("Can't cat file: contents are unreadable.");
            }

            EditableFile newFileE = newFile as EditableFile;

            try {
                return("Contents of file \"" + newFileE.getFullName() + "\":\n" + newFileE.getContents());
            } catch (InvalidUserException iue) {
                throw new ExecutionException(iue.Message);
            }
        }
Пример #4
0
    public void DoesMoveFileWorkAdvanced()
    {
        FileSystem fs = new FileSystem();

        Assert.IsNotNull(fs);

        Directory    dir  = fs.createDirectory("testing");
        Directory    dir2 = fs.createDirectory("testing2");
        EditableFile f    = fs.createFile("test.txt");

        Assert.AreEqual(f.getParent(), fs.root);
        Assert.AreEqual(f.getPath(), "/test.txt");
        Assert.AreEqual(dir.getPath(), "/testing");
        Assert.AreEqual(dir2.getPath(), "/testing2");

        fs.moveFile(dir2, dir);
        Assert.AreEqual(dir2.getParent(), dir);
        Assert.AreEqual(dir2.getPath(), dir.getPath() + "/" + dir2.getFullName());

        fs.moveFile(f, dir2);
        Assert.AreEqual(f.getParent(), dir2);
        Assert.AreEqual(f.getParent().getParent(), dir);
        Assert.AreEqual(f.getPath(), dir2.getPath() + "/" + f.getFullName());
        Assert.AreEqual(f.getPath(), dir.getPath() + "/" + dir2.getFullName() + "/" + f.getFullName());

        Assert.AreEqual(dir.getNumFiles(), 1);
        Assert.AreEqual(dir2.getNumFiles(), 1);

        Directory dir3 = fs.createDirectory(dir2.getPath() + "/" + "testing3");

        Assert.AreEqual(dir3.getPath(), dir2.getPath() + "/" + dir3.getFullName());
        Assert.AreEqual(dir2.getNumFiles(), 2);

        fs.moveFile(dir3, dir2);
        Assert.AreEqual(dir3.getPath(), dir2.getPath() + "/" + dir3.getFullName());
        Assert.AreEqual(dir2.getNumFiles(), 2);

        fs.moveFile(f, dir3);
        Assert.AreEqual(f.getParent(), dir3);
        Assert.AreEqual(f.getPath(), dir3.getPath() + "/" + f.getFullName());
        Assert.AreEqual("/testing/testing2/testing3/test.txt", f.getPath());
        Assert.AreEqual(dir.getNumFiles(), 1);
        Assert.AreEqual(dir2.getNumFiles(), 1);
        Assert.AreEqual(dir3.getNumFiles(), 1);

        // Can't move files to/from null locations
        Assert.Throws(typeof(InvalidFileException), delegate {
            fs.moveFile(null, dir3);
        });
        Assert.Throws(typeof(InvalidFileException), delegate {
            fs.moveFile(dir3, null);
        });
        Assert.AreEqual(dir3.getParent(), dir2);

        // Can't move directory inside itself
        Assert.Throws(typeof(InvalidFileException), delegate {
            fs.moveFile(dir3, dir3);
        });

        // Can't move directories inside children of themselves
        Assert.Throws(typeof(InvalidFileException), delegate {
            fs.moveFile(dir2, dir3);
        });
    }