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 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 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 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 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);
        }