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

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

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

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

                Bus.Send <NotifyApprovalStateChanged>(m =>
                {
                    m.DataCollectionId = message.DataCollectionId;
                    m.ApprovalState    = DataCollectionApprovalState.QaApproved.ToString();
                    m.Approver         = message.ApprovedBy;
                });
            }
        }
예제 #3
0
        public void Send_SubmitForOrdReApproval_command_to_bus_for_a_secondary_approved_data_collection_if_changes_have_been_made()
        {
            // Qa has made changes to the data collection so must be advised that it will return to secondary for reapproval
            var dataCollection = CreateDataCollectionWithState(DataCollectionStatus.SecondaryApproved);

            dataCollection.Title = "No changes yet";
            var vm = Builder <ApprovalConfirmationViewModel> .CreateNew()
                     .With(m => m.DataCollectionId = dataCollection.Id)
                     .And(m => m.State             = DataCollectionStatus.SecondaryApproved)
                     .Build();

            var oldHashCode = new DataCollectionHashCode();

            oldHashCode.UpdateHashCode(dataCollection);
            CreateQaUser();

            dataCollection.Title = "We've made a change";
            _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection);
            _hashCodeRepository.GetByDataCollectionId(dataCollection.Id).Returns(oldHashCode);

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

                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(QaId), "Invalid approver id passed to the bus");
            });

            _controller.WithCallTo(c => c.SubmitForReapproval(vm)).ShouldRedirectTo(x => x.Index);
            _bus.Received().Send(Arg.Any <Action <SubmitForSecondaryApproval> >());
            _hashCodeRepository.Received().Delete(oldHashCode);
        }
예제 #4
0
        public void Send_SubmitForOrdApproval_command_to_bus_for_a_submitted_data_collection_once_qa_approved()
        {
            // QA actions to qa approve the data collection (should pass on to secondary approver)
            var dataCollection = CreateDataCollectionWithState(DataCollectionStatus.Submitted);
            var vm             = Builder <ApprovalConfirmationViewModel> .CreateNew()
                                 .With(m => m.DataCollectionId = dataCollection.Id)
                                 .And(m => m.State             = DataCollectionStatus.Submitted)
                                 .And(m => m.IsQaApproved      = true)
                                 .Build();

            var hashCode = new DataCollectionHashCode();

            hashCode.UpdateHashCode(dataCollection);
            CreateQaUser();

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

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

                // Act
                lambda(rsc);

                // Assert
                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(QaId), "Invalid approver id passed to the bus");
            });

            _controller.WithCallTo(c => c.Confirm(vm)).ShouldRenderView("Approved")
            .WithModel <ApprovalConfirmationViewModel>(m => m.ProposedState == DataCollectionStatus.QaApproved);
        }