public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsOrgAdmin()
        {
            var applicationUser = new ApplicationUser();

            applicationUser.MakeOrgAdmin();
            //applicationUser.Claims.Add(new IdentityUserClaim<string>
            //{
            //    ClaimType = AllReady.Security.ClaimTypes.UserType,
            //    ClaimValue = Enum.GetName(typeof(UserType), UserType.OrgAdmin)
            //});

            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false);

            var routeValueDictionary = new RouteValueDictionary
            {
                ["area"] = "Admin"
            };

            var sut    = new RedirectAccountControllerRequests();
            var result = sut.RedirectToLocal(It.IsAny <string>(), applicationUser, urlHelper.Object) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(AllReady.Areas.Admin.Controllers.CampaignController.Index));
            Assert.Equal(result.ControllerName, "Campaign");
            Assert.Equal(result.RouteValues, routeValueDictionary);
        }
        public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsNotASiteOrAnOrgAdmin()
        {
            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false);

            var sut    = new RedirectAccountControllerRequests(urlHelper.Object);
            var result = sut.RedirectToLocal(It.IsAny <string>(), new ApplicationUser()) as RedirectToPageResult;

            Assert.Equal(result.PageName, "/Index");
        }
        public void InvokeIsLocalUrlWithCorrectReturnUrl()
        {
            const string returnUrl = "ReturnUrl";
            var          urlHelper = new Mock <IUrlHelper>();

            var sut = new RedirectAccountControllerRequests(urlHelper.Object);

            sut.RedirectToLocal(returnUrl, null);

            urlHelper.Verify(x => x.IsLocalUrl(returnUrl), Times.Once);
        }
        public void RedirectToReturnUrl_WhenReturnUrlIsALocalUrl()
        {
            const string returnUrl = "ReturnUrl";

            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(true);

            var sut    = new RedirectAccountControllerRequests(urlHelper.Object);
            var result = sut.RedirectToLocal(returnUrl, null) as RedirectResult;

            Assert.Equal(result.Url, returnUrl);
        }
Exemple #5
0
        public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsNotASiteOrAnOrgAdmin()
        {
            var applicationUser = new ApplicationUser();

            applicationUser.Claims.Add(new IdentityUserClaim <string>
            {
                ClaimType  = AllReady.Security.ClaimTypes.UserType,
                ClaimValue = Enum.GetName(typeof(UserType), UserType.BasicUser)
            });

            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false);

            var sut    = new RedirectAccountControllerRequests();
            var result = sut.RedirectToLocal(It.IsAny <string>(), applicationUser, urlHelper.Object) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(HomeController.Index));
            Assert.Equal(result.ControllerName, "Home");
            Assert.Equal(result.RouteValues, null);
        }
        public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsOrgAdmin()
        {
            var applicationUser = new ApplicationUser();

            applicationUser.MakeOrgAdmin();

            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false);

            var routeValueDictionary = new RouteValueDictionary
            {
                ["area"] = AreaNames.Admin
            };

            var sut    = new RedirectAccountControllerRequests(urlHelper.Object);
            var result = sut.RedirectToLocal(It.IsAny <string>(), applicationUser) as RedirectToActionResult;

            Assert.Equal(nameof(AllReady.Areas.Admin.Controllers.CampaignController.Index), result.ActionName);
            Assert.Equal("Campaign", result.ControllerName);
            Assert.Equal(result.RouteValues, routeValueDictionary);
        }
        public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsSiteAdmin()
        {
            var applicationUser = new ApplicationUser();

            applicationUser.MakeSiteAdmin();

            var urlHelper = new Mock <IUrlHelper>();

            urlHelper.Setup(x => x.IsLocalUrl(It.IsAny <string>())).Returns(false);

            var routeValueDictionary = new RouteValueDictionary
            {
                ["area"] = "Admin"
            };

            var sut    = new RedirectAccountControllerRequests(urlHelper.Object);
            var result = sut.RedirectToLocal(It.IsAny <string>(), applicationUser) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(SiteController.Index));
            Assert.Equal(result.ControllerName, "Site");
            Assert.Equal(result.RouteValues, routeValueDictionary);
        }