public void ReturnsRepositoryResult()
            {
                // Act.
                BudgetsController controller = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result     = controller.GetTotals();
                OkObjectResult    okResult   = result as OkObjectResult;

                // Assert.
                this.mockBudgetsRepository.Verify(m => m.GetTotals(this.userId), Times.Once, "The budgets should have been requested from the repository.");
                this.mockBudgetsRepository.VerifyNoOtherCalls();

                Assert.IsNotNull(okResult, "An OK response should have been returned.");
                Assert.AreEqual(200, okResult.StatusCode, "The status code from the response should have been 200.");
                Assert.AreEqual(this.stubBudgets, okResult.Value, "The result from the repository should have been returned.");
            }
            public void HandlesGeneralException()
            {
                // Arrange.
                this.mockBudgetsRepository
                .Setup(m => m.GetTotals(It.IsAny <long>()))
                .Throws(new Exception());

                // Act.
                BudgetsController controller   = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result       = controller.GetTotals();
                ObjectResult      objectResult = result as ObjectResult;

                // Assert.
                Assert.IsNotNull(objectResult, "An object result should have been returned.");
                Assert.AreEqual(500, objectResult.StatusCode, "The status code from the response should have been 500.");
                string expectedMessage = "There was an error getting the budgets.";

                Assert.AreEqual(expectedMessage, objectResult.Value, "The error message should have been the result.");
            }
            public void ReturnsAnEmptyListWhenRepositoryReturnsNull()
            {
                // Arrange.
                this.stubBudgets = null;
                this.mockBudgetsRepository
                .Setup(m => m.GetTotals(It.IsAny <long>()))
                .Returns(this.stubBudgets);

                // Act.
                BudgetsController controller = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result     = controller.GetTotals();
                OkObjectResult    okResult   = result as OkObjectResult;

                // Assert.
                this.mockBudgetsRepository.Verify(m => m.GetTotals(this.userId), Times.Once, "The budgets should have been requested from the repository.");
                this.mockBudgetsRepository.VerifyNoOtherCalls();

                Assert.IsNotNull(okResult, "An OK response should have been returned.");
                Assert.AreEqual(200, okResult.StatusCode, "The status code from the response should have been 200.");
                Assert.AreEqual(0, (okResult.Value as List <BudgetSummary>).Count, "An empty list should be the result.");
            }