Ejemplo n.º 1
0
        public void GetOrderBookExpected()
        {
            IDeserializer deserializer = null;

            var restMock = new Mock <IRestClient>(MockBehavior.Strict);

            restMock.SetupAllProperties();
            restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d);

            restMock.Setup(x => x.Execute <ResponseSingle <OrderBook> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request =>
            {
                var responseMock = new Mock <IRestResponse <ResponseSingle <OrderBook> > >(MockBehavior.Strict);
                responseMock.SetupAllProperties();

                var aggregateParameter = request.Parameters.Find(x => x.Name == "aggregate");
                bool aggregate         = aggregateParameter != null ? (bool)aggregateParameter.Value : false;

                responseMock.Object.Content = aggregate ? Properties.Resources.OrderBookResponse1 : Properties.Resources.OrderBookResponse2;
                responseMock.Object.Request = request;
                responseMock.Object.Data    = deserializer.Deserialize <ResponseSingle <OrderBook> >(responseMock.Object);

                return(responseMock.Object);
            });

            var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock);

            var res = client.GetOrderBook("btc_mxn");

            Assert.IsNotNull(res);
            Assert.AreNotEqual <int>(0, res.Asks.Count);
            Assert.AreNotEqual <int>(0, res.Bids.Count);
            Assert.AreNotEqual <long>(0, res.Sequence);

            var diff = res.UpdatedAt - default(System.DateTime);

            Assert.IsTrue(diff > System.TimeSpan.Zero);

            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount);
            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price);
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].OrderId));
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName));

            const bool AggregateResults = true;

            res = client.GetOrderBook("btc_mxn", AggregateResults);

            Assert.IsNotNull(res);
            Assert.AreNotEqual <int>(0, res.Asks.Count);
            Assert.AreNotEqual <int>(0, res.Bids.Count);
            Assert.AreNotEqual <long>(0, res.Sequence);

            diff = res.UpdatedAt - default(System.DateTime);
            Assert.IsTrue(diff > System.TimeSpan.Zero);

            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount);
            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price);
            Assert.IsTrue(string.IsNullOrEmpty(res.Asks[0].OrderId));
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName));
        }
Ejemplo n.º 2
0
        public void GetOrderBookExpected1()
        {
            var client = new BitsoClient(this.TestingServerUrl);

            var res = client.GetOrderBook("btc_mxn");

            Assert.IsNotNull(res);
            Assert.AreNotEqual <int>(0, res.Asks.Count);
            Assert.AreNotEqual <int>(0, res.Bids.Count);
            Assert.AreNotEqual <long>(0, res.Sequence);

            var diff = res.UpdatedAt - default(System.DateTime);

            Assert.IsTrue(diff > System.TimeSpan.Zero);

            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount);
            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price);
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].OrderId));
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName));

            const bool AggregateResults = true;

            res = client.GetOrderBook("btc_mxn", AggregateResults);

            Assert.IsNotNull(res);
            Assert.AreNotEqual <int>(0, res.Asks.Count);
            Assert.AreNotEqual <int>(0, res.Bids.Count);
            Assert.AreNotEqual <long>(0, res.Sequence);

            diff = res.UpdatedAt - default(System.DateTime);
            Assert.IsTrue(diff > System.TimeSpan.Zero);

            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount);
            Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price);
            Assert.IsTrue(string.IsNullOrEmpty(res.Asks[0].OrderId));
            Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName));
        }