Exemplo n.º 1
0
        public void FileAlreadyExistsExceptionCtor2()
        {
            FileAlreadyExistsException ex = new FileAlreadyExistsException("path");

            ex.Message.Should().Be("Cannot create a file when that file already exists.");
            ex.Path.Should().Be("path");
        }
Exemplo n.º 2
0
        public void FileAlreadyExistsExceptionCtor1()
        {
            FileAlreadyExistsException ex = new FileAlreadyExistsException("message", "path");

            ex.Message.Should().Be("message");
            ex.Path.Should().Be("path");
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGiveAClearErrorIfTheDestinationAlreadyExists()
        internal virtual void ShouldGiveAClearErrorIfTheDestinationAlreadyExists()
        {
            Path archive     = _testDirectory.file("the-archive.dump").toPath();
            Path destination = _testDirectory.directory("the-destination").toPath();
            FileAlreadyExistsException exception = assertThrows(typeof(FileAlreadyExistsException), () => (new Loader()).load(archive, destination, destination));

            assertEquals(destination.ToString(), exception.Message);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldGiveAClearErrorIfTheArchiveAlreadyExists()
        {
            Path directory = _testDirectory.directory("a-directory").toPath();
            Path archive   = _testDirectory.file("the-archive.dump").toPath();

            Files.write(archive, new sbyte[0]);
            FileAlreadyExistsException exception = assertThrows(typeof(FileAlreadyExistsException), () => (new Dumper()).dump(directory, directory, archive, GZIP, Predicates.alwaysFalse()));

            assertEquals(archive.ToString(), exception.Message);
        }
Exemplo n.º 5
0
        /// <summary>Create an IOE when an operation fails</summary>
        /// <param name="path">path of operation</param>
        /// <param name="operation">operation attempted</param>
        /// <param name="exception">caught the exception caught</param>
        /// <returns>an IOE to throw that contains the path and operation details.</returns>
        protected internal virtual IOException OperationFailure(string path, string operation
                                                                , Exception exception, IList <ACL> acls)
        {
            IOException ioe;
            string      aclList = "[" + RegistrySecurity.AclsToString(acls) + "]";

            if (exception is KeeperException.NoNodeException)
            {
                ioe = new PathNotFoundException(path);
            }
            else
            {
                if (exception is KeeperException.NodeExistsException)
                {
                    ioe = new FileAlreadyExistsException(path);
                }
                else
                {
                    if (exception is KeeperException.NoAuthException)
                    {
                        ioe = new NoPathPermissionsException(path, "Not authorized to access path; ACLs: "
                                                             + aclList);
                    }
                    else
                    {
                        if (exception is KeeperException.NotEmptyException)
                        {
                            ioe = new PathIsNotEmptyDirectoryException(path);
                        }
                        else
                        {
                            if (exception is KeeperException.AuthFailedException)
                            {
                                ioe = new AuthenticationFailedException(path, "Authentication Failed: " + exception
                                                                        + "; " + securityConnectionDiagnostics, exception);
                            }
                            else
                            {
                                if (exception is KeeperException.NoChildrenForEphemeralsException)
                                {
                                    ioe = new NoChildrenForEphemeralsException(path, "Cannot create a path under an ephemeral node: "
                                                                               + exception, exception);
                                }
                                else
                                {
                                    if (exception is KeeperException.InvalidACLException)
                                    {
                                        // this is a security exception of a kind
                                        // include the ACLs to help the diagnostics
                                        StringBuilder builder = new StringBuilder();
                                        builder.Append("Path access failure ").Append(aclList);
                                        builder.Append(" ");
                                        builder.Append(securityConnectionDiagnostics);
                                        ioe = new NoPathPermissionsException(path, builder.ToString());
                                    }
                                    else
                                    {
                                        ioe = new RegistryIOException(path, "Failure of " + operation + " on " + path + ": "
                                                                      + exception.ToString(), exception);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (ioe.InnerException == null)
            {
                Sharpen.Extensions.InitCause(ioe, exception);
            }
            return(ioe);
        }