Example #1
0
        public void WhenPathDoesNotContainCharactersToEscape_ShouldReturnPathUnchanged( )
        {
            var fixture = new Fixture( );
            var p1      = fixture.Create("p1-");
            var result  = LinuxPath.Escape(p1);

            Assert.Equal(p1, result);
        }
Example #2
0
        public void WhenPathContiansCharacterToEscape_ShouldReturnEscapedString( )
        {
            var chars   = @"\()*+?""'#/".ToCharArray();
            var fixture = new Fixture( );

            foreach (var c in chars)
            {
                var b      = "before-";
                var a      = "-after";
                var check  = "{0}{1}{2}".With(b, c, a);
                var result = LinuxPath.Escape(check);
                Assert.Equal("{0}\\{1}{2}".With(b, c, a), result);
            }
        }
Example #3
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(string path)
        {
            if (Device == null)
            {
                throw new ArgumentNullException("device", "Device cannot be null.");
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "Path cannot be null or empty.");
            }

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver();
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = Device.BusyBox.Available ? "touch" : ">";
                    var command = string.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU())
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!string.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(string.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(Device.FileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Example #4
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(String path)
        {
            Device.ThrowIfNull("Device");

            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver();
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = ">";
                    var command = String.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU())
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!String.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(String.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(this.fileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Example #5
0
 public void WhenPathIsEmpty_ShouldReturnThrowArgumentNullException( )
 {
     Assert.Throws <ArgumentException> (() => {
         LinuxPath.Escape(string.Empty);
     });
 }
Example #6
0
 public void WhenPathIsNull_ShouldReturnThrowArgumentNullException()
 {
     Assert.Throws <ArgumentException>(() => {
         LinuxPath.Escape(null);
     });
 }