|
| 1 | +using WebExpress.WebCore.WebIdentity; |
| 2 | +using WebExpress.WebCore.WebMessage; |
| 3 | +using WebExpress.WebCore.WebPage; |
| 4 | + |
| 5 | +namespace WebExpress.WebCore.Test.Data |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Provides a mock implementation of the IIdentityProvider interface for testing purposes. |
| 9 | + /// </summary> |
| 10 | + /// <remarks> |
| 11 | + /// This class simulates an identity provider by allowing test code to manage in-memory |
| 12 | + /// collections of identities and groups. It is intended for use in unit tests or development scenarios where a real |
| 13 | + /// identity provider is not required. |
| 14 | + /// </remarks> |
| 15 | + public class MockIdentityProvider : IIdentityProvider |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Gets the collection of identities associated with the current principal. |
| 19 | + /// </summary> |
| 20 | + public List<IIdentity> Identities { get; } = []; |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Gets the collection of identity groups associated with the current user or entity. |
| 24 | + /// </summary> |
| 25 | + public List<IIdentityGroup> Groups { get; } = []; |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Returns a collection of all associated identities for the current principal. |
| 29 | + /// </summary> |
| 30 | + /// <returns> |
| 31 | + /// An enumerable collection of <see cref="IIdentity"/> objects representing the identities associated with the |
| 32 | + /// principal. The collection may be empty if no identities are present. |
| 33 | + /// </returns> |
| 34 | + public IEnumerable<IIdentity> GetIdentities() => Identities; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Retrieves a collection of identity groups associated with the current context. |
| 38 | + /// </summary> |
| 39 | + /// <returns> |
| 40 | + /// An enumerable collection of objects that implement the IIdentityGroup interface. The collection may be empty |
| 41 | + /// if no groups are associated. |
| 42 | + /// </returns> |
| 43 | + public IEnumerable<IIdentityGroup> GetGroups() => Groups; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Authenticates the specified request and returns the associated identity. |
| 47 | + /// </summary> |
| 48 | + /// <param name="request"> |
| 49 | + /// The request to authenticate. Cannot be null. |
| 50 | + /// </param> |
| 51 | + /// <returns> |
| 52 | + /// An identity representing the authenticated user if authentication is successful; otherwise, null. |
| 53 | + /// </returns> |
| 54 | + public IIdentity Authenticate(IRequest request) |
| 55 | + { |
| 56 | + return null; // not needed for this test |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Logs out the specified request by clearing any authentication state. |
| 61 | + /// </summary> |
| 62 | + /// <param name="request"> |
| 63 | + /// The request whose authentication state should be cleared. Cannot be null. |
| 64 | + /// </param> |
| 65 | + public void Logout(IRequest request) |
| 66 | + { |
| 67 | + // not needed for this test |
| 68 | + } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Displays a login dialog using the specified request and identity information. |
| 72 | + /// </summary> |
| 73 | + /// <param name="request"> |
| 74 | + /// The request containing parameters and context for the login operation. Cannot be null. |
| 75 | + /// </param> |
| 76 | + /// <param name="initiator"> |
| 77 | + /// The endpoint that triggered the authentication process. Used to determine the origin and |
| 78 | + /// context of the authentication requirement. |
| 79 | + /// </param> |
| 80 | + /// <param name="identity"> |
| 81 | + /// The identity information to be used for authentication. Cannot be null. |
| 82 | + /// </param> |
| 83 | + /// <returns> |
| 84 | + /// An object that represents the response to the login dialog, including authentication results and any |
| 85 | + /// relevant status information. |
| 86 | + /// </returns> |
| 87 | + public IResponse CreateAuthenticationPrompt(IRequest request, IPageContext initiator, IIdentity identity) |
| 88 | + { |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Creates a forbidden response page for the specified request when the authenticated |
| 94 | + /// user lacks the required permissions to access the requested resource. |
| 95 | + /// </summary> |
| 96 | + /// <param name="request"> |
| 97 | + /// The request for which access was denied. Cannot be null. |
| 98 | + /// </param> |
| 99 | + /// <param name="initiator"> |
| 100 | + /// The endpoint that the user attempted to access. |
| 101 | + /// </param> |
| 102 | + /// <param name="identity"> |
| 103 | + /// The authenticated identity that lacks sufficient permissions. |
| 104 | + /// </param> |
| 105 | + /// <returns> |
| 106 | + /// A response representing the forbidden page if this provider can handle the forbidden |
| 107 | + /// scenario; otherwise, <c>null</c>. |
| 108 | + /// </returns> |
| 109 | + public IResponse CreateForbiddenPage(IRequest request, IPageContext initiator, IIdentity identity) |
| 110 | + { |
| 111 | + return null; |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments