public void SnapshotCanBeSetAndRetrieved()
 {
     var request = new StatusSnapshotResponse();
     var snapshot = new ProjectStatusSnapshot();
     request.Snapshot = snapshot;
     Assert.AreSame(snapshot, request.Snapshot);
 }
 public void RequestConstructorInitialisesTheValues()
 {
     var request = new EncryptedRequest();
     var response = new StatusSnapshotResponse(request);
     // Only check one property is set, since the properties are set by the base class
     Assert.AreEqual(request.Identifier, response.RequestIdentifier);
 }
 public void FullConstructorInitialisesTheValues()
 {
     var response1 = new StatusSnapshotResponse();
     response1.RequestIdentifier = "12345";
     var response2 = new StatusSnapshotResponse(response1);
     // Only check one property is set, since the properties are set by the base class
     Assert.AreEqual(response1.RequestIdentifier, response2.RequestIdentifier);
 }
 public void TakeStatusSnapshot()
 {
     var response = new StatusSnapshotResponse();
     response.Result = ResponseResult.Success;
     response.Snapshot = new ProjectStatusSnapshot();
     var client = new CruiseServerClient(
         new ServerStub("TakeStatusSnapshot", typeof(ProjectRequest), "Project #1", response));
     var result = client.TakeStatusSnapshot("Project #1");
     Assert.AreSame(response.Snapshot, result);
 }
 public void GetFinalBuildStatus()
 {
     var response = new StatusSnapshotResponse();
     response.Result = ResponseResult.Success;
     response.Snapshot = new ProjectStatusSnapshot();
     var client = new CruiseServerClient(
         new ServerStub("GetFinalBuildStatus", typeof(BuildRequest), "Project #1", response));
     var result = client.GetFinalBuildStatus("Project #1", "Build #1");
     Assert.AreSame(response.Snapshot, result);
 }
 /// <summary>
 /// Takes a status snapshot of a project.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>The snapshot of the current status.</returns>
 public virtual StatusSnapshotResponse TakeStatusSnapshot(ProjectRequest request)
 {
     ProjectStatusSnapshot snapshot = null;
     StatusSnapshotResponse response = new StatusSnapshotResponse(RunProjectRequest(request,
         SecurityPermission.ViewProject,
         null,
         delegate
         {
             IProjectIntegrator integrator = GetIntegrator(request.ProjectName);
             if (integrator != null)
             {
                 // First see if the project has its own associated generator
                 if (integrator.Project is IStatusSnapshotGenerator)
                 {
                     snapshot = (integrator.Project as IStatusSnapshotGenerator).GenerateSnapshot()
                         as ProjectStatusSnapshot;
                 }
                 else
                 {
                     // Otherwise generate an overview snapshot (details will not be available)
                     ProjectStatus status = integrator.Project.CreateProjectStatus(integrator);
                     snapshot = new ProjectStatusSnapshot();
                     snapshot.Name = integrator.Project.Name;
                     if (status.Activity.IsBuilding())
                     {
                         snapshot.Status = ItemBuildStatus.Running;
                     }
                     else if (status.Activity.IsPending())
                     {
                         snapshot.Status = ItemBuildStatus.Pending;
                     }
                     else if (status.Activity.IsSleeping())
                     {
                         switch (status.BuildStatus)
                         {
                             case IntegrationStatus.Success:
                                 snapshot.Status = ItemBuildStatus.CompletedSuccess;
                                 break;
                             case IntegrationStatus.Exception:
                             case IntegrationStatus.Failure:
                                 snapshot.Status = ItemBuildStatus.CompletedSuccess;
                                 break;
                         }
                     }
                 }
             }
             else
             {
                 throw new NoSuchProjectException(request.ProjectName);
             }
         }));
     response.Snapshot = snapshot;
     return response;
 }
        /// <summary>
        /// Gets the final status for a build.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="SnapshotResponse"/> for the build.</returns>
        public virtual StatusSnapshotResponse GetFinalBuildStatus(BuildRequest request)
        {
            ItemStatus snapshot = null;
            var response = new StatusSnapshotResponse(RunProjectRequest(
                request,
                SecurityPermission.ViewProject,
                SecurityEvent.GetFinalBuildStatus,
                (req, res) =>
                {
                    var project = this.GetIntegrator(req.ProjectName).Project;
                    snapshot = project.RetrieveBuildFinalStatus(request.BuildName);
                }));
            if (response.Result == ResponseResult.Success)
            {
                response.Snapshot = snapshot as ProjectStatusSnapshot;
                if (response.Snapshot == null)
                {
                    response.Result = ResponseResult.Warning;
                    response.ErrorMessages.Add(
                        new ErrorMessage("Build status does not exist"));
                }
            }

            return response;
        }
        public void GetFinalBuildStatusPassesOnCall()
        {
            var mocks = new MockRepository();
            var innerServer = mocks.DynamicMock<ICruiseServer>();
            var request = new BuildRequest();
            var response = new StatusSnapshotResponse();
            Expect.Call(innerServer.GetFinalBuildStatus(request))
                .Return(response);
            mocks.ReplayAll();

            var configFile = this.CreateTemporaryConfigurationFile();
            using (var server = new RemoteCruiseServer(innerServer, configFile, true))
            {
                var actual = server.GetFinalBuildStatus(request);
                Assert.AreSame(response, actual);
            }

            mocks.VerifyAll();
        }