Inheritance: MaverickController
Exemplo n.º 1
0
        public void Land_Calls_GetReturnUrl_With_ControllerContext_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            controller.Land(SelectedMockIdentitySource);

            // Assert
            mockSource.Verify(s => s.GetReturnUrl(controller.ControllerContext));
        }
Exemplo n.º 2
0
        private static void TestExpectedNotFoundResult(Func<IdentityController, ActionResult> action)
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);
            controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult result = action(controller);

            // Assert
            ResultAssert.IsResourceNotFound(result);
        }
Exemplo n.º 3
0
        public void Logout_Redirects_To_Home_Page()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            // Act
            ActionResult result = controller.Logout();

            // Assert
            ResultAssert.IsRedirectToRoute(result, new {controller = "Page", action = "View", page = (Page)null});
        }
Exemplo n.º 4
0
        public void Logout_Removes_Session_Token()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            // Act
            controller.Logout();

            // Assert
            mockSessionManager.Verify(s => s.ClearSessionPrincipal());
        }
Exemplo n.º 5
0
        public void LoginPost_Returns_Result_Of_OnLoginFormSubmit()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            EmptyResult expectedResult = new EmptyResult();
            mockSource.Setup(s => s.OnLoginFormSubmit(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(expectedResult);

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            Assert.AreSame(expectedResult, actualResult);
        }
Exemplo n.º 6
0
        public void Logout_Calls_IdentitySource_To_Logout_If_Token_Contains_IdentifiedBy_Claim_Matching_Valid_IdentitySource()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            var mockSessionManager = new Mock<ISessionIdentityManager>();
            controller.SessionIdentityManager = mockSessionManager.Object;

            Claim claim = new Claim(MaverickClaimTypes.IdentifiedBy, SelectedMockIdentitySource);
            IPrincipal oldPrincipal = Thread.CurrentPrincipal;
            Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claim));

            // Act
            controller.Logout();

            // Assert
            mockSource.Verify(s => s.Logout(controller.ControllerContext));

            // Cleanup
            Thread.CurrentPrincipal = oldPrincipal;
        }
Exemplo n.º 7
0
        public void LoginPost_Calls_OnLoginFormSubmit_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            mockSource.Verify(s => s.OnLoginFormSubmit(controller.ControllerContext, TestReturnUrl));
        }
Exemplo n.º 8
0
        public void LoginPost_Does_Not_Alter_ViewName_If_It_Starts_With_Tilde()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            mockSource.Setup(s => s.OnLoginFormSubmit(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(new ViewResult { ViewName = TestExplicitViewName });

            // Act
            ActionResult actualResult = controller.LoginPost(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            ResultAssert.IsView(actualResult, TestExplicitViewName, ExpectedMasterName);
        }
Exemplo n.º 9
0
        public void LoginGet_Returns_Result_Of_IdentitySource_Login()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            EmptyResult expectedResult = new EmptyResult();
            mockSource.Setup(s => s.Login(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(expectedResult);

            // Act
            ActionResult actualResult = controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            Assert.AreSame(expectedResult, actualResult, "Expected that the result of Login would be passed unmodified");
        }
Exemplo n.º 10
0
        public void LoginGet_Calls_Login_With_ControllerContext_And_ReturnUrl_If_IdentitySource_Found()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            mockSource.Verify(s => s.Login(controller.ControllerContext, TestReturnUrl));
        }
Exemplo n.º 11
0
        public void LoginGet_Alters_Master_And_View_Name_If_Result_Is_ViewResult()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            mockSource.Setup(s => s.Login(It.IsAny<ControllerContext>(), TestReturnUrl))
                      .Returns(new ViewResult {ViewName = TestViewName});

            // Act
            ActionResult actualResult = controller.LoginGet(SelectedMockIdentitySource, TestReturnUrl.ToString());

            // Assert
            ResultAssert.IsView(actualResult, ExpectedViewName, ExpectedMasterName);
        }
Exemplo n.º 12
0
        public void Land_Redirects_To_ReturnUrl_If_Present()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);
            mockSource.Setup(s => s.GetReturnUrl(It.IsAny<ControllerContext>()))
                      .Returns(TestReturnUrl);

            // Act
            ActionResult result = controller.Land(SelectedMockIdentitySource);

            // Assert
            ResultAssert.IsRedirect(result, TestReturnUrl.ToString());
        }
Exemplo n.º 13
0
        public void Land_Redirects_To_HomePage_If_No_Return_Url()
        {
            // Arrange
            var controller = new IdentityController();
            controller.IdentitySources.AddMock(UnusedMockIdentitySource);

            var mockSource = controller.IdentitySources.AddMock(SelectedMockIdentitySource);

            // Act
            ActionResult result = controller.Land(SelectedMockIdentitySource);

            // Assert
            ResultAssert.IsRedirectToRoute(result, new {controller = "Page", action = "View", page = (Page)null});
        }