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()); }
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()); }
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); }