/// <inheritdoc/> public async Task QueueContractEmailReminderMessage(Contract contract) { _logger.LogInformation($"Queuing email reminder for contract [{contract.ContractNumber}]."); var message = new ContractReminderMessage() { ContractId = contract.Id }; IDictionary <string, string> properties = new Dictionary <string, string>() { { "messageType", ContractReminderMessage.MessageProcessor_ContractReminderMessage } }; await _sbMessagingService.SendAsBinaryXmlMessageAsync(message, properties); await _auditService.AuditAsync( new Pds.Audit.Api.Client.Models.Audit { Severity = 0, Action = Audit.Api.Client.Enumerations.ActionType.ContractEmailReminderQueued, Ukprn = contract.Ukprn, Message = $"Email reminder has been queued for contract with Id [{contract.Id}].", User = Audit_User_System }); }
public void SendAsBinaryXmlMessageAsync_OmittingProperties_DoesNotCauseException() { // Arrange var sender = Mock.Of <IMessageSender>(); Mock.Get(sender) .Setup(p => p.SendAsync(It.IsAny <Message>())) .Throws <InvalidOperationException>(); ContractReminderMessage reminder = CreateContractReminderMessage(); ServiceBusMessagingService sbMessagingService = new ServiceBusMessagingService(sender); // Act Func <Task> act = async() => await sbMessagingService.SendAsBinaryXmlMessageAsync(reminder, null); // Assert act.Should().Throw <InvalidOperationException>(); Mock.Get(sender).VerifyAll(); }
public void QueueContractEmailReminderMessage_DoesNotThrowExceptions() { // Arrange ContractReminderMessage actualReminder = null; IDictionary <string, string> actualDictionary = null; var config = CreateContractsDataApiConfiguration(new Dictionary <string, string>()); Mock.Get(_contractsLogger) .Setup(p => p.LogInformation(It.IsAny <string>(), It.IsAny <object[]>())); Mock.Get(_sbMessagingService) .Setup(p => p.SendAsBinaryXmlMessageAsync(It.IsAny <ContractReminderMessage>(), It.IsAny <IDictionary <string, string> >())) .Returns(Task.CompletedTask) .Callback((ContractReminderMessage reminder, IDictionary <string, string> props) => { actualReminder = reminder; actualDictionary = props; }) .Verifiable(); Mock.Get(_auditService) .Setup(p => p.AuditAsync(It.IsAny <Audit.Api.Client.Models.Audit>())) .Returns(Task.CompletedTask) .Verifiable(); ContractNotificationService service = CreateContractNotificationService(config); // Act Func <Task> act = async() => await service.QueueContractEmailReminderMessage(_contract); // Assert act.Should().NotThrow(); actualReminder.ContractId.Should().Be(_contract.Id); actualDictionary["messageType"].Should().Be(ContractReminderMessage.MessageProcessor_ContractReminderMessage); VerifyAll(); }
public void SendAsBinaryXmlMessageAsync_SendsMessage() { // Arrange Message actual = null; var sender = Mock.Of <IMessageSender>(); Mock.Get(sender) .Setup(p => p.SendAsync(It.IsAny <Message>())) .Returns(Task.CompletedTask) .Callback((Message msg) => { actual = msg; }); ContractReminderMessage reminder = CreateContractReminderMessage(); var properties = CreateMessageProperties(); ServiceBusMessagingService sbMessagingService = new ServiceBusMessagingService(sender); // Act Func <Task> act = async() => await sbMessagingService.SendAsBinaryXmlMessageAsync(reminder, properties); // Assert act.Should().NotThrow(); actual.UserProperties["messageType"].Should().Be(TestMessageType); Mock.Get(sender).VerifyAll(); }