Exemple #1
0
        public void Allowed_Accesses_IAuthenticationService_If_ProtectionLevel_Is_Protected()
        {
            // Arrange
            var mockAuthenticationService = new Mock <IAuthenticationService>();
            var mockAuthorizationService  = new Mock <IAuthorizationService>();
            var protectionAttribute       = new ProtectionAttribute(ProtectionLevel.Protected);

            // Act
            protectionAttribute.Allowed(mockAuthenticationService.Object, mockAuthorizationService.Object);

            // Assert
            mockAuthenticationService.Verify(service => service.IsAuthenticCredential, Times.AtLeastOnce());
        }
Exemple #2
0
        public void Allowed_Not_Accesses_IAuthorizationService_If_ProtectionLevel_Is_Protected()
        {
            // Arrange
            var mockAuthenticationService = new Mock <IAuthenticationService>();
            var mockAuthorizationService  = new Mock <IAuthorizationService>();
            var protectionAttribute       = new ProtectionAttribute(ProtectionLevel.Protected);

            // Act
            protectionAttribute.Allowed(mockAuthenticationService.Object, mockAuthorizationService.Object);

            // Assert
            mockAuthorizationService.Verify(service => service.AllowUnsignedAction, Times.Never());
            mockAuthorizationService.Verify(service => service.HasRequiredPermissions(new string[] {}), Times.Never());
        }
Exemple #3
0
        public void Not_Allowed_If_Not_Authenticated_In_ProtectionLevel_Protected()
        {
            // Arrange
            var mockAuthenticationService = new Mock <IAuthenticationService>();
            var mockAuthorizationService  = new Mock <IAuthorizationService>();
            var protectionAttribute       = new ProtectionAttribute(ProtectionLevel.Protected);

            mockAuthenticationService.Setup(service => service.IsAuthenticCredential).Returns(false);

            // Act
            var result = protectionAttribute.Allowed(mockAuthenticationService.Object, mockAuthorizationService.Object);

            // Assert
            Assert.Equal(false, result);
        }