public async Task SendAsync_ValidInputForDomain_SendsMessage(DomainOrigin domainOrigin, string queueName) { // Arrange var serviceBusSenderMock = new Mock <ServiceBusSender>(); var serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>(); await using var mockedServiceBusClient = new MockedServiceBusClient( queueName, string.Empty, serviceBusSenderMock.Object, serviceBusSessionReceiverMock.Object); var serviceBusClientFactory = new Mock <IServiceBusClientFactory>(); serviceBusClientFactory .Setup(x => x.Create()) .Returns(mockedServiceBusClient); await using var messageBusFactory = new AzureServiceBusFactory(serviceBusClientFactory.Object); var target = new DequeueNotificationSender(messageBusFactory, _testConfig); var dataAvailable = new DequeueNotificationDto( "fake_value", new ActorIdDto(Guid.NewGuid())); // Act await target.SendAsync("fake_value", dataAvailable, domainOrigin).ConfigureAwait(false); // Assert serviceBusSenderMock.Verify(x => x.SendMessageAsync(It.IsAny <ServiceBusMessage>(), default), Times.Once); }
public byte[] Parse(DequeueNotificationDto dequeueNotificationDto) { ArgumentNullException.ThrowIfNull(dequeueNotificationDto, nameof(dequeueNotificationDto)); #pragma warning disable CS0618 // Type or member is obsolete var marketOperator = dequeueNotificationDto.MarketOperator is LegacyActorIdDto legacyActorIdDto #pragma warning restore CS0618 // Type or member is obsolete ? legacyActorIdDto.LegacyValue : dequeueNotificationDto.MarketOperator.Value.ToString(); var message = new DequeueContract { DataAvailableNotificationReferenceId = dequeueNotificationDto.DataAvailableNotificationReferenceId, MarketOperator = marketOperator }; return(message.ToByteArray()); }
public async Task SendAsync_ValidInput_AddsCorrectIntegrationEvents() { // Arrange var serviceBusSenderMock = new Mock <ServiceBusSender>(); var serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>(); var queueName = "sbq-TimeSeries-dequeue"; await using var mockedServiceBusClient = new MockedServiceBusClient( queueName, string.Empty, serviceBusSenderMock.Object, serviceBusSessionReceiverMock.Object); var serviceBusClientFactory = new Mock <IServiceBusClientFactory>(); serviceBusClientFactory .Setup(x => x.Create()) .Returns(mockedServiceBusClient); await using var messageBusFactory = new AzureServiceBusFactory(serviceBusClientFactory.Object); var target = new DequeueNotificationSender(messageBusFactory, _testConfig); var dataAvailable = new DequeueNotificationDto( "fake_value", new ActorIdDto(Guid.NewGuid())); // Act await target.SendAsync("fake_value", dataAvailable, DomainOrigin.TimeSeries).ConfigureAwait(false); // Assert serviceBusSenderMock.Verify( x => x.SendMessageAsync( It.Is <ServiceBusMessage>( message => message.ApplicationProperties.ContainsKey("OperationTimestamp") && message.ApplicationProperties.ContainsKey("OperationCorrelationId") && message.ApplicationProperties.ContainsKey("MessageVersion") && message.ApplicationProperties.ContainsKey("MessageType") && message.ApplicationProperties.ContainsKey("EventIdentification")), default), Times.Once); }
public void Parse_ValidObject_Returns_Bytes() { // arrange var target = new DequeueNotificationParser(); var actorId = Guid.NewGuid(); var valid = new DequeueNotificationDto( "F8201E4D-8989-4B75-A2C2-1E163DA7660B", new ActorIdDto(actorId)); // act var actual = target.Parse(valid); // assert Assert.NotNull(actual); var dequeueNotificationDto = target.Parse(actual); Assert.Equal(actorId, dequeueNotificationDto.MarketOperator.Value); }
public void Parse_LegacyObject_Returns_Bytes() { // arrange var target = new DequeueNotificationParser(); var valid = new DequeueNotificationDto( "F8201E4D-8989-4B75-A2C2-1E163DA7660B", #pragma warning disable CS0618 // Type or member is obsolete new LegacyActorIdDto("test")); #pragma warning restore CS0618 // Type or member is obsolete // act var actual = target.Parse(valid); // assert Assert.NotNull(actual); var dequeueNotificationDto = target.Parse(actual); #pragma warning disable CS0618 // Type or member is obsolete Assert.Equal("test", ((LegacyActorIdDto)dequeueNotificationDto.MarketOperator).LegacyValue); #pragma warning restore CS0618 // Type or member is obsolete }
public Task SendAsync(string correlationId, DequeueNotificationDto dequeueNotificationDto, DomainOrigin domainOrigin) { ArgumentNullException.ThrowIfNull(dequeueNotificationDto, nameof(dequeueNotificationDto)); var queueName = GetQueueName(domainOrigin); var serviceBusSender = _messageBusFactory.GetSenderClient(queueName); #pragma warning disable CS0618 var marketOperator = dequeueNotificationDto.MarketOperator is LegacyActorIdDto legacyActorIdDto #pragma warning restore CS0618 ? legacyActorIdDto.LegacyValue : dequeueNotificationDto.MarketOperator.Value.ToString(); var contract = new DequeueContract { DataAvailableNotificationReferenceId = dequeueNotificationDto.DataAvailableNotificationReferenceId, MarketOperator = marketOperator }; var dequeueMessage = new ServiceBusMessage(new BinaryData(contract.ToByteArray())) .AddDequeueIntegrationEvents(correlationId); return(serviceBusSender.PublishMessageAsync <ServiceBusMessage>(dequeueMessage)); }