public BaseTransactionsApiTests()
        {
            _transactionsResourceUri = _baseAddress + "api/transactions";
            _transactionResourceUri = _transactionsResourceUri + "/1";

            _dummyTransaction = new Transaction { Id = 1, Amount = 123, CurrencyCode = "JPY" };
            _dummyEmptyListOfTransactions = new List<Transaction>();
            _dummyListOfTransactionsWithADummyTransaction = new List<Transaction> { _dummyTransaction };
        }
Пример #2
0
        public void When_save_succeeds_should_return_http_staus_ok()
        {
            //Arrange
            var transactionToUpdate = new Transaction { Id = 1, Amount = 123, CurrencyCode = "JPY" };
            var updatedTransaction = new Transaction { Id = 1, Amount = 321, CurrencyCode = "GBP" };

            var transactionRepoMock = NinjectBootstrap.KernelInstance.Get<ITransactionRepository>();
            transactionRepoMock.Stub(_ => _.GetAll()).Return(new List<Transaction>() { transactionToUpdate });
            transactionRepoMock.Stub(_ => _.SaveOrUpdate(Arg<Transaction>.Is.Anything)).Return(true);

            var response = _client.PutAsJsonAsync(_transactionResourceUri, updatedTransaction).Result;

            Assert.IsTrue(
                response.IsSuccessStatusCode,
                String.Format("Actual {0}", response.StatusCode));
        }
Пример #3
0
        internal TransactionModel CreateNew(Transaction transaction)
        {
            return new TransactionModel
            {
                Url = _urlHelper.Link("TransactionsApi", new { Id = transaction.Id }),

                TransactionId = transaction.Id,
                TransactionAmount = transaction.Amount,
                CurrencyCode = transaction.CurrencyCode,
                Description = transaction.Description,
                Merchant = transaction.Merchant,
                TransactionDate = transaction.TransactedOn,
                CreatedDate = transaction.CreatedOn,
                ModifiedDate = transaction.ModifiedOn
            };
        }
Пример #4
0
        internal bool Update(Transaction transactionToUpdate, TransactionModel model)
        {
            var modified = false;
            //NOTE: Id, CreatedOn, and ModifiedOn modifications are owned by system only
            if (model.TransactionAmount != 0 &&
                model.TransactionAmount != transactionToUpdate.Amount)
            {
                transactionToUpdate.Amount = model.TransactionAmount;
                modified = true;
            }
            if (string.IsNullOrWhiteSpace(model.CurrencyCode) == false &&
                model.CurrencyCode != transactionToUpdate.CurrencyCode)
            {
                transactionToUpdate.CurrencyCode = model.CurrencyCode;
                modified = true;
            }
            if (model.TransactionDate != DateTime.MinValue &&
                model.TransactionDate != transactionToUpdate.TransactedOn)
            {
                transactionToUpdate.TransactedOn = model.TransactionDate;
                modified = true;
            }
            if (string.IsNullOrWhiteSpace(model.Description) == false &&
                model.Description != transactionToUpdate.Description)
            {
                transactionToUpdate.Description = model.Description;
                modified = true;
            }
            if (string.IsNullOrWhiteSpace(model.Merchant) == false &&
                model.Merchant != transactionToUpdate.Merchant)
            {
                transactionToUpdate.Merchant = model.Merchant;
                modified = true;
            }

            return modified;
        }
        public bool SaveOrUpdate(Transaction transaction)
        {
            try
            {
                if (transaction.Id == 0)
                {
                    //Id, CreatedOn, and ModifiedOn are owned by system only
                    transaction.Id = Transactions.Any() ? Transactions.Max(t => t.Id) + 1 : 1; //seed at one
                    transaction.CreatedOn = DateTime.Now;
                    transaction.ModifiedOn = DateTime.MinValue;

                    _transactions.Add(transaction);
                }
                else
                {
                    var transactionToUpdate = _transactions.Where(t => t.Id == transaction.Id).FirstOrDefault();
                    if (transactionToUpdate == null)
                        throw new ArgumentException("No transaction to update. Concurrency issue.");
                    _transactions.Remove(transactionToUpdate);

                    //Id, CreatedOn, and ModifiedOn are owned by system only
                    transaction.ModifiedOn = DateTime.Now;
                    _transactions.Add(transaction);
                }
            }
            catch (Exception)
            {
                //log error
                return false;
            }
            return true;
        }