Ejemplo n.º 1
0
            public void AddsUserIdToEntity()
            {
                // Act.
                BudgetsController controller = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result     = controller.Put(this.id, this.budget);
                OkObjectResult    okResult   = result as OkObjectResult;

                // Assert.
                this.mockBudgetsRepository.Verify(m => m.Save(It.Is <Budget>(x => x.UserId == this.userId), It.IsAny <long>()), Times.Once, "The user ID should have been added to the entity.");
            }
Ejemplo n.º 2
0
            public void ReturnsRepositoryResult()
            {
                // Act.
                BudgetsController controller = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result     = controller.Put(this.id, this.budget);
                OkObjectResult    okResult   = result as OkObjectResult;

                // Assert.
                this.mockBudgetsRepository.Verify(m => m.Save(this.budget, this.userId), Times.Once, "The save method should have been called.");
                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.stubBudget, okResult.Value, "The result from the repository should have been returned.");
            }
Ejemplo n.º 3
0
            public void HandlesGeneralException()
            {
                // Arrange.
                this.mockBudgetsRepository
                .Setup(m => m.Save(It.IsAny <Budget>(), It.IsAny <long>()))
                .Throws(new Exception());

                // Act.
                BudgetsController controller   = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult     result       = controller.Put(this.id, this.budget);
                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 saving the budget.";

                Assert.AreEqual(expectedMessage, objectResult.Value, "The error message should have been the result.");
            }
Ejemplo n.º 4
0
            public void ReturnsBadRequestErrorWhenBudgetIdsMismatch()
            {
                // Arrange.
                this.id = this.id + 2;

                // Act.
                BudgetsController      controller       = new BudgetsController(this.mockBudgetsRepository.Object);
                IActionResult          result           = controller.Put(this.id, this.budget);
                BadRequestObjectResult badRequestResult = result as BadRequestObjectResult;

                // Assert.
                this.mockBudgetsRepository.VerifyNoOtherCalls();

                Assert.IsNotNull(badRequestResult, "A bad request response should have been returned.");
                Assert.AreEqual(400, badRequestResult.StatusCode, "The status code from the response should have been 405.");
                string expectedMessage = "The budget ID values did not match.";

                Assert.AreEqual(expectedMessage, badRequestResult.Value, "The error message should have been the result.");
            }