コード例 #1
0
        public async Task SendEofMessage_ShouldCallTransmissionLinkSendEofMessage()
        {
            Recipient  transmittedRecipient  = null;
            EofMessage transmittedEofMessage = null;
            var        transmissionLinkMock  = new Mock <ITransmissionLink>();

            transmissionLinkMock.Setup(x => x.SendEofMessage(It.IsAny <Recipient>(), It.IsAny <EofMessage>()))
            .Callback <Recipient, EofMessage>((x, y) =>
            {
                transmittedRecipient  = x;
                transmittedEofMessage = y;
            });

            var transmissionRepositoryMock = new Mock <ITransmissionRepository>();

            transmissionRepositoryMock.Setup(x => x.AddFailedFileTransmission(It.IsAny <Guid>(), It.IsAny <Guid>()));

            var recipient           = Helper.GetRecipientModel("testRecipient");
            var eofMesage           = Helper.GetEofMessageModel();
            var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object);
            await transmissionService.SendEofMessage(recipient, eofMesage);

            Assert.AreSame(recipient, transmittedRecipient);
            Assert.AreSame(eofMesage, transmittedEofMessage);
        }
コード例 #2
0
        public async Task SendEofMessage_Exception_ShouldAddToFailedTransmission()
        {
            var transmissionLinkMock = new Mock <ITransmissionLink>();

            transmissionLinkMock.Setup(x => x.SendEofMessage(It.IsAny <Recipient>(), It.IsAny <EofMessage>()))
            .Callback <Recipient, EofMessage>((x, y) =>
            {
                throw new InvalidOperationException();
            });

            Guid transmittedEofMessageId    = Guid.Empty;
            Guid transmittedRecipientId     = Guid.Empty;
            var  transmissionRepositoryMock = new Mock <ITransmissionRepository>();

            transmissionRepositoryMock.Setup(x => x.AddFailedEofMessageTransmission(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Callback <Guid, Guid>((x, y) => {
                transmittedEofMessageId = x;
                transmittedRecipientId  = y;
            })
            .ReturnsAsync(() => Result.Success());

            var recipient           = Helper.GetRecipientModel("testRecipient");
            var eofMesage           = Helper.GetEofMessageModel();
            var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object);
            var canContinue         = await transmissionService.SendEofMessage(recipient, eofMesage);

            Assert.AreEqual(recipient.Id, transmittedRecipientId);
            Assert.AreEqual(eofMesage.Id, transmittedEofMessageId);
            Assert.IsTrue(canContinue);
        }
コード例 #3
0
        private async Task RetryFailedTransmissionEofMessages()
        {
            WorkerLog.Instance.Information($"Retrying to send eof messages that have failed");
            var failedEofMessagesResult = await _transmissionRepository.GetFailedEofMessageTransmission();

            if (failedEofMessagesResult.WasSuccessful)
            {
                foreach (var fem in failedEofMessagesResult.Data)
                {
                    var wasSuccessful = await _transmissionService.SendEofMessage(fem.Item2, fem.Item1);

                    if (wasSuccessful)
                    {
                        await _transmissionRepository.DeleteFailedEofMessageTransmission(fem.Item1.Id, fem.Item2.Id);
                    }
                }
            }
        }
コード例 #4
0
        public async Task SendEofMessage_ExceptionDuringAddFailedTransmission_ShouldNotContinue()
        {
            var transmissionLinkMock = new Mock <ITransmissionLink>();

            transmissionLinkMock.Setup(x => x.SendEofMessage(It.IsAny <Recipient>(), It.IsAny <EofMessage>()))
            .Callback <Recipient, EofMessage>((x, y) =>
            {
                throw new InvalidOperationException();
            });

            var transmissionRepositoryMock = new Mock <ITransmissionRepository>();

            transmissionRepositoryMock.Setup(x => x.AddFailedEofMessageTransmission(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(() => Result.Failure());

            var recipient           = Helper.GetRecipientModel("testRecipient");
            var eofMesage           = Helper.GetEofMessageModel();
            var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object);
            var canContinue         = await transmissionService.SendEofMessage(recipient, eofMesage);

            Assert.IsFalse(canContinue);
        }