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