コード例 #1
0
        public async Task HTTPステータスが200かつSuccessが1_Assetを返す()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, _) =>
            {
                Assert.StartsWith("https://api.bitbank.cc/v1/", request.RequestUri.AbsoluteUri, StringComparison.Ordinal);
            })
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(Json)
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = await restApi.GetAssetsAsync().ConfigureAwait(false);

            Assert.NotNull(result);
            Assert.All(result, entity =>
            {
                Assert.Equal(EntityHelper.GetTestValue <int>(), entity.AmountPrecision);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.FreeAmount);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.LockedAmount);
                Assert.Equal(EntityHelper.GetTestValue <AssetName>(), entity.Name);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.OnhandAmount);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.WithdrawalFee.Over);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.WithdrawalFee.Threshold);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.WithdrawalFee.Under);
            });
        }
コード例 #2
0
        public async Task HTTPステータスが200かつSuccessが1_HealthStatusを返す()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, _) =>
            {
                Assert.StartsWith("https://api.bitbank.cc/v1/", request.RequestUri.AbsoluteUri, StringComparison.Ordinal);
            })
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(Json)
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = await restApi.GetStatusesAsync().ConfigureAwait(false);

            Assert.NotNull(result);
            Assert.All(result, entity =>
            {
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.MinAmount);
                Assert.Equal(EntityHelper.GetTestValue <CurrencyPair>(), entity.Pair);
                Assert.Equal(EntityHelper.GetTestValue <SystemStatus>(), entity.Status);
            });
        }
コード例 #3
0
        public async Task タイムアウト_BitbankDotNetExceptionをスローする()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Throws <TaskCanceledException>();

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = restApi.GetAssetsAsync();

            var exception = await Assert.ThrowsAsync <BitbankDotNetException>(() => result).ConfigureAwait(false);

            Assert.IsType <TaskCanceledException>(exception.InnerException);
        }
コード例 #4
0
        public async Task  正なJSONを取得_BitbankDotNetExceptionをスローする(string content)
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                Content = new StringContent(content)
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = restApi.GetAssetsAsync();

            await Assert.ThrowsAsync <BitbankDotNetException>(() => result).ConfigureAwait(false);
        }
コード例 #5
0
        public async Task HTTPステータスが200かつSuccessが1_Orderを返す()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, _) =>
            {
                Assert.StartsWith("https://api.bitbank.cc/v1/", request.RequestUri.AbsoluteUri, StringComparison.Ordinal);
            })
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(Json)
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = await restApi.GetOrdersAsync(default, default).ConfigureAwait(false);
コード例 #6
0
        public async Task HTTPステータスが404またはSuccessが0_BitbankDotNetExceptionをスローする(HttpStatusCode statusCode, int success, int apiErrorCode)
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage(statusCode)
            {
                Content = new StringContent($"{{\"success\":{success},\"data\":{{\"code\":{apiErrorCode}}}}}")
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = restApi.GetAssetsAsync();

            var exception = await Assert.ThrowsAsync <BitbankDotNetException>(() => result).ConfigureAwait(false);

            Assert.Equal(apiErrorCode, exception.ApiErrorCode);
        }
        public async Task HTTPステータスが200かつSuccessが1_CurrencyPairSettingを返す()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, _) =>
            {
                Assert.StartsWith("https://api.bitbank.cc/v1/", request.RequestUri.AbsoluteUri, StringComparison.Ordinal);
            })
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(Json)
            });

            using var client  = new HttpClient(handler.Object);
            using var restApi = new BitbankRestApiClient(client, " ", " ");
            var result = await restApi.GetCurrencyPairSettingsAsync().ConfigureAwait(false);

            Assert.NotNull(result);
            Assert.All(result, entity =>
            {
                Assert.Equal(EntityHelper.GetTestValue <int>(), entity.AmountDigits);
                Assert.Equal(EntityHelper.GetTestValue <AssetName>(), entity.BaseAsset);
                Assert.Equal(EntityHelper.GetTestValue <bool>(), entity.IsStopBuy);
                Assert.Equal(EntityHelper.GetTestValue <bool>(), entity.IsStopSell);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.LimitMaxAmount);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.MakerFeeRateBase);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.MakerFeeRateQuote);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.MarketAllowanceRate);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.MarketMaxAmount);
                Assert.Equal(EntityHelper.GetTestValue <CurrencyPair>(), entity.Name);
                Assert.Equal(EntityHelper.GetTestValue <int>(), entity.PriceDigits);
                Assert.Equal(EntityHelper.GetTestValue <AssetName>(), entity.QuoteAsset);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.TakerFeeRateBase);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.TakerFeeRateQuote);
                Assert.Equal(EntityHelper.GetTestValue <decimal>(), entity.UnitAmount);
            });
        }