Ejemplo n.º 1
0
        public async Task ValidateRedisPendingAsync()
        {
            var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync("localhost");

            var publisher     = new RedisStreamPublisher <SampleMessage, CreateEvent>(connectionMultiplexer);
            var subscriberA   = new RedisStreamSubscriber <SampleMessage, CreateEvent>(connectionMultiplexer, StreamPosition.NewMessages);
            var subscriberB   = new RedisStreamSubscriber <SampleMessage, CreateEvent>(connectionMultiplexer, StreamPosition.NewMessages);
            var sampleMessage = new SampleMessage();
            var original      = await publisher.Database.StreamInfoAsync(publisher.StreamKey);

            _ = await publisher.PublishAsync(sampleMessage);

            var result = await publisher.Database.StreamInfoAsync(publisher.StreamKey);

            Assert.AreEqual(original.Length + 1, result.Length);
            var subscribedMessages = await subscriberA.GetMessagesAsync();

            Assert.AreEqual(1, subscribedMessages.Count());
            subscribedMessages = await subscriberB.GetPendingMessagesAsync();

            Assert.AreNotEqual(0, subscribedMessages.Count());
            var count = 0L;

            foreach (var(Id, Entity) in subscribedMessages)
            {
                count += await subscriberB.AcknowledgeMessageAsync(Id);
            }
            Assert.AreNotEqual(0, count);
        }
Ejemplo n.º 2
0
        public async Task ValidateRedisMoqPublishAsync()
        {
            var moqConnection = new Mock <IConnectionMultiplexer>();
            var moqDatabase   = new Mock <IDatabase>();

            _ = moqConnection.Setup(t => t.GetDatabase(-1, null)).Returns(moqDatabase.Object);
            var publisher = new RedisStreamPublisher <SampleMessage, CreateEvent, Guid>(moqConnection.Object);
            var msg       = new SampleMessage();

            _ = await publisher.PublishAsync(msg);

            moqDatabase
            .Verify(t => t.StreamAddAsync(publisher.StreamKey, It.Is <RedisValue>(x => x.StartsWith(msg.Id.ToString())), It.IsAny <RedisValue>(), null, null, false, CommandFlags.None), Times.Once);
        }
Ejemplo n.º 3
0
        public async Task ValidateRedisPublishAsync()
        {
            var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync("localhost");

            var publisher     = new RedisStreamPublisher <SampleMessage, CreateEvent>(connectionMultiplexer);
            var subscriber    = new RedisStreamSubscriber <SampleMessage, CreateEvent>(connectionMultiplexer, StreamPosition.NewMessages);
            var sampleMessage = new SampleMessage();
            var original      = await publisher.Database.StreamInfoAsync(publisher.StreamKey);

            _ = await publisher.PublishAsync(sampleMessage);

            var result = await publisher.Database.StreamInfoAsync(publisher.StreamKey);

            Assert.AreEqual(original.Length + 1, result.Length);
            var subscribedMessages = await subscriber.GetMessagesAsync();

            var(Id, Entity) = subscribedMessages.First();
            Assert.AreEqual(sampleMessage.Name, Entity.Name);
            var count = await subscriber.AcknowledgeMessageAsync(Id);

            Assert.AreEqual(1, count);
        }