public async Task ThrowsException()
        {
            var logbookServiceMock = new Mock <ILogbookService>();
            var userServiceMock    = new Mock <IUserService>();
            var imageOptimizerMock = new Mock <IImageOptimizer>();

            var sut = new LogbooksController(logbookServiceMock.Object, userServiceMock.Object, imageOptimizerMock.Object);

            var logbookViewModel = new LogbookViewModel()
            {
                Id             = 1,
                Name           = "Logbook01",
                BusinessUnitId = 1,
                LogbookPicture = null
            };

            logbookServiceMock.Setup(x => x.CreateLogbookAsync(logbookViewModel.Name, logbookViewModel.BusinessUnitId, logbookViewModel.Picture)).ThrowsAsync(new Exception());

            var actionResult = await sut.Create(logbookViewModel);

            var result = (RedirectToActionResult)actionResult;

            Assert.AreEqual("Error", result.ActionName);
            Assert.AreEqual("Home", result.ControllerName);
            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
        public async Task ThrowsAlreadyExistsException()
        {
            var logbookServiceMock = new Mock <ILogbookService>();
            var userServiceMock    = new Mock <IUserService>();
            var imageOptimizerMock = new Mock <IImageOptimizer>();

            var sut = new LogbooksController(logbookServiceMock.Object, userServiceMock.Object, imageOptimizerMock.Object);

            var logbookViewModel = new LogbookViewModel()
            {
                Id             = 1,
                Name           = "Logbook01",
                BusinessUnitId = 1,
                LogbookPicture = null
            };

            logbookServiceMock.Setup(x => x.CreateLogbookAsync(logbookViewModel.Name, logbookViewModel.BusinessUnitId, logbookViewModel.Picture)).ThrowsAsync(new AlreadyExistsException());

            var actionResult = await sut.Create(logbookViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }
        public async Task ThrowsBadRequestWhenReviewViewModelIsNotValid()
        {
            var logbookServiceMock = new Mock <ILogbookService>();
            var userServiceMock    = new Mock <IUserService>();
            var imageOptimizerMock = new Mock <IImageOptimizer>();

            var sut = new LogbooksController(logbookServiceMock.Object, userServiceMock.Object, imageOptimizerMock.Object);

            var logbookViewModel = new LogbookViewModel()
            {
                Id             = 1,
                Name           = null,
                BusinessUnitId = 1,
                LogbookPicture = null
            };

            logbookServiceMock.Setup(x => x.CreateLogbookAsync(logbookViewModel.Name, logbookViewModel.BusinessUnitId, logbookViewModel.Picture)).ReturnsAsync(TestHelpersLogbookController.TestLogbookDTO01());

            var actionResult = await sut.Create(logbookViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }