예제 #1
0
        public async Task ThenProcessandStoreMessage()
        {
            //Arrange
            await base.SetupDatabase();

            var message = new ApprovedTransferConnectionInvitationEvent()
            {
                CreatedAt             = DateTime.UtcNow,
                SenderAccountHashedId = "aabbcc16",
                SenderAccountId       = 12345,
                ApprovedByUserId      = 98765,
                ReceiverAccountId     = 54321
            };

            var sentMessage = new WhenAStartTransferRequestEventIsRecieved();

            await sentMessage.ThenProcessandStoreMessage();

            var logger = new TraceWriterStub(TraceLevel.Verbose);

            //Act
            DAS.Data.Functions.Transfers.ProcessTransferRelationshipApprovedMessage.Run(message, null, logger, transferRelationshipService, log);


            //Assert
            //Assert.AreEqual(1, logger.Traces.Count);

            var databaseAsExpected = TestHelper.ConditionMet(IsDatabaseInExpectedState, TimeSpan.FromSeconds(60));

            Assert.IsTrue(databaseAsExpected);
        }
        public static void RunDLQ([ServiceBusTrigger("approved_transfer_connection_invitation", "RDS_ApprovedTransferConnectionInvitiationProcessor/$DeadLetterQueue", AccessRights.Manage, Connection = "MessageBusConnectionString")] BrokeredMessage bMessage, ExecutionContext executionContext, TraceWriter log, [Inject] ITransferRelationshipService transferRelationshipMessageService, [Inject] ILog logger)
        {
            log.Info($"Processing messageId: {bMessage.MessageId} {{ID={executionContext.InvocationId}}}");

            ApprovedTransferConnectionInvitationEvent messageBody = null;

            try
            {
                messageBody = bMessage.GetBody <ApprovedTransferConnectionInvitationEvent>();
            }
            catch (Exception e)
            {
                log.Error($"Unable to deserialize message body for message queue sent_transfer_connection_invitation. messageId: {bMessage.MessageId} {{ID={executionContext.InvocationId}}}", e);
                bMessage.Defer();
            }

            if (messageBody != null)
            {
                try
                {
                    transferRelationshipMessageService.SaveApprovedMessage(messageBody);
                    log.Info($"Processing Completed for messageId: {bMessage.MessageId} {{ID={executionContext.InvocationId}}}");
                    bMessage.Complete();
                }
                catch (Exception e)
                {
                    log.Error($"Unable to save message for queue sent_transfer_connection_invitation DLQ. messageId: {bMessage.MessageId} {{ID={executionContext.InvocationId}}}", e);
                    bMessage.Defer();
                }
            }
        }
        public void AndIsATransferApprovedMessageThenSaveMessageDetails()
        {
            var approvedMessage = new ApprovedTransferConnectionInvitationEvent();

            _transferRelationshipRepositoryMock.Setup(s => s.SaveTransferRelationship(It.IsAny <TransferRelationship>())).Returns(Task.FromResult(true));

            _service.SaveApprovedMessage(approvedMessage);

            _transferRelationshipRepositoryMock.Verify(v => v.SaveTransferRelationship(It.IsAny <TransferRelationship>()));
        }
예제 #4
0
        public void SaveApprovedMessage(ApprovedTransferConnectionInvitationEvent message)
        {
            var senderUserId = GetSenderUserId(message.SenderAccountId, message.ReceiverAccountId);

            var transferRelationship = new TransferRelationship()
            {
                SenderAccountId    = message.SenderAccountId,
                ReceiverAccountId  = message.ReceiverAccountId,
                SenderUserId       = senderUserId,
                RelationshipStatus = TransferRelationshipStatus.Approved,
                ApproverUserId     = message.ApprovedByUserId
            };

            _transferRelationshipRepository.SaveTransferRelationship(transferRelationship);
        }
예제 #5
0
        public void Arrange()
        {
            _subscriptionFactory = new Mock <IMessageSubscriberFactory>();
            _subscriber          = new Mock <IMessageSubscriber <ApprovedTransferConnectionInvitationEvent> >();

            _messageContent = new ApprovedTransferConnectionInvitationEvent();

            _mockMessage = new Mock <IMessage <ApprovedTransferConnectionInvitationEvent> >();
            _mockMessage.Setup(x => x.Content).Returns(_messageContent);

            _mediator    = new Mock <IMediator>();
            _tokenSource = new CancellationTokenSource();

            _processor = new ApprovedTransferConnectionInvitationMessageProcessor(_subscriptionFactory.Object, Mock.Of <ILog>(),
                                                                                  _mediator.Object);

            _subscriptionFactory.Setup(x => x.GetSubscriber <ApprovedTransferConnectionInvitationEvent>()).Returns(_subscriber.Object);

            _subscriber.Setup(x => x.ReceiveAsAsync())
            .ReturnsAsync(() => _mockMessage.Object)
            .Callback(() => _tokenSource.Cancel());
        }
        public static void Run([ServiceBusTrigger("approved_transfer_connection_invitation", "RDS_ApprovedTransferConnectionInvitiationProcessor", AccessRights.Manage, Connection = "MessageBusConnectionString")] ApprovedTransferConnectionInvitationEvent message, ExecutionContext executionContext, TraceWriter log, [Inject] ITransferRelationshipService transferRelationshipMessageService, [Inject] ILog logger)
        {
            transferRelationshipMessageService.SaveApprovedMessage(message);

            logger.Info($"C# service bus trigger function executed at ProcessTransferRelationshipStartMessage: {DateTime.Now}");
        }