コード例 #1
0
        public void GetWalletDetailsById_ValidWalletId_ReturnsBalanceForAnExistingWallet(Guid walletId, string expTransactionId, int expVersion, int expCoins)
        {
            using (var mock = AutoMock.GetLoose())
            {
                Wallet expected = new Wallet
                {
                    WalletId        = new Guid("1d4e7d81-ce9d-457b-b056-0f883baa783d"),
                    TransactionType = Const.Credit,
                    Coins           = expCoins,
                    TransactionId   = expTransactionId,
                    Version         = expVersion
                };

                IEnumerable <Wallet> response = new List <Wallet> {
                    expected
                };
                var walletRepo = new Mock <IWalletRepository>();
                walletRepo.Setup(p => p.GetWalletById(It.IsAny <Guid>())).Returns(response);
                walletRepo.Setup(p => p.AddWalletData(expected));
                WalletService walletService = new WalletService(walletRepo.Object);

                walletService.CreateAndCreditWallet(expected);
                var actual = walletService.GetWalletDetailsById(walletId);

                Assert.Equal(expected.Coins, actual.Coins);
                Assert.Equal(expected.TransactionId, actual.TransactionId);
                Assert.Equal(expected.Version, actual.Version);
            }
        }
コード例 #2
0
        public void CreateAndCreditWallet_DuplicateCredit_ReturnsStatusCodeAcceptedAndBalance(int coins, string transactionId, int version, HttpStatusCode expHttpCode, int expBalance)
        {
            using (var mock = AutoMock.GetLoose())
            {
                Wallet payload = new Wallet
                {
                    WalletId        = new Guid("1d4e7d81-ce9d-457b-b056-0f883baa783d"),
                    TransactionType = Const.Credit,
                    Coins           = coins,
                    TransactionId   = transactionId,
                    Version         = version
                };

                IEnumerable <Wallet> response = new List <Wallet>()
                {
                    payload
                };
                var walletRepo = new Mock <IWalletRepository>();
                walletRepo.Setup(p => p.GetWalletById(It.IsAny <Guid>())).Returns(response);
                walletRepo.Setup(p => p.AddWalletData(payload));
                WalletService walletService = new WalletService(walletRepo.Object);

                var actual = walletService.CreateAndCreditWallet(payload);

                Assert.Equal(expHttpCode, actual.Item1);
                Assert.Equal(expBalance, actual.Item2);
            }
        }
コード例 #3
0
        public void DebitWallet_LessThanBalance_ReturnsStatusCodeCreatedAndBalance(int coins, string transactionId, HttpStatusCode expHttpCode, int expBalance)
        {
            using (var mock = AutoMock.GetLoose())
            {
                Wallet credit = new Wallet
                {
                    WalletId        = new Guid("1d4e7d81-ce9d-457b-b056-0f883baa783d"),
                    TransactionType = Const.Credit,
                    Coins           = 1000,
                    TransactionId   = "tx123",
                    Version         = 1
                };

                IEnumerable <Wallet> response = new List <Wallet>()
                {
                    credit
                };
                var walletRepo = new Mock <IWalletRepository>();
                walletRepo.Setup(p => p.GetWalletById(It.IsAny <Guid>())).Returns(response);
                walletRepo.Setup(p => p.AddWalletData(credit));
                WalletService walletService = new WalletService(walletRepo.Object);

                walletService.CreateAndCreditWallet(credit);

                Wallet debit = new Wallet
                {
                    WalletId        = new Guid("1d4e7d81-ce9d-457b-b056-0f883baa783d"),
                    TransactionType = Const.Debit,
                    Coins           = coins,
                    TransactionId   = transactionId
                };

                var actual = walletService.DebitWallet(debit);

                Assert.Equal(expHttpCode, actual.Item1);
                Assert.Equal(expBalance, actual.Item2);
            }
        }