Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
        private async Task ProcessGroupAsync(string key, IEnumerable <DataAvailableNotificationDto> group)
        {
            var items = group.ToList();
            var retry = 0;

            while (true)
            {
                try
                {
                    var request = new InsertDataAvailableNotificationsCommand(items);
                    await _mediator.Send(request).ConfigureAwait(false);

                    return;
                }
                catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.TooManyRequests)
                {
                    if (++retry == 3)
                    {
                        throw;
                    }

                    _logger.LogWarning("{0} will be retried ({1} messages).\nReason:\nTMR", key, items.Count);
                    await Task.Delay(1500).ConfigureAwait(false);
                }
            }
        }
        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);
        }
Esempio n. 5
0
        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);
        }
        public async Task Handle_WithNotifications_DataIsSaved()
        {
            // Arrangem
            var repository = new Mock <IDataAvailableNotificationRepository>();
            var target     = new InsertDataAvailableNotificationsCommandHandler(repository.Object);

            const string recipient = "7495563456235";
            const string origin    = "TimeSeries";

            var dataAvailableNotifications = new[]
            {
                new DataAvailableNotificationDto(
                    "E8E875C0-250D-4B82-9357-4CE26E0E7A1E",
                    recipient,
                    "fake_value_1",
                    origin,
                    true,
                    1,
                    1,
                    "RSM??"),
                new DataAvailableNotificationDto(
                    "70469BE2-EFA3-4CBA-ABAF-AAE573BF057E",
                    recipient,
                    "fake_value_2",
                    origin,
                    true,
                    2,
                    2,
                    "RSM??"),
                new DataAvailableNotificationDto(
                    "F8FC4D49-5245-4924-80D3-F1FB81FA3903",
                    recipient,
                    "fake_value_3",
                    origin,
                    false,
                    3,
                    3,
                    "RSM??"),
            };

            var request = new InsertDataAvailableNotificationsCommand(dataAvailableNotifications);

            // Act
            await target.Handle(request, CancellationToken.None).ConfigureAwait(false);

            // Assert
            repository.Verify(
                x => x.SaveAsync(
                    It.Is(ExpectedCabinetKey(dataAvailableNotifications[0])),
                    It.Is(ExpectedNotification(dataAvailableNotifications[0]))),
                Times.Once);

            repository.Verify(
                x => x.SaveAsync(
                    It.Is(ExpectedCabinetKey(dataAvailableNotifications[1])),
                    It.Is(ExpectedNotification(dataAvailableNotifications[1]))),
                Times.Once);

            repository.Verify(
                x => x.SaveAsync(
                    It.Is(ExpectedCabinetKey(dataAvailableNotifications[2])),
                    It.Is(ExpectedNotification(dataAvailableNotifications[2]))),
                Times.Once);
        }
Esempio n. 7
0
        public async Task InsertDataAvailableNotificationsCommand_PeekDequeuePeekSequence_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);

            var dataAvailableNotificationC = new DataAvailableNotificationDto(
                Guid.NewGuid().ToString(),
                dataAvailableNotificationA.Recipient,
                dataAvailableNotificationA.ContentType,
                dataAvailableNotificationA.Origin,
                dataAvailableNotificationA.SupportsBundling,
                dataAvailableNotificationA.Weight,
                3,
                dataAvailableNotificationA.DocumentType);

            var insert3 = new InsertDataAvailableNotificationsCommand(new[]
            {
                dataAvailableNotificationA,
                dataAvailableNotificationB,
                dataAvailableNotificationC
            });

            await mediator.Send(insert3).ConfigureAwait(false);

            await mediator.Send(new UpdateMaximumSequenceNumberCommand(3)).ConfigureAwait(false);

            // Act
            await mediator.Send(new PeekCommand(recipientGln, bundleIdA)).ConfigureAwait(false);

            await mediator.Send(new DequeueCommand(recipientGln, bundleIdA)).ConfigureAwait(false);

            var dataAvailableNotificationD = new DataAvailableNotificationDto(
                Guid.NewGuid().ToString(),
                dataAvailableNotificationA.Recipient,
                dataAvailableNotificationA.ContentType,
                dataAvailableNotificationA.Origin,
                dataAvailableNotificationA.SupportsBundling,
                dataAvailableNotificationA.Weight,
                4,
                dataAvailableNotificationA.DocumentType);

            var insert1 = new InsertDataAvailableNotificationsCommand(new[]
            {
                dataAvailableNotificationD
            });

            await mediator.Send(insert1).ConfigureAwait(false);

            await mediator.Send(new UpdateMaximumSequenceNumberCommand(4)).ConfigureAwait(false);

            var peekResponse = await mediator
                               .Send(new PeekCommand(recipientGln, bundleIdB))
                               .ConfigureAwait(false);

            // Assert
            Assert.True(peekResponse.HasContent);
        }