public void WhenPaymentMessageReceivedWithRecipientUriUnKnownMeCodeArgumentExceptionOccurs()
        {
            _userService = new UserService(_ctx);
            _messageService = new MessageServices(_ctx);
            _paymentAccountService = new PaymentAccountService(_ctx);

            var application = _ctx.Applications.Add(new Application()
            {
                ApiKey = Guid.NewGuid(),
                ApplicationName = "Test",
                IsActive = true,
                Url = "http://www.test.com"
            });

            var securityPin = "2589";

            var sender = _userService.AddUser(application.ApiKey, "*****@*****.**",
                "james123", "*****@*****.**", "");

            sender.MobileNumber = "804-387-9693";
            _userService.UpdateUser(sender);

            sender.SecurityPin = securityPin;
            _userService.UpdateUser(sender);

            var senderAccount = _paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "James G Rhodes", "053000219",
                "1234123412", "Checking");

            sender.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            sender.PaymentAccounts.Add(senderAccount);

            var recipient = _userService.AddUser(application.ApiKey, "*****@*****.**",
                "james123", "*****@*****.**", "");

            var recipientAccount = _paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "James G Rhodes", "053000219",
                "1234123412", "Checking");

            recipient.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            recipient.PaymentAccounts.Add(recipientAccount);

            var meCodeValue = "$therealjamesrhodes";

            var message = _messageService.AddMessage(application.ApiKey.ToString(), sender.MobileNumber, meCodeValue, senderAccount.Id.ToString(),
                10.00, "Test Payment", "Payment", securityPin);
        }
        public void WhenPaymentMessageReceivedWithRecipientUriRegisteredMeCodeMessageCountIs1()
        {
            _userService = new UserService(_ctx);
            _messageService = new MessageServices(_ctx);
            _paymentAccountService = new PaymentAccountService(_ctx);

            var application = _ctx.Applications.Add(new Application()
            {
                ApiKey = Guid.NewGuid(),
                ApplicationName = "Test",
                IsActive = true,
                Url = "http://www.test.com"
            });

            var securityPin = "2589";

            var sender = _userService.AddUser(application.ApiKey, "*****@*****.**",
                "james123", "*****@*****.**", "");

            sender.MobileNumber = "804-387-9693";
            _userService.UpdateUser(sender);

            var senderAccount = _paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "James G Rhodes", "053000219",
                "1234123412", "Checking");

            sender.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            sender.PaymentAccounts.Add(senderAccount);

            var recipient = _userService.AddUser(application.ApiKey, "*****@*****.**",
                "james123", "*****@*****.**", "");

            var recipientAccount = _paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "James G Rhodes", "053000219",
                "1234123412", "Checking");

            recipient.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            recipient.PaymentAccounts.Add(recipientAccount);

            var meCodeValue = "$therealjamesrhodes";

            var meCode = _ctx.MECodes.Add(
                new MECode()
                {
                    ApprovedDate = System.DateTime.Now,
                    CreateDate = System.DateTime.Now,
                    Id = Guid.NewGuid(),
                    IsActive = true,
                    IsApproved = true,
                    LastUpdatedDate = System.DateTime.Now,
                    MeCode = meCodeValue,
                    UserId = recipient.UserId
                });

            sender.SecurityPin = securityPin;
            _userService.UpdateUser(sender);

            var message = _messageService.AddMessage(application.ApiKey.ToString(), sender.MobileNumber, "$therealjamesrhodes", senderAccount.Id.ToString(),
                10.00, "Test Payment", "Payment", securityPin);

            Assert.AreEqual(_ctx.Messages.Count(), 1);
        }
        public void WhenBatchingMessageWithOpenBatchWithWithdrawAndDepositTransactionThenTransactionsInBatchIs2()
        {
            ApplicationService applicationService = new ApplicationService(_ctx);
            MessageServices messageService = new MessageServices(_ctx);
            UserService userService = new UserService(_ctx);
            PaymentAccountService paymentAccountService = new PaymentAccountService(_ctx);
            TransactionBatchService transactionBatchService = new TransactionBatchService(_ctx, _logger);

            var transactionBatchGuid = Guid.NewGuid();
            var transactionAmount = 2.75;

            _ctx.TransactionBatches.Add(new TransactionBatch()
            {
                CreateDate = System.DateTime.Now,
                Id = transactionBatchGuid,
                IsClosed = false,
                TotalDepositAmount = 0,
                TotalNumberOfDeposits = 0,
                TotalWithdrawalAmount = 0,
                TotalNumberOfWithdrawals = 0,
                Transactions = new List<Transaction>()
            });
            _ctx.SaveChanges();

            var application = applicationService.AddApplication("Test", "http://www.test.com", true);
            var sender = userService.AddUser(application.ApiKey, "*****@*****.**", "pdthx123",
                "*****@*****.**", "1234");
            sender.SecurityPin = "2589";
            userService.UpdateUser(sender);

            var senderPaymentAccount = paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "Sender PaidThx",
                "053000219", "1234123412", "Checking");

            sender.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            sender.PaymentAccounts.Add(senderPaymentAccount);

            var recipient = userService.AddUser(application.ApiKey, "*****@*****.**", "pdthx123",
                "*****@*****.**", "1234");

            var recipientPaymentAccount = paymentAccountService.AddPaymentAccount(sender.UserId.ToString(), "Recipient PaidThx",
            "053000219", "1234123412", "Savings");

            recipient.PaymentAccounts = new System.Collections.ObjectModel.Collection<PaymentAccount>();
            recipient.PaymentAccounts.Add(recipientPaymentAccount);

            var message = messageService.AddMessage(application.ApiKey.ToString(), sender.EmailAddress, recipient.EmailAddress,
                senderPaymentAccount.Id.ToString(), transactionAmount, "Test Payment", "Payment", "2589");

            message.Recipient = userService.FindUserByEmailAddress(recipient.EmailAddress);

            transactionBatchService.BatchTransactions(message);

            var transactionBatch = transactionBatchService.GetOpenBatch();

            Assert.AreEqual(transactionBatchGuid, transactionBatch.Id);
            Assert.AreEqual(2, transactionBatch.Transactions.Count);
            Assert.AreEqual(1, transactionBatch.TotalNumberOfDeposits);
            Assert.AreEqual(1, transactionBatch.TotalNumberOfWithdrawals);
        }