public void PutAccountUpdateAccount()
        {
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<AccountModel> contentResult;
            OkNegotiatedContentResult<AccountModel> accountResult;

            //Arrange
            using (var accountsController = new AccountsController())
            {
                //Build new AccountModel Object
                var newAccount = new AccountModel
                {
                    AccountNumber = 21323,
                    Balance = 213213,


                };
                //Insert AccountModelObject into Database so 
                //that I can take it out and test for update.
                result = accountsController.PostAccount(newAccount);

                //Cast result as Content Result so that I can gather information from ContentResult
                contentResult = (CreatedAtRouteNegotiatedContentResult<AccountModel>)result;
            }
            using (var SecondaccountsController = new AccountsController())
            {
                //Result contains the customer I had JUST createad
                result = SecondaccountsController.GetAccount(contentResult.Content.AccountId);

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

                //Get AccountModel from 'result'
                accountResult = (OkNegotiatedContentResult<AccountModel>)result;
            }

            using (var thirdController = new AccountsController())
            {
                var modifiedAccount = accountResult.Content;

                modifiedAccount.Balance += 5;

                //Act
                //The result of the Put Request
                result = thirdController.PutAccount(accountResult.Content.AccountId, modifiedAccount);

                //Assert
                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            }
        }
        public void DeleteAccountDeletesAccount()
        {
            int customerIdForTest = 1;

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

            var account = new AccountModel
            {
                CustomerId = customerIdForTest,
                CreatedDate = DateTime.Now,
                AccountNumber = "5555",
                Balance = 998877.66M
            };
            IHttpActionResult result = accountController.PostAccount(account);
            CreatedAtRouteNegotiatedContentResult<AccountModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult<AccountModel>)result;

            int accountIdToDelete = contentResult.Content.AccountId;

            //Act: Call DeleteAccount
            result = accountController.DeleteAccount(accountIdToDelete);

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

            result = accountController.GetAccount(accountIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetAccountsReturnsAccounts()
        {
            //Arrange: Instantiate AccountsController so its methods can be called
            var accountController = new AccountsController();

            //Act: Call the GetAccounts method
            IEnumerable<AccountModel> accounts = accountController.GetAccounts();

            //Assert: Verify that an array was returned with at least one element
            Assert.IsTrue(accounts.Count() > 0);
        }
        public void GetAccountsReturnAccounts()
        {
            //Arrange
            var accountsController = new AccountsController();

            //Act
            IQueryable<AccountModel> accounts = accountsController.GetAccounts();

            //Assert
            Assert.IsTrue(accounts.Count() > 0);

        }
        public void GetAccountbyIDReturnAccount()
        {
            //Arrange
            var accountsController = new AccountsController();

            //Act
            IHttpActionResult result = accountsController.GetAccount(1);

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

            //If action returns: Ok()
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<AccountModel>));

        }
        public void GetAccountsForCustomerReturnAccounts()
        {
            //Arrange
            var AccountsController = new AccountsController();

            //Act
            IHttpActionResult result = AccountsController.GetAccounts(1);

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

            //If action returns: Ok()
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<IQueryable<AccountModel>>));

        }
        public void GetAccountReturnsAccount()
        {
            int AccountIdForTest = 1;

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

            //Act: Call the GetAccount method
            IHttpActionResult result = accountController.GetAccount(AccountIdForTest);

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

            OkNegotiatedContentResult<AccountModel> contentResult =
                (OkNegotiatedContentResult<AccountModel>)result;
            Assert.IsTrue(contentResult.Content.AccountId == AccountIdForTest);
        }
        public void PostAccountUpdateAccount()
        {
            //Arrange
            var accountController = new AccountsController();

            //Act
            var newAccount = new AccountModel
            {
                AccountNumber = 1231,
                Balance = 1222222
            };

            //Get the result of the post request
            IHttpActionResult result = accountController.PostAccount(newAccount);

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

            //Cast
            CreatedAtRouteNegotiatedContentResult<AccountModel> contentResult = (CreatedAtRouteNegotiatedContentResult<AccountModel>)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);


        }
        public void DeleteAccountRecord()
        {
            //Arrange
            //Create Controller
            var customersController = new AccountsController();

            //Create a customer to be deleted
            var dbAccount = new AccountModel
            {
                AccountNumber = 21323,
                Balance = 213213,

            };

            //Add 'new customer' to the DB using a POST
            //Save returned value as RESULT
            IHttpActionResult result = customersController.PostAccount(dbAccount);

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


            //Result contains the customer I had JUST created
            result = customersController.GetAccount(contentResult.Content.AccountId);

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


            //Act
            //The result of the Delete Request
            result = customersController.DeleteAccount(customerResult.Content.AccountId);

            //Assert

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

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<AccountModel>));
        }
        public void GetTransactionsForAccountReturnsTransactions()
        {
            int accountIdForTest = 1;

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

            //Act: Call the GetTransactionsForAccount method
            IHttpActionResult result =
                accountController.GetTransactionsForAccount(accountIdForTest);

            //Assert:
            // Verify that HTTP status code is OK
            // Verify that an array was returned with at least one element
            Assert.IsInstanceOfType(result,
                typeof(OkNegotiatedContentResult<IQueryable<TransactionModel>>));

            OkNegotiatedContentResult<IQueryable<TransactionModel>> contentResult =
                (OkNegotiatedContentResult<IQueryable<TransactionModel>>)result;
            Assert.IsTrue(contentResult.Content.Count() > 0);
        }
        public void PutAccountUpdatesAccount()
        {
            int accountIdForTest = 1;
            string accountNumberForTest = "XXXY1";
            decimal balanceForTest = 872345.34M;

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

            //Act:
            // Get an existing account, change it, and
            //  pass it to PutAccount

            IHttpActionResult result = accountController.GetAccount(accountIdForTest);
            OkNegotiatedContentResult<AccountModel> contentResult =
                (OkNegotiatedContentResult<AccountModel>)result;
            AccountModel updatedAccount = (AccountModel)contentResult.Content;

            string accountNumberBeforeUpdate = updatedAccount.AccountNumber;
            decimal balanceBeforeUpdate = updatedAccount.Balance;

            updatedAccount.AccountNumber = accountNumberForTest;
            updatedAccount.Balance = balanceForTest;

            result = accountController.PutAccount
                                     (updatedAccount.AccountId, updatedAccount);

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

            var statusCode = (StatusCodeResult)result;

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

            result = accountController.GetAccount(accountIdForTest);

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

            OkNegotiatedContentResult<AccountModel> readContentResult =
                (OkNegotiatedContentResult<AccountModel>)result;
            updatedAccount = (AccountModel)readContentResult.Content;

            Assert.IsTrue(updatedAccount.AccountNumber == accountNumberForTest);
            Assert.IsTrue(updatedAccount.Balance == balanceForTest);

            updatedAccount.AccountNumber = accountNumberBeforeUpdate;
            updatedAccount.Balance = balanceBeforeUpdate;

            /*
            updatedAccount.AccountNumber = "1000";
            updatedAccount.Balance = 938M;
            */

            result = accountController.PutAccount
                                 (updatedAccount.AccountId, updatedAccount);
        }
        public void PostAccountCreatesAccount()
        {
            int customerIdForTest = 1;

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

            //Act:
            // Create a AccountModel object populated with test data,
            //  and call PostAccount
            var newAccount = new AccountModel
            {
                AccountNumber = "223344",
                Balance = 888.77M,
                CreatedDate = DateTime.Now,
                CustomerId = customerIdForTest
            };
            IHttpActionResult result = accountController.PostAccount(newAccount);

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

            // Delete the test account
            result = accountController.DeleteAccount(contentResult.Content.AccountId);
        }