public async Task Validate_Recipient_ValidatesProperty(string value, bool isValid)
        {
            // Arrange
            const string propertyName = nameof(DequeueCommand.MarketOperator);

            var target  = new DequeueCommandRuleSet();
            var command = new DequeueCommand(
                value,
                ValidUuid);

            // Act
            var result = await target.ValidateAsync(command).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));
            }
        }
예제 #2
0
        public async Task Dequeue_HasData_ReturnsIsDequeued()
        {
            // Arrange
            var recipientGln = new MockedGln();
            var bundleId     = Guid.NewGuid().ToString();

            await AddDataAvailableNotificationAsync(recipientGln).ConfigureAwait(false);

            await using var host = await MarketOperatorIntegrationTestHost
                                   .InitializeAsync()
                                   .ConfigureAwait(false);

            await using var scope = host.BeginScope();
            var mediator = scope.GetInstance <IMediator>();

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

            var bundleUuid = await ReadBundleIdAsync(peekResponse).ConfigureAwait(false);

            var dequeueCommand = new DequeueCommand(recipientGln, bundleUuid);

            // Act
            var response = await mediator.Send(dequeueCommand).ConfigureAwait(false);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.IsDequeued);
        }
        public async Task Handle_WithoutData_ReturnsFalse()
        {
            // Arrange
            var request = new DequeueCommand("fake_value", "E3A22C4F-BA71-4BC0-9571-85F7F906D20D");

            var warehouseDomainServiceMock = new Mock <IMarketOperatorDataDomainService>();

            warehouseDomainServiceMock.Setup(x => x.CanAcknowledgeAsync(
                                                 It.Is <LegacyActorId>(r => string.Equals(r.Value, request.MarketOperator, StringComparison.OrdinalIgnoreCase)),
                                                 It.Is <Uuid>(id => string.Equals(id.ToString(), request.BundleId, StringComparison.OrdinalIgnoreCase))))
            .ReturnsAsync((false, null));
            var dequeueNotificationSenderMock = new Mock <IDequeueNotificationSender>();
            var target = new DequeueHandler(
                warehouseDomainServiceMock.Object,
                dequeueNotificationSenderMock.Object,
                new Mock <ILogger>().Object,
                new Mock <ICorrelationContext>().Object);

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

            // Assert
            Assert.NotNull(response);
            Assert.False(response.IsDequeued);
        }
예제 #4
0
        public async Task Dequeue_InvalidCommand_ThrowsException()
        {
            // Arrange
            await using var host = await MarketOperatorIntegrationTestHost
                                   .InitializeAsync()
                                   .ConfigureAwait(false);

            await using var scope = host.BeginScope();
            var mediator = scope.GetInstance <IMediator>();

            var dequeueCommand = new DequeueCommand("  ", "  ");

            // Act + Assert
            await Assert.ThrowsAsync <ValidationException>(() => mediator.Send(dequeueCommand)).ConfigureAwait(false);
        }
예제 #5
0
        public Task <HttpResponseData> RunAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete")]
            HttpRequestData request)
        {
            return(request.ProcessAsync(async() =>
            {
                var command = new DequeueCommand(_operatorIdentity.ActorId, request.Url.GetQueryValue(Constants.BundleIdQueryName));
                var response = await _mediator.Send(command).ConfigureAwait(false);

                var httpResponse = response.IsDequeued
                    ? request.CreateResponse(HttpStatusCode.OK)
                    : request.CreateResponse(HttpStatusCode.NotFound);

                return httpResponse;
            }));
        }
        public async Task Handle_WithData_ReturnsTrue()
        {
            // Arrange
            var request           = new DequeueCommand("fake_value", "9FB4753A-0E2C-4F42-BA10-D38128DDA877");
            var bundleContentMock = new Mock <IBundleContent>();
            var bundle            = new Bundle(
                new Uuid(Guid.NewGuid()),
                new LegacyActorId(new GlobalLocationNumber("fake_value")),
                DomainOrigin.TimeSeries,
                new ContentType("fake_value"),
                Array.Empty <Uuid>(),
                bundleContentMock.Object,
                Enumerable.Empty <string>());

            var warehouseDomainServiceMock = new Mock <IMarketOperatorDataDomainService>();

            warehouseDomainServiceMock.Setup(x => x.CanAcknowledgeAsync(
                                                 It.Is <LegacyActorId>(r => string.Equals(r.Value, request.MarketOperator, StringComparison.OrdinalIgnoreCase)),
                                                 It.Is <Uuid>(id => string.Equals(id.ToString(), request.BundleId, StringComparison.OrdinalIgnoreCase))))
            .ReturnsAsync((true, bundle));

            var dequeueNotificationSenderMock = new Mock <IDequeueNotificationSender>();

            dequeueNotificationSenderMock.Setup(x => x.SendAsync(
                                                    bundle.ProcessId.ToString(),
                                                    It.IsAny <DequeueNotificationDto>(),
                                                    It.IsAny <MessageHub.Model.Model.DomainOrigin>())).Returns(Task.CompletedTask);

            var target = new DequeueHandler(
                warehouseDomainServiceMock.Object,
                dequeueNotificationSenderMock.Object,
                new Mock <ILogger>().Object,
                new Mock <ICorrelationContext>().Object);

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

            // Assert
            Assert.NotNull(response);
            Assert.True(response.IsDequeued);
            dequeueNotificationSenderMock.Verify(
                x => x.SendAsync(
                    bundle.ProcessId.ToString(),
                    It.IsAny <DequeueNotificationDto>(),
                    It.IsAny <MessageHub.Model.Model.DomainOrigin>()),
                Times.Once);
        }
예제 #7
0
        public async Task Dequeue_NoData_ReturnsNotDequeued()
        {
            // Arrange
            var recipientGln = new MockedGln();
            var bundleUuid   = Guid.NewGuid().ToString();

            await using var host = await MarketOperatorIntegrationTestHost
                                   .InitializeAsync()
                                   .ConfigureAwait(false);

            await using var scope = host.BeginScope();
            var mediator = scope.GetInstance <IMediator>();

            var dequeueCommand = new DequeueCommand(recipientGln, bundleUuid);

            // Act
            var response = await mediator.Send(dequeueCommand).ConfigureAwait(false);

            // Assert
            Assert.NotNull(response);
            Assert.False(response.IsDequeued);
        }