Ejemplo n.º 1
0
        public async void RemoveMessageFromCapsule(Models.Capsule[] capsules)
        {
            // Arrange
            var capsule         = capsules[0];
            var messageToRemove = capsule[0];
            var messageSrvMock  = new Mock <IMessageService>();

            messageSrvMock.Setup(srv => srv.GetMessageByIdAsync(It.IsAny <int>())).Returns(() => Task <Message> .Run(() => messageToRemove));

            var capsuleSrvMock = new Mock <ICapsuleService>();

            capsuleSrvMock.Setup(srv => srv.GetCapsuleByUserAsync()).Returns(Task <Capsule> .Run(() => capsule));
            capsuleSrvMock.Setup(srv => srv.SaveCapsuleAsync(It.IsAny <Capsule>())).Verifiable();

            var controller = new CapsuleController(messageService: messageSrvMock.Object, capsuleService: capsuleSrvMock.Object);

            // Act
            var result = await controller.RemoveFromCapsule(messageId : messageToRemove.Id, returnUrl : string.Empty) as RedirectToActionResult;

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Capsule", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
            capsuleSrvMock.Verify(srv => srv.GetCapsuleByUserAsync(), Times.Once);
            capsuleSrvMock.Verify(srv => srv.SaveCapsuleAsync(It.IsAny <Capsule>()), Times.Once);
        }