public async Task Validate_Recipient_ValidatesProperty(string value, bool isValid) { // Arrange const string propertyName = "Notifications[0]." + nameof(DataAvailableNotificationDto.Recipient); var target = new InsertDataAvailableNotificationsCommandRuleSet(); var dto = new DataAvailableNotificationDto( ValidUuid, value, ValidContentType, ValidOrigin, false, ValidWeight, ValidSequenceNumber, ValidDocumentType); // Act var items = new[] { dto }; var result = await target.ValidateAsync(new InsertDataAvailableNotificationsCommand(items)).ConfigureAwait(false); // Assert if (isValid) { Assert.True(result.IsValid); Assert.DoesNotContain(propertyName, result.Errors.Select(x => x.PropertyName)); } else { Assert.False(result.IsValid); Assert.Contains(propertyName, result.Errors.Select(x => x.PropertyName)); } }
public Task SendAsync(string correlationId, DataAvailableNotificationDto dataAvailableNotificationDto) { ArgumentNullException.ThrowIfNull(correlationId, nameof(correlationId)); ArgumentNullException.ThrowIfNull(dataAvailableNotificationDto, nameof(dataAvailableNotificationDto)); var sender = _messageBusFactory.GetSenderClient(_messageHubConfig.DataAvailableQueue); #pragma warning disable CS0618 var recipient = dataAvailableNotificationDto.Recipient is LegacyActorIdDto legacyActorIdDto #pragma warning restore CS0618 ? legacyActorIdDto.LegacyValue : dataAvailableNotificationDto.Recipient.Value.ToString(); var contract = new DataAvailableNotificationContract { UUID = dataAvailableNotificationDto.Uuid.ToString(), Recipient = recipient, MessageType = dataAvailableNotificationDto.MessageType.Value, Origin = dataAvailableNotificationDto.Origin.ToString(), SupportsBundling = dataAvailableNotificationDto.SupportsBundling, RelativeWeight = dataAvailableNotificationDto.RelativeWeight, DocumentType = dataAvailableNotificationDto.DocumentType }; var messageId = Guid.NewGuid().ToString(); var message = new ServiceBusMessage(new BinaryData(contract.ToByteArray())) { MessageId = messageId, PartitionKey = dataAvailableNotificationDto.Origin.ToString() } .AddDataAvailableIntegrationEvents(correlationId); return(sender.PublishMessageAsync <ServiceBusMessage>(message)); }
public async Task SendAsync_NullCorrelationId_ThrowsException() { // Arrange var serviceBusSenderMock = new Mock <ServiceBusSender>(); var serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>(); await using var mockedServiceBusClient = new MockedServiceBusClient( string.Empty, 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 config = new MessageHubConfig("fake_value", "fake_value"); var target = new DataAvailableNotificationSender(messageBusFactory, config); var dataAvailable = new DataAvailableNotificationDto( Guid.Parse("F9A5115D-44EB-4AD4-BC7E-E8E8A0BC425E"), new ActorIdDto(Guid.NewGuid()), new MessageTypeDto("fake_value"), "RSM??", DomainOrigin.TimeSeries, true, 1); // Act + Assert await Assert .ThrowsAsync <ArgumentNullException>(() => target.SendAsync(null !, dataAvailable)) .ConfigureAwait(false); }
private static Expression <Func <CabinetKey, bool> > ExpectedCabinetKey(DataAvailableNotificationDto dto) { return(cabinetKey => cabinetKey == new CabinetKey( new LegacyActorId(new GlobalLocationNumber(dto.Recipient)), Enum.Parse <DomainOrigin>(dto.Origin, true), new ContentType(dto.ContentType))); }
public async Task InsertDataAvailableNotificationsCommand_WithData_CanBePeekedBack() { // Arrange var recipientGln = new MockedGln(); var bundleId = Guid.NewGuid().ToString(); await using var host = await MarketOperatorIntegrationTestHost .InitializeAsync() .ConfigureAwait(false); await using var scope = host.BeginScope(); var mediator = scope.GetInstance <IMediator>(); var dataAvailableNotification = new DataAvailableNotificationDto( Guid.NewGuid().ToString(), recipientGln, "timeseries", "timeseries", false, 1, 1, "RSM??"); var command = new InsertDataAvailableNotificationsCommand(new[] { dataAvailableNotification }); // Act await mediator.Send(command).ConfigureAwait(false); // Assert var peekResponse = await mediator.Send(new PeekCommand(recipientGln, bundleId)).ConfigureAwait(false); Assert.NotNull(peekResponse); Assert.True(peekResponse.HasContent); }
public async Task InsertDataAvailableNotificationsCommand_InvalidCommand_ThrowsException() { // Arrange const string blankValue = " "; await using var host = await MarketOperatorIntegrationTestHost .InitializeAsync() .ConfigureAwait(false); await using var scope = host.BeginScope(); var mediator = scope.GetInstance <IMediator>(); var dataAvailableNotification = new DataAvailableNotificationDto( blankValue, blankValue, blankValue, blankValue, false, 1, 1, "RSM??"); var command = new InsertDataAvailableNotificationsCommand(new[] { dataAvailableNotification }); // Act + Assert await Assert .ThrowsAsync <ValidationException>(() => mediator.Send(command)) .ConfigureAwait(false); }
public async Task InsertDataAvailableNotificationsCommand_PeekInsertDequeueSequence_CanBePeekedBack() { // Arrange var recipientGln = new MockedGln(); var bundleIdA = Guid.NewGuid().ToString(); var bundleIdB = Guid.NewGuid().ToString(); await using var host = await MarketOperatorIntegrationTestHost .InitializeAsync() .ConfigureAwait(false); await using var scope = host.BeginScope(); var mediator = scope.GetInstance <IMediator>(); var dataAvailableNotificationA = new DataAvailableNotificationDto( Guid.NewGuid().ToString(), recipientGln, "MeteringPoints", "MeteringPoints", true, 1, 1, "RSM??"); var dataAvailableNotificationB = new DataAvailableNotificationDto( Guid.NewGuid().ToString(), dataAvailableNotificationA.Recipient, dataAvailableNotificationA.ContentType, dataAvailableNotificationA.Origin, dataAvailableNotificationA.SupportsBundling, dataAvailableNotificationA.Weight, 2, dataAvailableNotificationA.DocumentType); await mediator .Send(new InsertDataAvailableNotificationsCommand(new[] { dataAvailableNotificationA })) .ConfigureAwait(false); // Act await mediator.Send(new PeekCommand(recipientGln, bundleIdA)).ConfigureAwait(false); await mediator .Send(new InsertDataAvailableNotificationsCommand(new[] { dataAvailableNotificationB })) .ConfigureAwait(false); await mediator.Send(new DequeueCommand(recipientGln, bundleIdA)).ConfigureAwait(false); // Assert var peekResponse = await mediator .Send(new PeekCommand(recipientGln, bundleIdB)) .ConfigureAwait(false); Assert.True(peekResponse.HasContent); }
private static async Task AddNotificationAsync(DataAvailableNotificationDto dataAvailableDto) { await using var host = await SubDomainIntegrationTestHost .InitializeAsync() .ConfigureAwait(false); await using var scope = host.BeginScope(); var mediator = scope.GetInstance <IMediator>(); var command = new InsertDataAvailableNotificationsCommand(new[] { dataAvailableDto }); await mediator.Send(command).ConfigureAwait(false); }
private static async Task AddAggregationsNotificationAsync(string recipientGln) { var dataAvailableUuid = Guid.NewGuid(); var dataAvailableCommand = new DataAvailableNotificationDto( dataAvailableUuid.ToString(), recipientGln, "aggregations", "Aggregations", false, 1, 1, "RSM??"); await AddNotificationAsync(dataAvailableCommand).ConfigureAwait(false); }
private static DataAvailableNotification Map(DataAvailableNotificationDto notificationDto) { var recipient = Guid.TryParse(notificationDto.Recipient, out var actorId) ? new ActorId(actorId) : new LegacyActorId(new GlobalLocationNumber(notificationDto.Recipient)); return(new DataAvailableNotification( new Uuid(notificationDto.Uuid), recipient, new ContentType(notificationDto.ContentType), Enum.Parse <DomainOrigin>(notificationDto.Origin, true), new SupportsBundling(notificationDto.SupportsBundling), new Weight(notificationDto.Weight), new SequenceNumber(notificationDto.SequenceNumber), new DocumentType(notificationDto.DocumentType))); }
public async Task SendAsync_ValidInput_AddsCorrectIntegrationEvents() { // Arrange var serviceBusSenderMock = new Mock <ServiceBusSender>(); var serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>(); const string dataAvailableQueue = "sbq-dataavailable"; await using var mockedServiceBusClient = new MockedServiceBusClient( dataAvailableQueue, 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 config = new MessageHubConfig(dataAvailableQueue, "fake_value"); var target = new DataAvailableNotificationSender(messageBusFactory, config); var dataAvailable = new DataAvailableNotificationDto( Guid.Parse("F9A5115D-44EB-4AD4-BC7E-E8E8A0BC425E"), new ActorIdDto(Guid.NewGuid()), new MessageTypeDto("fake_value"), "RSM??", DomainOrigin.TimeSeries, true, 1); // Act await target.SendAsync("F9A5115D-44EB-4AD4-BC7E-E8E8A0BC425E", dataAvailable).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); }
private static async Task <Guid> AddBundlingNotificationAsync(string recipientGln, string origin, bool supportsBundling) { var dataAvailableUuid = Guid.NewGuid(); var dataAvailableCommand = new DataAvailableNotificationDto( dataAvailableUuid.ToString(), recipientGln, "content_type", origin, supportsBundling, 1, 1, "RSM??"); await AddNotificationAsync(dataAvailableCommand).ConfigureAwait(false); return(dataAvailableUuid); }
private static async Task <Guid> AddChargesNotificationAsync(string recipientGln) { var dataAvailableUuid = Guid.NewGuid(); var dataAvailableCommand = new DataAvailableNotificationDto( dataAvailableUuid.ToString(), recipientGln, "charges", "Charges", false, 1, 1, "RSM??"); await AddNotificationAsync(dataAvailableCommand).ConfigureAwait(false); return(dataAvailableUuid); }
private static async Task AddDataAvailableNotificationAsync(string recipientGln) { var dataAvailableUuid = Guid.NewGuid().ToString(); var dataAvailableNotification = new DataAvailableNotificationDto( dataAvailableUuid, recipientGln, "timeseries", "timeseries", false, 1, 1, "RSM??"); await using var host = await SubDomainIntegrationTestHost .InitializeAsync() .ConfigureAwait(false); await using var scope = host.BeginScope(); var mediator = scope.GetInstance <IMediator>(); var command = new InsertDataAvailableNotificationsCommand(new[] { dataAvailableNotification }); await mediator.Send(command).ConfigureAwait(false); }
private static bool ExpectedNotification(DataAvailableNotification notification, DataAvailableNotificationDto dto) { return (notification.NotificationId == new Uuid(dto.Uuid) && notification.Recipient.Value == dto.Recipient && notification.Origin.ToString() == dto.Origin && notification.ContentType.Value == dto.ContentType && notification.Weight.Value == dto.Weight && notification.SupportsBundling.Value == dto.SupportsBundling && notification.SequenceNumber.Value == dto.SequenceNumber); }
ExpectedNotification(DataAvailableNotificationDto dataAvailableNotification) { return(notifications => ExpectedNotification(notifications.Single(), dataAvailableNotification)); }