public async Task GetActorAsync_GivenActorId_ReturnsActor()
    {
        // Arrange
        await using var host = await SubDomainIntegrationTestHost.InitializeAsync().ConfigureAwait(false);

        var scope = host.BeginScope();

        var container = scope.GetInstance <IActorRepositoryContainer>();
        var target    = new ActorRepository(container);

        var actorId    = Guid.NewGuid();
        var externalId = Guid.NewGuid();

        var actor = new Actor(new ActorId(actorId), new ExternalActorId(externalId));
        await target.AddOrUpdateAsync(actor).ConfigureAwait(false);

        // Act
        var actual = await target
                     .GetActorAsync(new ActorId(actorId))
                     .ConfigureAwait(false);

        // Assert
        Assert.NotNull(actual);
        Assert.Equal(actorId, Guid.Parse(actual !.Id.Value));
        Assert.Equal(externalId, actual.ExternalId.Value);
    }
        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);
        }
    public async Task DeleteAsync_NoActor_DoesNothing()
    {
        // Arrange
        await using var host = await SubDomainIntegrationTestHost.InitializeAsync().ConfigureAwait(false);

        var scope = host.BeginScope();

        var container = scope.GetInstance <IActorRepositoryContainer>();
        var target    = new ActorRepository(container);

        var actorId    = Guid.NewGuid();
        var externalId = Guid.NewGuid();

        var actor = new Actor(new ActorId(actorId), new ExternalActorId(externalId));

        // Act + Assert
        await target.DeleteAsync(actor).ConfigureAwait(false);
    }
Exemple #4
0
        public async Task SaveAsync_IdempotencySkip_CannotReadBack()
        {
            // Arrange
            await using var host = await SubDomainIntegrationTestHost.InitializeAsync().ConfigureAwait(false);

            var scope = host.BeginScope();

            var dataAvailableNotificationRepository = scope.GetInstance <IDataAvailableNotificationRepository>();

            var recipient     = new LegacyActorId(new MockedGln());
            var notifications = CreateInfinite(recipient, 1)
                                .Take(1)
                                .ToList();

            // Act
            await dataAvailableNotificationRepository
            .SaveAsync(new CabinetKey(notifications[0]), new[] { notifications[0], notifications[0] })
            .ConfigureAwait(false);

            var reader = await dataAvailableNotificationRepository
                         .GetNextUnacknowledgedAsync(recipient, DomainOrigin.Charges)
                         .ConfigureAwait(false);

            // Assert
            Assert.NotNull(reader);

            var items = await reader !
                        .ReadToEndAsync()
                        .ConfigureAwait(false);

            Assert.Single(items);

            for (var i = 0; i < items.Count; i++)
            {
                Assert.Equal(notifications[i].NotificationId, items[i].NotificationId);
                Assert.Equal(notifications[i].Recipient, items[i].Recipient);
                Assert.Equal(notifications[i].Origin, items[i].Origin);
                Assert.Equal(notifications[i].ContentType, items[i].ContentType);
                Assert.Equal(notifications[i].SupportsBundling, items[i].SupportsBundling);
                Assert.Equal(notifications[i].Weight, items[i].Weight);
                Assert.Equal(notifications[i].SequenceNumber, items[i].SequenceNumber);
            }
        }
    public async Task GetActorAsync_NoExternalActorId_ReturnsNull()
    {
        // Arrange
        await using var host = await SubDomainIntegrationTestHost.InitializeAsync().ConfigureAwait(false);

        var scope = host.BeginScope();

        var container = scope.GetInstance <IActorRepositoryContainer>();
        var target    = new ActorRepository(container);

        var externalId = Guid.NewGuid();

        // Act
        var actual = await target
                     .GetActorAsync(new ExternalActorId(externalId))
                     .ConfigureAwait(false);

        // Assert
        Assert.Null(actual);
    }
Exemple #6
0
        public async Task SaveAsync_IdempotencyFailed_ThrowsException()
        {
            // Arrange
            await using var host = await SubDomainIntegrationTestHost.InitializeAsync().ConfigureAwait(false);

            var scope = host.BeginScope();

            var dataAvailableNotificationRepository = scope.GetInstance <IDataAvailableNotificationRepository>();

            var recipient = new LegacyActorId(new MockedGln());

            var notification1 = new DataAvailableNotification(
                new Uuid(Guid.NewGuid()),
                recipient,
                new ContentType("a"),
                DomainOrigin.Charges,
                new SupportsBundling(true),
                new Weight(1),
                new SequenceNumber(1),
                new DocumentType("RSM??"));
            var notification2 = new DataAvailableNotification(
                notification1.NotificationId,
                notification1.Recipient,
                new ContentType("b"),
                notification1.Origin,
                notification1.SupportsBundling,
                notification1.Weight,
                new SequenceNumber(2),
                new DocumentType("RSM??"));

            var notifications = new[] { notification1, notification2 };

            // Act + Assert
            await Assert
            .ThrowsAsync <ValidationException>(
                () => dataAvailableNotificationRepository.SaveAsync(new CabinetKey(notifications[0]), notifications))
            .ConfigureAwait(false);
        }
Exemple #7
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);
        }