Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public async Task SendAsync_NullArgument_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 target = new DequeueNotificationSender(messageBusFactory, _testConfig);

            // Act + Assert
            await Assert
            .ThrowsAsync <ArgumentNullException>(() => target.SendAsync("fake_value", null !, DomainOrigin.TimeSeries))
            .ConfigureAwait(false);
        }
Пример #4
0
        public async Task SendAsync_NullNotification_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);

            // Act + Assert
            await Assert
            .ThrowsAsync <ArgumentNullException>(() => target.SendAsync("F9A5115D-44EB-4AD4-BC7E-E8E8A0BC425E", null !))
            .ConfigureAwait(false);
        }
        public async Task SendAsync_NullDto_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 DataBundleResponseSender(
                new ResponseBundleParser(),
                messageBusFactory,
                config);

            // Act + Assert
            await Assert
            .ThrowsAsync <ArgumentNullException>(() => target.SendAsync(null !))
            .ConfigureAwait(false);
        }
        public async Task SendAsync_ValidInput_AddsCorrectIntegrationEvents()
        {
            // Arrange
            var          serviceBusSenderMock          = new Mock <ServiceBusSender>();
            var          serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>();
            const string sbqTimeseriesReply            = "sbq-TimeSeries-reply";

            await using var mockedServiceBusClient = new MockedServiceBusClient(
                            sbqTimeseriesReply,
                            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", sbqTimeseriesReply);

            // ServiceBusMessage
            var target = new DataBundleResponseSender(
                new ResponseBundleParser(),
                messageBusFactory,
                config);

            var requestMock = new DataBundleRequestDto(
                Guid.NewGuid(),
                "A9D032EB-4AAC-44F3-BE1C-8584B8533875",
                "42D509CB-1D93-430D-A2D4-7DBB9AE56771",
                new MessageTypeDto("80BB9BB8-CDE8-4C77-BE76-FDC886FD75A3"));

            var response = requestMock.CreateResponse(new Uri("https://test.dk/test"));

            // Act
            await target.SendAsync(response).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 async Task Create_ReturnsServiceBusClientSessionReceiver()
        {
            // arrange
            var queueName            = "sbq-test";
            var replyQueue           = "sbq-test-reply";
            var serviceBusSenderMock = new Mock <ServiceBusSender>();
            var bytes = new DataBundleResponseContract
            {
                RequestId = "729AB33C-714D-4641-89FB-9F37C78F6F8A",
                Success   = new DataBundleResponseContract.Types.FileResource
                {
                    ContentUri = "http://localhost"
                }
            }.ToByteArray();

            var serviceBusReceivedMessage     = MockedServiceBusReceivedMessage.Create(bytes);
            var serviceBusSessionReceiverMock = new Mock <ServiceBusSessionReceiver>();

            serviceBusSessionReceiverMock
            .Setup(x => x.ReceiveMessageAsync(It.IsAny <TimeSpan>(), default))
            .ReturnsAsync(serviceBusReceivedMessage);

            await using var serviceBusClient = new MockedServiceBusClient(
                            queueName,
                            replyQueue,
                            serviceBusSenderMock.Object,
                            serviceBusSessionReceiverMock.Object);

            var serviceBusClientFactory = new Mock <IServiceBusClientFactory>();

            serviceBusClientFactory
            .Setup(x => x.Create())
            .Returns(serviceBusClient);

            await using var messageBusFactory = new AzureServiceBusFactory(serviceBusClientFactory.Object);

            // act
            var actualAdd = await messageBusFactory.GetSessionReceiverClientAsync(replyQueue, It.IsAny <string>()).ConfigureAwait(false);

            var returnMessage = await actualAdd.ReceiveMessageAsync <ServiceBusMessage>(It.IsAny <TimeSpan>()).ConfigureAwait(false);

            await actualAdd.DisposeAsync().ConfigureAwait(false);

            // assert
            Assert.NotNull(returnMessage);
            Assert.NotNull(actualAdd);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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 async Task SendAsync_ValidInput_SendsMessage()
        {
            // Arrange
            const string queueName                     = "sbq-MeteringPoints-reply";
            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 config = new MessageHubConfig("fake_value", queueName);

            var target = new DataBundleResponseSender(
                new ResponseBundleParser(),
                messageBusFactory,
                config);

            var requestMock = new DataBundleRequestDto(
                Guid.NewGuid(),
                "F3DE0389-AC26-4461-A11B-61077BF0CA32",
                "7E9D048D-F0D8-476D-8739-AAA83284C9C6",
                new MessageTypeDto("80BB9BB8-CDE8-4C77-BE76-FDC886FD75A3"));

            var response = requestMock.CreateResponse(new Uri("https://test.dk/test"));

            // Act
            await target.SendAsync(response).ConfigureAwait(false);

            // Assert
            serviceBusSenderMock.Verify(x => x.SendMessageAsync(It.IsAny <ServiceBusMessage>(), default), Times.Once);
        }