Esempio n. 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new ArgumentException("Invalid token type, must be StartObject");
            }
            if (objectType != typeof(AccountAssetsReply))
            {
                throw new ArgumentException("Can only convert to AccountAssetsReply");
            }
            var accountAssetsReply = new AccountAssetsReply();
            var jObject            = JObject.Load(reader);

            var accountAssets = jObject.SelectToken(Parameters.AccountAssets) as JArray;

            if (accountAssets != null)
            {
                foreach (var accountAssetJson in accountAssets)
                {
                    var accountAsset = JsonConvert.DeserializeObject <AccountAsset>(accountAssetJson.ToString());
                    accountAssetsReply.AccountAssets.Add(accountAsset);
                }
            }
            else
            {
                var accountAsset = JsonConvert.DeserializeObject <AccountAsset>(jObject.ToString());
                accountAssetsReply.AccountAssets.Add(accountAsset);
            }

            return(accountAssetsReply);
        }
Esempio n. 2
0
        private static void VerifyAccountAssets(AccountAssetsReply result, int expectedCount, bool includeAssetInfo)
        {
            AssertEquals(expectedCount, result.AccountAssets.Count, $"Number of assets on {TestSettings.Account1.AccountRs}");
            result.AccountAssets.ForEach(a => AssertIsLargerThanZero(a.AssetId, nameof(a.AssetId)));
            result.AccountAssets.ForEach(a => AssertIsLargerThanZero(a.QuantityQnt, nameof(a.QuantityQnt)));
            result.AccountAssets.ForEach(a => AssertIsLargerThanZero(a.UnconfirmedQuantityQnt, nameof(a.UnconfirmedQuantityQnt)));

            if (includeAssetInfo)
            {
                result.AccountAssets.ForEach(a => AssertIsNotNullOrEmpty(a.Name, nameof(a.Name)));
            }
            else
            {
                result.AccountAssets.ForEach(a => AssertIsNull(a.Name, nameof(a.Name)));
                result.AccountAssets.ForEach(a => AssertEquals(0, a.Decimals, nameof(a.Decimals)));
            }
        }