コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }