public IPublisherMessage Build()
        {
            var message = new PublisherMessage(Publisher, _message, _serializer, _routing, _correlationId,
                                               _cancellationToken);

            return(message);
        }
        public async Task GivenMessage_WhenPublish_ShouldPublish()
        {
            const string body              = "test_message";
            const string correlationId     = "correlationId";
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            publisherMock
            .Setup(x => x.PublishAsync(It.IsAny <PublisherMessage>(), cancellationToken))
            .Verifiable();

            var message = new PublisherMessage(
                publisherMock.Object,
                body,
                serializerMock.Object,
                routingMock.Object,
                correlationId,
                cancellationToken);

            await message.PublishAsync(cancellationToken);

            message.Should().NotBeNull();
            message.GetHeaders().Should().ContainKey("PublishedAt");
            message.GetHeaders()["PublishedAt"].ToString().Should().MatchRegex(@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}");
            publisherMock.VerifyAll();
        }
        public void GivenMessage_WhenInstantiate_ShouldAddDefaultHeader()
        {
            const string body           = "";
            const string correlationId  = "correlationId";
            const string exchange       = "exchange";
            const string routingKey     = "routingKey";
            var          publisherMock  = new Mock <IPublisher>();
            var          serializerMock = new Mock <IPublisherSerializer>();
            var          routingMock    = new Mock <IRouting>();

            routingMock.SetupGet(x => x.ExchangeName)
            .Returns(exchange)
            .Verifiable();
            routingMock.SetupGet(x => x.RoutingKey)
            .Returns(routingKey)
            .Verifiable();
            var cancellationToken = new CancellationToken();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            var headers = message.GetHeaders();

            headers.Should().NotBeNull();
            headers.Should().Contain(nameof(IRouting.ExchangeName), exchange);
            headers.Should().Contain(nameof(IRouting.RoutingKey), routingKey);
            headers.Should().Contain("SerializerType", serializerMock.Object.GetType().FullName);
            headers.Should().ContainKey(nameof(message.CreatedAt));
        }
        private void UpdatePublisher()
        {
            _selectedPublisher.PublisherName = txtPublisherName.Text;
            _selectedPublisher.PhoneNumber   = txtPublisherPhoneNumber.Text;
            _selectedPublisher.EMail         = txtPublisherEmail.Text;
            _selectedPublisher.Address       = rtxtPublisherAddress.Text;

            _publisherManager.Update(_selectedPublisher);
            MessageBox.Show(PublisherMessage.UpdateMessage());
        }
        private void AddPublisher()
        {
            Publisher publisher = new Publisher();

            publisher.PublisherName = txtPublisherName.Text;
            publisher.PhoneNumber   = txtPublisherPhoneNumber.Text;
            publisher.EMail         = txtPublisherEmail.Text;
            publisher.Address       = rtxtPublisherAddress.Text;

            _publisherManager.Add(publisher);
            MessageBox.Show(PublisherMessage.AddMessage());
        }
        public void GivenMessage_ShouldInstantiate()
        {
            const string body              = "";
            const string correlationId     = "correlationId";
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            message.Should().NotBeNull();
            message.Routing.Should().Be(routingMock.Object);
            message.CancellationToken.Should().Be(cancellationToken);
            message.CorrelationId.Should().Be(correlationId);
            message.CreatedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(1));
        }
        public void GivenMessage_ShouldAddHeader()
        {
            const string body              = "";
            const string correlationId     = "correlationId";
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            message.AddHeader("NewHeader", "NewHeaderValue");

            var headers = message.GetHeaders();

            headers.Should().NotBeNull();
            headers.Should().Contain("NewHeader", "NewHeaderValue");
        }
Beispiel #8
0
 public IMessage CreateMessage(int currentLineNumber)
 {
     try
     {
         using (var ctx = new PublisherContext("DefaultConnection"))
         {
             var dbMessage = ctx.Messages.FirstOrDefault(m => m.Id == currentLineNumber % ctx.Messages.Count());
             var result    = new PublisherMessage()
             {
                 Id           = dbMessage.Id,
                 Content      = dbMessage.Content,
                 SendTime     = DateTime.Now,
                 DatabaseHash = currentLineNumber
             };
             return(result);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public void GivenMessage_WhenSerialize_ShouldSerialize()
        {
            const string body              = "test_message";
            const string correlationId     = "correlationId";
            var          resultBody        = Encoding.UTF8.GetBytes(body);
            var          publisherMock     = new Mock <IPublisher>();
            var          serializerMock    = new Mock <IPublisherSerializer>();
            var          routingMock       = new Mock <IRouting>();
            var          cancellationToken = new CancellationToken();

            serializerMock.Setup(x => x.Serialize(body))
            .Returns(resultBody)
            .Verifiable();

            var message = new PublisherMessage(publisherMock.Object, body, serializerMock.Object, routingMock.Object,
                                               correlationId,
                                               cancellationToken);

            var result = message.Serialize();

            message.Should().NotBeNull();
            Encoding.UTF8.GetString(result.ToArray()).Should().Be(body);
            serializerMock.VerifyAll();
        }
 private void DeletePublisher()
 {
     _publisherManager.Delete(_selectedPublisher);
     MessageBox.Show(PublisherMessage.DeleteMessage());
 }