public static ClientBalanceModel Create(ClientBalanceResponseModel src)
 {
     return(new ClientBalanceModel
     {
         AssetId = src.AssetId,
         Balance = src.Balance,
         Reserved = src.Reserved
     });
 }
示例#2
0
        public async Task ClaimInvitationLink()
        {
            await this.PrepareClainInvitationLink();

            var url = $"{ApiPaths.REFERRAL_LINKS_PATH}/{GlobalConstants.AutoTest}/claim";

            //send request without data
            var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NotFound);

            var body = new InvitationLinkClaimDTO()
            {
                ReferalLinkUrl = GlobalConstants.AutoTest,
                IsNewClient    = false
            };

            //send request with wrong data
            response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(body), Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NotFound);



            //Create link to be claimed
            var         createLinkUrl      = ApiPaths.REFERRAL_LINKS_INVITATION_PATH;
            ApiConsumer createLinkConsumer = this.InvitationLinkClaimersConsumers[0];

            this.InvitationLinkClaimersConsumers.RemoveAt(0);

            var createLinkResponse = await createLinkConsumer.ExecuteRequest(createLinkUrl, Helpers.EmptyDictionary, null, Method.POST);

            Assert.True(createLinkResponse.Status == HttpStatusCode.Created);
            var createdLink = JsonUtils.DeserializeJson <RequestInvitationLinkResponseDto>(createLinkResponse.ResponseJson);

            body = new InvitationLinkClaimDTO()
            {
                ReferalLinkUrl = createdLink.RefLinkUrl,
                IsNewClient    = true
            };
            string claimParam = JsonUtils.SerializeObject(body);

            url = $"{ApiPaths.REFERRAL_LINKS_INVITATION_PATH}/{createdLink.RefLinkId}/claim";

            for (int i = 0; i < this.InvitationLinkClaimersConsumers.Count; i++)
            {
                ApiConsumer claimConsumer = this.InvitationLinkClaimersConsumers[i];
                var         claimResponse = await claimConsumer.ExecuteRequest(url, Helpers.EmptyDictionary, claimParam, Method.PUT);

                InvitationLinkClaimResponseDTO parsedClaimResponse = JsonUtils.DeserializeJson <InvitationLinkClaimResponseDTO>(claimResponse.ResponseJson);

                ClientBalanceResponseModel senderBalance   = null;
                ClientBalanceResponseModel recieverBalance = null;

                if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                {
                    List <ClientBalanceResponseModel> senderBalances = (await this.BalancesClient.GetClientBalances(createLinkConsumer.ClientInfo.Account.Id)).ToList();
                    senderBalance = senderBalances.Where(b => b.AssetId == Constants.TREE_COIN_ID).FirstOrDefault();

                    List <ClientBalanceResponseModel> recieverBalances = (await this.BalancesClient.GetClientBalances(claimConsumer.ClientInfo.Account.Id)).ToList();
                    recieverBalance = recieverBalances.Where(b => b.AssetId == Constants.TREE_COIN_ID).FirstOrDefault();
                }

                var statisticsResponse = await createLinkConsumer.ExecuteRequest($"{ApiPaths.REFERRAL_LINKS_PATH}/statistics", Helpers.EmptyDictionary, null, Method.GET);

                RefLinksStatisticsDTO linkStatistics = JsonUtils.DeserializeJson <RefLinksStatisticsDTO>(statisticsResponse.ResponseJson);

                //assert first five claimers should claim successfully and recieve reward
                if (i < 6)
                {
                    //Assert.True(Guid.TryParse(parsedClaimResponse.TransactionRewardSender, out Guid temp1));
                    //Assert.True(Guid.TryParse(parsedClaimResponse.TransactionRewardRecipient, out Guid temp2));
                    if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                    {
                        Assert.True(senderBalance.Balance == (i + 1) * Constants.TREE_COIN_INVIRATION_AWARD);
                        Assert.True(recieverBalance.Balance == Constants.TREE_COIN_INVIRATION_AWARD);
                    }
                }
                else
                {
                    //Assert.Null(parsedClaimResponse.TransactionRewardSender);
                    //Assert.Null(parsedClaimResponse.TransactionRewardRecipient);
                    if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                    {
                        Assert.True(senderBalance.Balance == 5 * Constants.TREE_COIN_INVIRATION_AWARD);
                        Assert.Null(recieverBalance);
                    }
                }

                Assert.True(linkStatistics.NumberOfInvitationLinksAccepted == i + 1);

                //attempt to claim again with single user should result in error
                if (i == 0)
                {
                    var secondClaimResponse = await claimConsumer.ExecuteRequest(url, Helpers.EmptyDictionary, claimParam, Method.POST);

                    Assert.True(secondClaimResponse.Status != HttpStatusCode.OK);
                }
            }
        }