public async Task Test_AddNewExpense_Fail_BadArgument() { var controller = new BudgetExpensesController(_expensesServices.Object); var response = await controller.AddNewExpense(null); Assert.NotNull(response); Assert.AreEqual(400, ((ObjectResult)response).StatusCode); }
public async Task Test_AddNewExpense_Fail_CallingMethod() { _expensesServices.Setup(e => e.AddNewExpense(It.IsAny <BudgetExpensesModel>())) .ThrowsAsync(new Exception("Exception when trying to add new model")); var controller = new BudgetExpensesController(_expensesServices.Object); var response = await controller.AddNewExpense(new AddNewExpenseRequest() { UserId = 1, ExpenseAmount = 50, ExpenseType = "Groceries" }); Assert.NotNull(response); Assert.AreEqual(500, ((ObjectResult)response).StatusCode); }
public async Task Test_AddNewExpense_Success() { _expensesServices.Setup(e => e.AddNewExpense(It.IsAny <BudgetExpensesModel>())) .Returns(Task.CompletedTask); var controller = new BudgetExpensesController(_expensesServices.Object); var response = await controller.AddNewExpense(new AddNewExpenseRequest() { UserId = 1, ExpenseAmount = 50, ExpenseType = "Groceries" }); Assert.NotNull(response); /*Assert.AreEqual(response.GetType(), typeof(StatusCodeResult));*/ Assert.AreEqual(201, ((StatusCodeResult)response).StatusCode); }