Example #1
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 SubmitForSecondaryReApproval message.
        /// </summary>
        /// <param name="message">SubmitForSecondaryReApproval message.</param>
        public void Handle(SubmitForSecondaryReApproval message)
        {
            Log.InfoFormat("[URDMS] Received SubmitForSecondaryReApproval message id:{0}, approvedBy:{1}, approvedOn:{2}.", message.DataCollectionId, message.ApprovedBy, message.ApprovedOn);

            Debug.Assert(Data.ApprovalState == DataCollectionApprovalState.SecondaryApproved);

            // Ensure that the current expected state is OrdApproved or RecordAmended.
            // If not, then this handler should not be processing the message.
            if (Data.ApprovalState != DataCollectionApprovalState.SecondaryApproved)
            {
                // An instance already exists for this DataCollection. There cannot be more than one.
                Log.WarnFormat("[URDMS] Saga instance is in state {0}, expected OrdApproved. 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.RecordAmended;

                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.RecordAmended;
                    m.StateChangedOn   = message.ApprovedOn;
                    m.Approver         = message.ApprovedBy;
                });

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