public void DeleteTransactionDeletesTransaction()
        {
            int accountIdForTest = 1;

            //Arrange:
            // Instantiate TransactionsController so its methods can be called
            // Create a new transaction to be deleted, and get its transaction ID
            var transactionController = new TransactionsController();

            var transaction = new TransactionModel
            {
                AccountId = accountIdForTest,
                Amount = 3451.87M,
                TransactionDate = DateTime.Now
            };
            IHttpActionResult result =
                    transactionController.PostTransaction(transaction);
            CreatedAtRouteNegotiatedContentResult<TransactionModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<TransactionModel>)result;

            int transactionIdToDelete = contentResult.Content.TransactionId;

            //Act: Call DeleteTransaction
            result = transactionController.DeleteTransaction(transactionIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted transaction returns result not found
            Assert.IsInstanceOfType(result,
                typeof(OkNegotiatedContentResult<Transaction>));

            result = transactionController.GetTransaction(transactionIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetTransactionsReturnsTransactions()
        {
            //Arrange: Instantiate TransactionsController so its methods can be called
            var transactionController = new TransactionsController();

            //Act: Call the GetTransactions method
            IEnumerable<TransactionModel> transactions = transactionController.GetTransactions();

            //Assert: Verify that an array was returned with at least one element
            Assert.IsTrue(transactions.Count() > 0);
        }
        [TestMethod] //{1}
        public void GetTransactionsReturnTransactions()
        {
            //Arrange
            var transactionsController = new TransactionsController();

            //Act
            IQueryable<TransactionModel> results = transactionsController.GetTransactions();

            //Assert (if true, pass)
            Assert.IsTrue(results.Count() > 0);
        }
        [TestMethod]  //{3}
        public void GetAllTransactionsForAccountIdReturnTransactions()
        {
            //arrange
            var transactionsController = new TransactionsController();

            //act
            IHttpActionResult result = transactionsController.GetTransactions(1);

            //assert
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<IQueryable<TransactionModel>>));
        }
        [TestMethod]  //{4}
        public void PutTransactionUpdateTransaction()
        {
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<TransactionModel> contentResult;
            OkNegotiatedContentResult<TransactionModel> transactionResult;


            //Arrange
            using (var transactionsController = new TransactionsController())
            {

                var tsModel = new TransactionModel
                {
                    Amount = 123,                
                };

                result = transactionsController.PostTransaction(tsModel);

                //Cast result as Content Result so that I can gather information from ContentResult
                contentResult = (CreatedAtRouteNegotiatedContentResult<TransactionModel>)result;
            }

            using (var secondTransactionsController = new TransactionsController())
            {

                //Result contains the customer I had JUST createad
                result = secondTransactionsController.GetTransaction(1);

                Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));
                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TransactionModel>));
                
                //Get transactionModel from 'result'
                transactionResult = (OkNegotiatedContentResult<TransactionModel>)result;
           
             }

            using (var thirdTransactionsController = new TransactionsController())
            {
                var modifiedContent = transactionResult.Content;

                modifiedContent.Amount += 5;

                //Act
                result = thirdTransactionsController.PutTransaction(transactionResult.Content.TransactionId, modifiedContent);
                //Assert
                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));

            }
        }
        [TestMethod] //{2}
        public void GetTransactionReturnTransaction()
        {
            //Arrange
            var transactionController = new TransactionsController();

            //Act
          
            IHttpActionResult result = transactionController.GetTransaction(1);

            //Assert
            //If not found
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));


            //If is found, and returned
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TransactionModel>));
            
        }
        public void GetTransactionReturnsTransaction()
        {
            int transactionIdForTest = 1;

            //Arrange: Instantiate TransactionsController so its methods can be called
            var transactionController = new TransactionsController();

            //Act: Call the GetTransaction method
            IHttpActionResult result = transactionController.GetTransaction(transactionIdForTest);

            //Assert:
            // Verify that HTTP status code is OK
            // Verify that returned transaction ID is correct
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<TransactionModel>));

            OkNegotiatedContentResult<TransactionModel> contentResult =
                (OkNegotiatedContentResult<TransactionModel>)result;
            Assert.IsTrue(contentResult.Content.TransactionId == transactionIdForTest);
        }
        public void PostTransactionCreatesTransaction()
        {
            int accountIdForTest = 1;

            //Arrange: Instantiate TransactionsController so its methods can be called
            var transactionController = new TransactionsController();

            //Act:
            // Create a TransactionModel object populated with test data,
            //  and call PostTransaction
            var newTransaction = new TransactionModel
            {
                AccountId = accountIdForTest,
                Amount = -555M,
                TransactionDate = DateTime.Now

            };
            IHttpActionResult result = transactionController.PostTransaction(newTransaction);

            //Assert:
            // Verify that the HTTP result is CreatedAtRouteNegotiatedContentResult
            // Verify that the HTTP result body contains a nonzero transaction ID
            Assert.IsInstanceOfType
                (result, typeof(CreatedAtRouteNegotiatedContentResult<TransactionModel>));
            CreatedAtRouteNegotiatedContentResult<TransactionModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<TransactionModel>)result;
            Assert.IsTrue(contentResult.Content.TransactionId != 0);

            // Delete the test transaction
            result = transactionController.DeleteTransaction(contentResult.Content.TransactionId);
        }
        public void PutTransactionUpdatesTransaction()
        {
            int transactionIdForTest = 1;
            decimal newTransactionAmount;

            //Arrange: Instantiate TransactionsController so its methods can be called
            var transactionController = new TransactionsController();

            //Act:
            // Get an existing transaction, change it, and
            //  pass it to PutTransaction

            IHttpActionResult result =
                transactionController.GetTransaction(transactionIdForTest);
            OkNegotiatedContentResult<TransactionModel> contentResult =
                (OkNegotiatedContentResult<TransactionModel>)result;
            TransactionModel updatedTransaction = (TransactionModel)contentResult.Content;

            decimal amountBeforeUpdate = updatedTransaction.Amount;

            updatedTransaction.Amount += 500.23M;
            newTransactionAmount = updatedTransaction.Amount;

            result = transactionController.PutTransaction
                                 (updatedTransaction.TransactionId, updatedTransaction);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the transaction and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = transactionController.GetTransaction(transactionIdForTest);

            Assert.IsInstanceOfType(result,
                typeof(OkNegotiatedContentResult<TransactionModel>));

            OkNegotiatedContentResult<TransactionModel> readContentResult =
                (OkNegotiatedContentResult<TransactionModel>)result;
            updatedTransaction = (TransactionModel)readContentResult.Content;

            Assert.IsTrue(updatedTransaction.Amount == newTransactionAmount);

            updatedTransaction.Amount = amountBeforeUpdate;

            /*
            updatedTransaction.Amount = 1000M;
            */

            result = transactionController.PutTransaction
                                 (updatedTransaction.TransactionId, updatedTransaction);
        }
        [TestMethod] //{6}
        public void DeleteTransactionDeleteTransaction()
        {
            //Arrange
            //Create Controller
            var transactionsController = new TransactionsController();
            
            //Create a customer to be deleted
            var dbTransactions = new TransactionModel
            {
                Amount = 21323,
               
            };

            //Add 'new customer' to the DB using a POST
            //Save returned value as RESULT
            IHttpActionResult result = transactionsController.PostTransaction(dbTransactions);

            //Cast result as Content Result so that I can gather information from ContentResult
            CreatedAtRouteNegotiatedContentResult<TransactionModel> contentResult = (CreatedAtRouteNegotiatedContentResult<TransactionModel>)result;


            //Result contains the customer I had JUST created
            result = transactionsController.GetTransaction(1);

            //Get CustomerModel from 'result'
            OkNegotiatedContentResult<TransactionModel> customerResult = (OkNegotiatedContentResult<TransactionModel>)result;
            

            //Act
            //The result of the Delete Request
           IHttpActionResult second = transactionsController.DeleteTransaction(1);

            //Assert

            //If action returns: NotFound()
            Assert.IsNotInstanceOfType(second, typeof(NotFoundResult));

            Assert.IsInstanceOfType(second, typeof(OkNegotiatedContentResult<TransactionModel>));
        }
        [TestMethod] // {5}
        public void PostTransactionCreateTransactions()
        {
            //Arrange
            var transactionsController = new TransactionsController();

            //Act
            var newTransaction = new TransactionModel
            {
                Amount = 12,

            };

            IHttpActionResult result = transactionsController.PostTransaction(newTransaction);

            //Assert

            //If not 'true' Assert False
            Assert.IsInstanceOfType(result, typeof(CreatedAtRouteNegotiatedContentResult<TransactionModel>));

            //Cast
            CreatedAtRouteNegotiatedContentResult<TransactionModel> contentResult = (CreatedAtRouteNegotiatedContentResult<TransactionModel>)result;

            //Check if Customer is posted to the database
            //Check to see if Customer ID is NOT equal to zero.  If Customer Id us equal to zero,
            //then customer was NOT added to Database
            Assert.IsTrue(contentResult.Content.AccountId!= 0);
        }