Ejemplo n.º 1
0
        public void should_use_authorizationprovider()
        {
            // Arrange
            EditorRequiredAttributeMock attribute = new EditorRequiredAttributeMock();

            attribute.AuthorizationProvider = new AuthorizationProviderMock()
            {
                IsEditorResult = true
            };
            attribute.ApplicationSettings = _applicationSettings;
            attribute.UserService         = _userService;

            IdentityStub identity = new IdentityStub()
            {
                Name = Guid.NewGuid().ToString(), IsAuthenticated = true
            };
            PrincipalStub principal = new PrincipalStub()
            {
                Identity = identity
            };
            HttpContextBase context = GetHttpContext(principal);

            // Act
            bool isAuthorized = attribute.CallAuthorize(context);

            // Assert
            Assert.That(isAuthorized, Is.True);
        }
		public void Should_Throw_SecurityException_When_AuthorizationProvider_Is_Null()
		{
			// Arrange
			EditorRequiredAttributeMock attribute = new EditorRequiredAttributeMock();
			attribute.AuthorizationProvider = null;

			IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true };
			PrincipalStub principal = new PrincipalStub() { Identity = identity };
			HttpContextBase context = GetHttpContext(principal);

			// Act + Assert
			attribute.CallAuthorize(context);
		}
		public void should_use_authorizationprovider()
		{
			// Arrange
			EditorRequiredAttributeMock attribute = new EditorRequiredAttributeMock();
			attribute.AuthorizationProvider = new AuthorizationProviderMock() { IsEditorResult = true };
			attribute.ApplicationSettings = _applicationSettings;
			attribute.UserService = _userService;

			IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true };
			PrincipalStub principal = new PrincipalStub() { Identity = identity };
			HttpContextBase context = GetHttpContext(principal);

			// Act
			bool isAuthorized = attribute.CallAuthorize(context);

			// Assert
			Assert.That(isAuthorized, Is.True);
		}
Ejemplo n.º 4
0
        public void Should_Throw_SecurityException_When_AuthorizationProvider_Is_Null()
        {
            // Arrange
            EditorRequiredAttributeMock attribute = new EditorRequiredAttributeMock();

            attribute.AuthorizationProvider = null;

            IdentityStub identity = new IdentityStub()
            {
                Name = Guid.NewGuid().ToString(), IsAuthenticated = true
            };
            PrincipalStub principal = new PrincipalStub()
            {
                Identity = identity
            };
            HttpContextBase context = GetHttpContext(principal);

            // Act + Assert
            attribute.CallAuthorize(context);
        }