Esempio n. 1
0
        public void Constructor_AllArgs_CreateObject()
        {
            // arrange
            var client = new SocketClientStub {
                Protocol = new Mock <ISocketProtocol>().Object
            };

            // act
            Exception?exception = Record.Exception(() => new Session(client));

            // assert
            Assert.Null(exception);
        }
Esempio n. 2
0
        public async Task OpenSessionAsync_ValidSocket_OpenSocket()
        {
            // arrange
            var protocolMock = new Mock <ISocketProtocol>();
            var client       = new SocketClientStub()
            {
                Protocol = protocolMock.Object
            };
            var manager = new Session(client);

            // act
            await manager.OpenSessionAsync().ConfigureAwait(false);

            // assert
            Assert.Equal(1, client.GetCallCount(x => x.OpenAsync(default !)));
        public async Task Constructor_AllArgs_Construct()
        {
            // arrange
            ProcessAsync  a            = (_, _) => default;
            ISocketClient socketClient = new SocketClientStub()
            {
                IsClosed = false
            };

            // act
            await using var messagePipeline = new MessagePipeline(socketClient, a);

            // assert
            Assert.IsType <MessagePipeline>(messagePipeline);
        }
        public async Task Constructor_AllArgs_SubscribeToChanges()
        {
            // arrange
            var socketClient = new SocketClientStub {
                IsClosed = false
            };

            // act
            var protocol = new GraphQLWebSocketProtocol(socketClient);
            await protocol.InitializeAsync(CancellationToken.None);

            await protocol.DisposeAsync();


            // assert
            Assert.Equal(1, socketClient.GetCallCount(x => x.ReceiveAsync(default !, default !)));
Esempio n. 5
0
        public async Task OpenSessionAsync_ValidSocket_SubscribeToProtocol()
        {
            // arrange
            var protocolMock = new Mock <ISocketProtocol>(MockBehavior.Strict);
            var client       = new SocketClientStub()
            {
                Protocol = protocolMock.Object
            };

            protocolMock.Setup(x => x.Subscribe(It.IsAny <OnReceiveAsync>()));
            var manager = new Session(client);

            // act
            await manager.OpenSessionAsync().ConfigureAwait(false);

            // assert
            protocolMock.VerifyAll();
        }
Esempio n. 6
0
        public async Task RentAsync_NoRentals_OpenSocketConnection()
        {
            // arrange
            Mock <ISocketClientFactory> optionsMonitorMock = new(MockBehavior.Strict);
            Mock <ISocketProtocol>      protocol           = new();
            ISocketClientFactory        optionsMonitor     = optionsMonitorMock.Object;
            var socket = new SocketClientStub()
            {
                Protocol = protocol.Object, Name = "Foo"
            };

            optionsMonitorMock
            .Setup(x => x.CreateClient("Foo"))
            .Returns(() => socket);
            var pool = new SessionPool(optionsMonitor);

            // act
            await pool.CreateAsync("Foo");

            // assert
            Assert.Equal(1, socket.GetCallCount(x => x.OpenAsync(default !)));
        public async Task WriteObject_EmptyBuffer_ObjectParallel()
        {
            // arrange
            var socketClient = new SocketClientStub()
            {
                IsClosed = false
            };

            await using var writer = new SynchronizedMessageWriter(socketClient);

            // act
            List <Task> tasks = new();

            for (var i = 0; i < 10; i++)
            {
                tasks.Add(Task.Run(async() =>
                {
                    for (var m = 0; m < 100; m++)
                    {
                        await writer.CommitAsync(x =>
                        {
                            x.WriteStartObject();
                            x.WriteEndObject();
                        },
                                                 CancellationToken.None);
                    }
                }));
            }

            await Task.WhenAll(tasks);

            // assert
            Assert.Equal(1000, socketClient.SentMessages.Count);
            foreach (var message in socketClient.SentMessages)
            {
                Assert.Equal("{}", message);
            }
        }
        public async Task WriteObject_EmptyBuffer_Object()
        {
            // arrange
            var socketClient = new SocketClientStub()
            {
                IsClosed = false
            };

            await using var writer = new SynchronizedMessageWriter(socketClient);

            // act
            await writer.CommitAsync(x =>
            {
                x.WriteStartObject();
                x.WriteEndObject();
            },
                                     CancellationToken.None);

            // assert
            var elm = Assert.Single(socketClient.SentMessages);

            Assert.Equal("{}", elm);
        }