public async Task SimpleConnect()
        {
            var stream     = new MemoryStream();
            var respWriter = new RespWriter(stream);
            var hi         = new SimpleStringMessage("HI {\"v\":\"1\"}");
            var ok         = new SimpleStringMessage("OK");
            await respWriter.WriteAsync(hi);

            await respWriter.WriteAsync(ok);

            stream.Position = 0;
            var transport = new Mock <IConnectionTransport>();

            transport
            .Setup(t => t.GetStreamAsync())
            .Returns(Task.FromResult((Stream)stream));
            var transportFactory = new Mock <IConnectionTransportFactory>();

            transportFactory
            .Setup(f => f.CreateTransport())
            .Returns(transport.Object);
            var configuration = new Mock <IConnectionConfiguration>();

            configuration
            .Setup(c => c.TransportFactory)
            .Returns(transportFactory.Object);
            configuration
            .Setup(c => c.Identity)
            .Returns(WorkerConnectionIdentity.GenerateNew);
            var connection = new FaktoryConnection(configuration.Object);
            await connection.ConnectAsync();
        }
Esempio n. 2
0
        private static async Task AssertWrite(string rawMessage, RespMessage message)
        {
            var stream     = new MemoryStream();
            var respWriter = new RespWriter(stream);
            await respWriter.WriteAsync(message);

            stream.Position = 0;
            var streamReader = new StreamReader(stream);
            var actual       = await streamReader.ReadToEndAsync();

            Assert.That(actual, Is.EqualTo(rawMessage));
        }
Esempio n. 3
0
        public async Task Should_write_normal_messages(string name, string rawMessage, RespMessage message)
        {
            await AssertWrite(rawMessage, message);

            var stream     = new MemoryStream();
            var respWriter = new RespWriter(stream);
            await respWriter.WriteAsync(message);

            stream.Position = 0;
            var streamReader = new StreamReader(stream);
            var actual       = await streamReader.ReadToEndAsync();

            Assert.That(actual, Is.EqualTo(rawMessage));
        }