Exemplo n.º 1
0
        public async Task Delete_ShouldReturnRedirect_IfNotAuthorAndNotAdmin()
        {
            user.Stories = new List <Story>();
            var service = new Mock <IStoryService>();

            StoriesController controller = new StoriesController(
                service.Object, userManager.Object, logger)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                        {
                            new Claim(ClaimTypes.Role, "User")
                        })),
                    },
                },
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };
            var result = await controller.Delete("testId");

            result.ShouldNotBeNull();
            var viewResult = Assert.IsAssignableFrom <RedirectResult>(result);

            viewResult.Url.ShouldBe("/Stories/Details/testId");
            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");
        }