public async Task TestTipCornFromUnregistered() { var dbContext = TestUtils.CreateDatabase(); try { var startToUser = dbContext.TwitchQuery(_configuration["Config:TestToUserId"]).FirstOrDefault().UserWallet.Balance; var txController = new TxController(dbContext); var request = new TipRequest(); request.Columns = new string[] { }; request.To = "twitch|" + _configuration["Config:TestToUserId"]; request.From = "twitch|123123"; request.Platform = "twitch"; request.Amount = 100; var response = await txController.Tipcorn(request); var receipt = response.Value[0]; Assert.Null(receipt.Tx); Assert.Null(receipt.From); Assert.NotNull(receipt.To); var endToUser = dbContext.TwitchQuery(_configuration["Config:TestToUserId"]).FirstOrDefault().UserWallet.Balance; Assert.Equal(startToUser, endToUser); } finally { dbContext.Dispose(); } }
async Task <TxTestResult[]> Rain(decimal amount, User fromUser, User[] toUsers, bool writeOutput = true) { var dbContext = TestUtils.CreateDatabase(); try { List <TxTestResult> results = new List <TxTestResult>(); List <string> toList = new List <string>(); for (int i = 0; i < toUsers.Length; i++) { var res = new TxTestResult(); res.Amount = amount; res.FromUserId = fromUser.UserId; res.ToUserId = toUsers[i].UserId; res.FromStartBalance = fromUser.UserWallet.Balance.Value; res.ToStartBalance = toUsers[i].UserWallet.Balance.Value; toList.Add("twitch|" + toUsers[i].UserIdentity.TwitchId); results.Add(res); } var txController = new TxController(dbContext); var request = new RainRequest(); request.Columns = new string[] { "twitchid" }; request.Amount = amount; request.Platform = "twitch"; request.From = "twitch|" + fromUser.UserIdentity.TwitchId; request.To = toList.ToArray(); var response = (await txController.Rain(request)); using (var dbContext2 = TestUtils.CreateDatabase()) { var fromEnd = dbContext2.TwitchQuery(fromUser.UserIdentity.TwitchId).FirstOrDefault().UserWallet.Balance;//(decimal)responseData[0].From[nameof(UserWallet.Balance).ToLower()]; foreach (var result in results) { if (writeOutput) { result.FromEndBalance = fromEnd.Value; var toEnd = dbContext2.TwitchQuery(toUsers.FirstOrDefault(u => u.UserId == result.ToUserId).UserIdentity.TwitchId).FirstOrDefault().UserWallet.Balance; result.ToEndBalance = toEnd.Value; } result.ResponseObject = response; } } return(results.ToArray()); } finally { dbContext.Dispose(); } }
async Task <TxTestResult> Tip(decimal amount, User fromUser, User toUser, bool writeOutput = true) { var dbContext = TestUtils.CreateDatabase(); try { var tipResult = new TxTestResult(); tipResult.Amount = amount; tipResult.ToUserId = toUser.UserId; tipResult.FromUserId = fromUser.UserId; var txController = new TxController(dbContext); var request = new TipRequest(); request.Columns = new string[] { }; tipResult.FromStartBalance = fromUser.UserWallet.Balance.Value; tipResult.ToStartBalance = toUser.UserWallet.Balance.Value; request.Amount = amount; request.Platform = "twitch"; request.From = "twitch|" + fromUser.UserIdentity.TwitchId; request.To = "twitch|" + toUser.UserIdentity.TwitchId; var response = (await txController.Tipcorn(request)); if (writeOutput) { using (var dbContext2 = TestUtils.CreateDatabase()) { var fromEnd = dbContext2.TwitchQuery(fromUser.UserIdentity.TwitchId).FirstOrDefault().UserWallet.Balance;//(decimal)responseData[0].From[nameof(UserWallet.Balance).ToLower()]; var toEnd = dbContext2.TwitchQuery(toUser.UserIdentity.TwitchId).FirstOrDefault().UserWallet.Balance; tipResult.FromEndBalance = fromEnd.Value; tipResult.ToEndBalance = toEnd.Value; } } tipResult.ResponseObject = response; return(tipResult); } finally { dbContext.Dispose(); } }
public async Task TestPayoutSuccess() { var dbContext = TestUtils.CreateDatabase(); try { var txController = new TxController(dbContext); int changeCount = await txController.Payout(new HashSet <string>() { _configuration["Config:TestFromUserId"], _configuration["Config:TestToUserId"] }); Assert.Equal(2, changeCount); } finally { dbContext.Dispose(); } }
public async Task TestTipCornToUnregistered() { var dbContext = TestUtils.CreateDatabase(); try { var startFromUser = dbContext.TwitchQuery(_configuration["Config:TestFromUserId"]).FirstOrDefault().UserWallet.Balance; var txController = new TxController(dbContext); var request = new TipRequest(); request.Columns = new string[] { }; string toTwitchId = "123123"; request.To = "twitch|" + toTwitchId; request.From = "twitch|" + _configuration["Config:TestFromUserId"]; request.Platform = "twitch"; request.Amount = 100; var toUser = await dbContext.TwitchAsync(toTwitchId); dbContext.RemoveRange(dbContext.UnclaimedTx); TestUtils.RemoveUserIfExists(dbContext, toUser); var response = await txController.Tipcorn(request); var receipt = response.Value[0]; Assert.Null(receipt.Tx); Assert.NotNull(receipt.From); Assert.Null(receipt.To); using (var dbContext2 = TestUtils.CreateDatabase()) { var endFromUser = dbContext2.TwitchQuery(_configuration["Config:TestFromUserId"]).FirstOrDefault().UserWallet.Balance; Assert.Equal(startFromUser - request.Amount, endFromUser); dbContext2.AddUser(new UserIdentity() { Auth0Id = "temp", Auth0Nickname = "temp", TwitchId = toTwitchId }, new UserWallet()); var to = await dbContext2.TwitchAsync(toTwitchId); await TxUtils.TryClaimTx(new PlatformId() { Platform = "twitch", Id = toTwitchId }, to, dbContext2); } using (var dbContext2 = TestUtils.CreateDatabase()) { var to = await dbContext2.TwitchAsync(toTwitchId); Assert.Equal(request.Amount, to.UserWallet.Balance); var claim2 = await TxUtils.TryClaimTx(new PlatformId() { Platform = "twitch", Id = toTwitchId }, to, dbContext2);; Assert.Equal(0, claim2); } } finally { dbContext.Dispose(); } }