コード例 #1
0
        public void GetCurrentPrice_NotInitialized_ThrowsException()
        {
            var subject = new Binance(Mock.Of <IWebSocket>(), Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            var exception = Expect.ThrowAsync <InvalidOperationException>(async() => {
                await subject.GetCurrentPrice();
            });

            Assert.AreEqual("Binance cannot GetCurrentPrice until Initialized!", exception.Message);
        }
コード例 #2
0
        public void Dispose_NotInitialized_CantDoStuff()
        {
            var socketMock = new Mock <IWebSocket>();
            var subject    = new Binance(socketMock.Object, Mock.Of <IBinanceClient>(), Mock.Of <ITime>());

            subject.Dispose();

            var e = Expect.ThrowAsync <InvalidOperationException>(async() => {
                await subject.GetCurrentPrice();
            });

            Assert.AreEqual("Binance cannot GetCurrentPrice until Initialized!", e.Message);
            socketMock.Verify(m => m.Dispose());
        }
コード例 #3
0
        public void GetCurrentPrice_NonTickerMessage_Retries()
        {
            var time = DateTime.Now;
            var message = new { e = "24hrTicker", b = 1.25 }.Json();
            var dummyMessage = new { type = "cat facts" }.Json();
            var socketMock  = new Mock <IWebSocket>();
            var timeMock    = new Mock <ITime>();
            var binanceMock = InitBinanceClientMock();

            var subject = new Binance(socketMock.Object, binanceMock.Object, timeMock.Object);

            subject.Initialize(Assets.BTC, Assets.USDT).Wait();

            socketMock.SetupSequence(m => m.ReceiveMessage())
            .ReturnsAsync(dummyMessage)
            .ReturnsAsync(message);
            timeMock.Setup(m => m.Now).Returns(time);

            var result = subject.GetCurrentPrice().Result;

            Assert.AreEqual(time, result.DateTime);
            Assert.AreEqual(1.25M, result.Value);
        }
コード例 #4
0
        public void GetCurrentPrice_SocketDisconnct_ReconnectsAndRetries()
        {
            var time = DateTime.Now;
            var message = new { e = "24hrTicker", b = 1.25 }.Json();
            var socketMock  = new Mock <IWebSocket>();
            var timeMock    = new Mock <ITime>();
            var binanceMock = InitBinanceClientMock();

            var subject = new Binance(socketMock.Object, binanceMock.Object, timeMock.Object);

            subject.Initialize(Assets.BTC, Assets.USDT).Wait();

            socketMock.SetupSequence(m => m.ReceiveMessage())
            .ThrowsAsync(new WebSocketException("Shit's broken yo"))
            .ReturnsAsync(message);
            timeMock.Setup(m => m.Now).Returns(time);

            var result = subject.GetCurrentPrice().Result;

            Assert.AreEqual(time, result.DateTime);
            Assert.AreEqual(1.25M, result.Value);
            socketMock.Verify(m => m.Connect("wss://stream.binance.com:9443/ws/btcusdt@ticker"));
        }