Esempio n. 1
0
        public void UnsubscribingOrderUpdateWhenAccountInfoAlsoSubscribed_Should_NotCloseSocket()
        {
            // arrange
            int closed = 0;
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close()).Raises(s => s.OnClose += null, new ClosedEventArgs(0, "", true));
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));
            socket.Object.OnClose += (sender, args) =>
            {
                closed++;
            };

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            var client = new BinanceSocketClient("test", "test")
            {
                SocketFactory = factory.Object
            };

            client.SubscribeToOrderUpdateStream("test", (data) => { });
            client.SubscribeToAccountUpdateStream("test", (data) => { });

            // act
            client.UnsubscribeFromOrderUpdateStream();

            // assert
            Assert.IsTrue(closed == 0);
        }