示例#1
0
        public void Send_SubmitForFinalApproval_command_to_bus_for_a_qa_approved_data_collection_once_secondary_approved()
        {
            // Secondary approver actions to secondary approve the data collection (should pass by to qa approver)
            var dataCollection = CreateDataCollectionWithState(DataCollectionStatus.QaApproved);
            var vm             = Builder <ApprovalConfirmationViewModel> .CreateNew()
                                 .With(m => m.DataCollectionId        = dataCollection.Id)
                                 .And(m => m.State                    = DataCollectionStatus.QaApproved)
                                 .And(m => m.DoesNotViolateAgreements = true)
                                 .And(m => m.DoesNotViolateConfidentialityAndEthics = true)
                                 .Build();

            var hashCode = new DataCollectionHashCode();

            hashCode.UpdateHashCode(dataCollection);
            CreateOrdApprover();

            _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection);
            _hashCodeRepository.GetByDataCollectionId(dataCollection.Id).Returns(hashCode);

            _bus.When(c => c.Send(Arg.Any <Action <SubmitForFinalApproval> >())).Do(a =>
            {
                var rsc    = new SubmitForFinalApproval();
                var lambda = a.Arg <Action <SubmitForFinalApproval> >();

                lambda(rsc);

                Assert.That(rsc.DataCollectionId, Is.EqualTo(dataCollection.Id), "Invalid data collection id passed to the bus");
                Assert.That(rsc.ApprovedOn, Is.EqualTo(dataCollection.CurrentState.StateChangedOn).Within(1).Minutes, "Invalid approval date passed to the bus");
                Assert.That(rsc.ApprovedBy, Is.EqualTo(SecondaryApproverId), "Invalid approver id passed to the bus");
            });

            _controller.WithCallTo(c => c.Confirm(vm)).ShouldRenderView("Approved")
            .WithModel <ApprovalConfirmationViewModel>(m => m.ProposedState == DataCollectionStatus.SecondaryApproved);
        }
示例#2
0
        public void Setup()
        {
            Test.Initialize();


            _now = DateTime.Now;

            _submitForApprovalMessage = new SubmitForApproval
            {
                ApprovedBy       = "GH13579",
                ApprovedOn       = _now,
                DataCollectionId = 1
            };

            _submitForSecondaryApprovalMessage = new SubmitForSecondaryApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "FH13545",
                ApprovedOn       = _submitForApprovalMessage.ApprovedOn.AddDays(1)
            };

            _submitForFinalApprovalMessage = new SubmitForFinalApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "787878r",
                ApprovedOn       = _submitForSecondaryApprovalMessage.ApprovedOn.AddDays(1)
            };

            _submitForSecondaryReApprovalMessage = new SubmitForSecondaryReApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "454545k",
                ApprovedOn       = _submitForFinalApprovalMessage.ApprovedOn.AddDays(1)
            };


            _publishDataCollectionMessage = new PublishDataCollection
            {
                DataCollectionId = 1,
                ApprovedBy       = "321312w",
                ApprovedOn       = _submitForFinalApprovalMessage.ApprovedOn.AddDays(2)
            };

            _exportToVivoResponse = new ExportToVivoResponse
            {
                DataCollectionId = 1
            };
        }
        /// <summary>
        /// Handles the SubmitForFinalApproval message.
        /// </summary>
        /// <param name="message">SubmitForFinalApproval message.</param>
        public void Handle(SubmitForFinalApproval message)
        {
            Log.InfoFormat("[URDMS] Received SubmitForFinalApproval message id:{0}, approvedBy:{1}, approvedOn:{2}.", message.DataCollectionId, message.ApprovedBy, message.ApprovedOn);

            Debug.Assert(Data.ApprovalState == DataCollectionApprovalState.QaApproved || Data.ApprovalState == DataCollectionApprovalState.RecordAmended);

            // Ensure that the current expected state is QaApproved.
            // If not, then this handler should not be processing the message.
            if (Data.ApprovalState != DataCollectionApprovalState.QaApproved && Data.ApprovalState != DataCollectionApprovalState.RecordAmended)
            {
                // An instance already exists for this DataCollection. There cannot be more than one.
                Log.WarnFormat("[URDMS] Saga instance is in state {0}, expected QaApproved or RecordAmended. Saga will not continue processing this message.", Data.ApprovalState);
                Bus.DoNotContinueDispatchingCurrentMessageToHandlers();
            }
            else
            {
                // Update State
                Data.Approver       = message.ApprovedBy;
                Data.StateChangedOn = message.ApprovedOn;
                Data.ApprovalState  = DataCollectionApprovalState.SecondaryApproved;

                Log.InfoFormat("[URDMS] Publishing ApprovalStateChanged for id:{0}", message.DataCollectionId);
                // Change the approvalState of the DataCollection
                Bus.Publish <ApprovalStateChanged>(m =>
                {
                    m.DataCollectionId = message.DataCollectionId;
                    m.ApprovalState    = DataCollectionApprovalState.SecondaryApproved;
                    m.StateChangedOn   = message.ApprovedOn;
                    m.Approver         = message.ApprovedBy;
                });

                Bus.Send <NotifyApprovalStateChanged>(m =>
                {
                    m.DataCollectionId = message.DataCollectionId;
                    m.ApprovalState    = DataCollectionApprovalState.SecondaryApproved.ToString();
                    m.Approver         = message.ApprovedBy;
                });
            }
        }