Esempio n. 1
0
        public async Task ConnectStoryAndRoute_OnException()
        {
            var service = new Mock <IConnectService>();

            service.Setup(s => s.ConnectStoryAndRoute("sId", "rId"))
            .Throws(new Exception());

            ConnectRouteAndStoryInputModel model = new ConnectRouteAndStoryInputModel
            {
                StoryId = "sId",
                RouteId = "rId"
            };

            ConnectController controller = new ConnectController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };
            var result = await controller.ConnectStoryAndRoute(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> ConnectRouteAndStory(ConnectRouteAndStoryInputModel model)
        {
            try
            {
                bool result = await this.connectService.ConnectStoryAndRoute(model.StoryId, model.RouteId);

                if (result)
                {
                    AddSuccessNotification(Notifications.Success);
                }
                else
                {
                    AddDangerNotification(Notifications.Fail);
                }

                return(Redirect($"/Routes/Details/{model.RouteId}"));
            }
            catch (System.Exception e)
            {
                logger.LogError(string.Format(SetLog.Error,
                                              CurrentUser.UserName,
                                              CurrentController,
                                              e.Message));

                AddDangerNotification(string.Format(Notifications.Fail));
                return(Redirect("/"));
            }
        }
Esempio n. 3
0
        public async Task <IViewComponentResult> InvokeAsync(string storyId)
        {
            ConnectRouteAndStoryInputModel model = new ConnectRouteAndStoryInputModel();

            model.StoryId = storyId;

            User user = await this.userManager.GetUserAsync(this.UserClaimsPrincipal);

            this.TempData["routeList"] = user.Routes.ToList();

            return(View(model));
        }