public Task Transfer( IAccountGrain fromAccount, IAccountGrain toAccount, uint amountToTransfer) => Task.WhenAll( fromAccount.Withdraw(amountToTransfer), toAccount.Deposit(amountToTransfer));
public async Task TestSequence(IAccountGrain account, bool hasLogStored) { Assert.Equal(0u, await account.Balance()); var initialdepositguid = Guid.NewGuid(); await account.Deposit(100, initialdepositguid, "initial deposit"); Assert.Equal(100u, await account.Balance()); var firstwithdrawalguid = Guid.NewGuid(); var success = await account.Withdraw(70, firstwithdrawalguid, "first withdrawal"); Assert.True(success); Assert.Equal(30u, await account.Balance()); var secondwithdrawalguid = Guid.NewGuid(); success = await account.Withdraw(70, secondwithdrawalguid, "second withdrawal"); Assert.False(success); Assert.Equal(30u, await account.Balance()); if (hasLogStored) { // check the transaction log var log = await account.GetTransactionLog(); Assert.Equal(2, log.Count()); Assert.Equal(initialdepositguid, log[0].Guid); Assert.Equal("initial deposit", log[0].Description); Assert.Equal(firstwithdrawalguid, log[1].Guid); Assert.Equal("first withdrawal", log[1].Description); Assert.True(log[0].IssueTime < log[1].IssueTime); } else { await Assert.ThrowsAsync(typeof(NotSupportedException), async() => await account.GetTransactionLog()); } }
//public Task Transfer<TBalance>(long fromAccount, long toAccount, ulong amountToTransfer) where TBalance : Balance //{ // return Task.WhenAll( // this.GrainFactory.GetGrain<IAccount<TBalance>>(fromAccount).Withdraw(amountToTransfer), // this.GrainFactory.GetGrain<IAccount<TBalance>>(toAccount).Deposit(amountToTransfer)); //} public Task Transfer <TBalance>(IAccountGrain <TBalance> fromAccount, IAccountGrain <TBalance> toAccount, ulong amountToTransfer) where TBalance : Balance { return(Task.WhenAll( fromAccount.Withdraw(amountToTransfer), toAccount.Deposit(amountToTransfer))); }