public void RequestConstructorInitialisesTheValues()
 {
     var request = new EncryptedRequest();
     var response = new FileTransferResponse(request);
     // Only check one property is set, since the properties are set by the base class
     Assert.AreEqual(request.Identifier, response.RequestIdentifier);
 }
 public void FileTransferCanBeSetAndRetrieved()
 {
     var request = new FileTransferResponse();
     var mocks = new MockRepository();
     var transfer = mocks.StrictMock<IFileTransfer>();
     request.FileTransfer = transfer;
     Assert.AreEqual(transfer, request.FileTransfer);
 }
 public void FullConstructorInitialisesTheValues()
 {
     var response1 = new FileTransferResponse();
     response1.RequestIdentifier = "12345";
     var response2 = new FileTransferResponse(response1);
     // Only check one property is set, since the properties are set by the base class
     Assert.AreEqual(response1.RequestIdentifier, response2.RequestIdentifier);
 }
 public void RetrieveFileTransfer()
 {
     var response = new FileTransferResponse();
     response.Result = ResponseResult.Success;
     response.FileTransfer = this.mocks.StrictMock<IFileTransfer>();
     var client = new CruiseServerClient(
         new ServerStub("RetrieveFileTransfer", typeof(FileTransferRequest), "Project #1", response));
     var result = client.RetrieveFileTransfer("Project #1", "Build #1");
     Assert.AreSame(response.FileTransfer, result);
 }
        /// <summary>
        /// Retrieve a file transfer object.
        /// </summary>
        /// <param name="request"></param>
        public virtual FileTransferResponse RetrieveFileTransfer(FileTransferRequest request)
        {
            var response = new FileTransferResponse(request);
            try
            {
                // Validate that the path is valid
                var sourceProject = GetIntegrator(request.ProjectName).Project;
                var filePath = Path.Combine(sourceProject.ArtifactDirectory, request.FileName);
                var fileInfo = new FileInfo(filePath);
                if (!fileInfo.FullName.StartsWith(sourceProject.ArtifactDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    var message = string.Format(CultureInfo.CurrentCulture, "Files can only be retrieved from the artefact folder - unable to retrieve {0}", request.FileName);
                    Log.Warning(message);
                    throw new CruiseControlException(message);
                }
                else if (fileInfo.FullName.StartsWith(Path.Combine(sourceProject.ArtifactDirectory, "buildlogs"), StringComparison.OrdinalIgnoreCase))
                {
                    var message = string.Format(CultureInfo.CurrentCulture, "Unable to retrieve files from the build logs folder - unable to retrieve {0}", request.FileName);
                    Log.Warning(message);
                    throw new CruiseControlException(message);
                }

                RemotingFileTransfer fileTransfer = null;
                if (fileInfo.Exists)
                {
                    Log.Debug(string.Format(CultureInfo.CurrentCulture, "Retrieving file '{0}' from '{1}'", request.FileName, request.ProjectName));
                    fileTransfer = new RemotingFileTransfer(File.OpenRead(filePath));
                }
                else
                {
                    Log.Warning(string.Format(CultureInfo.CurrentCulture, "Unable to find file '{0}' in '{1}'", request.FileName, request.ProjectName));
                }
                response.FileTransfer = fileTransfer;
                response.Result = ResponseResult.Success;
            }
            catch (Exception error)
            {
                response.Result = ResponseResult.Failure;
                response.ErrorMessages.Add(
                    new ErrorMessage(error.Message));
            }
            return response;
        }