示例#1
0
        public async Task TestDeleteExpenseNotFound()
        {
            var result = await _controller.DeleteExpense(Guid.NewGuid());

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
            _mockContext.Verify(m => m.SaveChangesAsync(), Times.Never);
        }
        public void Delete_Expense_Deletes_The_Expense()
        {
            var expenseId = 42;

            underTest.DeleteExpense(expenseId);

            expenseRepo.Received().Delete(expenseId);
        }
        public async Task DeleteExpenseNotFoundIdTest()
        {
            var mockRepo = new Mock <IExpenseRepository>(MockBehavior.Strict);

            mockRepo.Setup(repo => repo.DetailAsync(It.IsAny <long>()))
            .ReturnsAsync((Expense)null);

            var controller = new ExpensesController(mockRepo.Object, _loggerManager, _mapper);

            var result = await controller.DeleteExpense(3);

            Assert.IsType <NotFoundResult>(result.Result);
            Assert.Null(result.Value);
        }
        public async Task DeleteExpenseTest()
        {
            var mockRepo = new Mock <IExpenseRepository>(MockBehavior.Strict);

            mockRepo.Setup(repo => repo.DeleteAsync(It.IsAny <Expense>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            mockRepo.Setup(repo => repo.DetailAsync(It.IsAny <long>()))
            .ReturnsAsync(GetTestExpense());

            var controller = new ExpensesController(mockRepo.Object, _loggerManager, _mapper);

            var result = await controller.DeleteExpense(3);

            var okResult = Assert.IsType <OkObjectResult>(result.Result);
            var model    = Assert.IsAssignableFrom <ExpenseDto>(okResult.Value);

            Assert.Equal(3, model.Id);
            mockRepo.Verify();
        }