public async Task ConnectStoryAndAlbum_OnException() { var service = new Mock <IConnectService>(); service.Setup(s => s.ConnectAlbumAndStory("aId", "sId")) .Throws(new Exception()); ConnectAlbumAndStoryInputModel model = new ConnectAlbumAndStoryInputModel { StoryId = "sId", AlbumId = "aId" }; ConnectController controller = new ConnectController( service.Object, userManager.Object, logger) { TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object) }; var result = await controller.ConnectStoryAndAlbum(model); var viewResult = Assert.IsAssignableFrom <RedirectResult>(result); viewResult.Url.ShouldBe("/"); controller.TempData.ContainsKey("notification").ShouldBeTrue(); controller.TempData["notification"].ShouldNotBeNull(); controller.TempData["notification"].ShouldBeOfType <string[]>(); string[] arr = controller.TempData["notification"] as string[]; arr[0].ShouldBe("danger"); }
public async Task <IActionResult> ConnectStoryAndAlbum(ConnectAlbumAndStoryInputModel model) { try { bool result = await this.connectService.ConnectAlbumAndStory(model.AlbumId, model.StoryId); if (result) { AddSuccessNotification(Notifications.Success); } else { AddDangerNotification(Notifications.Fail); } return(Redirect($"/Stories/Details/{model.StoryId}")); } catch (System.Exception e) { logger.LogError(string.Format(SetLog.Error, CurrentUser.UserName, CurrentController, e.Message)); AddDangerNotification(string.Format(Notifications.Fail)); return(Redirect("/")); } }
public async Task <IViewComponentResult> InvokeAsync(string albumId) { ConnectAlbumAndStoryInputModel model = new ConnectAlbumAndStoryInputModel(); model.AlbumId = albumId; User user = await this.userManager.GetUserAsync(this.UserClaimsPrincipal); this.TempData["storyList"] = user.Stories.ToList(); return(View(model)); }