From: Griffin C. <gc...@us...> - 2006-06-06 03:07:29
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Security/Principal In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv6076/DotNetMock.Framework/Security/Principal Modified Files: MockIIdentity.cs MockIPrincipal.cs Log Message: - Initial conversion to .NET 2.0 and VIsual Studio 2005 Index: MockIPrincipal.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Security/Principal/MockIPrincipal.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockIPrincipal.cs 5 Feb 2005 22:05:09 -0000 1.5 --- MockIPrincipal.cs 6 Jun 2006 03:06:52 -0000 1.6 *************** *** 1,105 **** - using System; using System.Collections; using System.Security.Principal; - using DotNetMock; namespace DotNetMock.Framework.Security.Principal { ! /// <summary> ! /// Mock Object to implement the IPrincipal interface ! /// </summary> ! public class MockIPrincipal : MockObject, IPrincipal ! { ! /// <summary> ! /// Current Identity associated with this Principal ! /// </summary> ! private IIdentity _expectedIdentity = null; ! /// <summary> ! /// Expected number of IsInRole() calls ! /// </summary> ! private ExpectationCounter _isInRoleCalls = new ExpectationCounter("MockIPrincipal.IsIsRoleCalls"); ! /// <summary> ! /// Lists of roles the current Principal belongs to ! /// </summary> ! private ArrayList _roles = null; ! /// <summary> ! /// Default Constructor ! /// </summary> ! public MockIPrincipal() : base("MockIPrincipal") ! { ! _roles = new ArrayList(); ! } ! #region MockMethods ! /// <summary> ! /// Sets the expected value of Identity to return ! /// </summary> ! /// <param name="identity">Identity for current Principal</param> ! public void SetExpectedIdentity( IIdentity identity ) ! { ! _expectedIdentity = identity; ! } ! /// <summary> ! /// Sets the number of calls to IsInRole() ! /// </summary> ! /// <param name="count">expected number of calls to IsInRol()</param> ! public void SetExpectedIsInRoleCount( int count ) ! { ! _isInRoleCalls.Expected = count; ! } ! /// <summary> ! /// Adds the given role to the list of roles this Principal belongs to ! /// </summary> ! /// <param name="role">role to add</param> ! public void AddExpectedRole( string role ) ! { ! _roles.Add( role ); ! } ! /// <summary> ! /// Adds the given roles to the list of roles this Principal belongs to ! /// </summary> ! /// <param name="roles"></param> ! public void AddExpectedRoles( string[] roles ) ! { ! for (int i = 0; i < roles.Length; i++) ! { ! AddExpectedRole( roles[i] ); ! } ! } ! #endregion ! #region Implementation of IPrincipal ! /// <summary> ! /// Returns true/false if the current principal belongs to the given role ! /// </summary> ! /// <param name="roleToSearch">Role to check for</param> ! /// <returns>True/False</returns> ! public bool IsInRole(string roleToSearch) ! { ! _isInRoleCalls.Inc(); ! bool found = false; ! foreach (string role in _roles) ! { ! if (role.Equals(roleToSearch)) ! { ! found = true; ! } ! } ! return found; ! } ! /// <summary> ! /// Returns the current Identity associated with this Principal ! /// </summary> ! public System.Security.Principal.IIdentity Identity ! { ! get ! { ! if (_expectedIdentity == null) ! { ! return new MockIIdentity(); ! } ! return _expectedIdentity; ! } ! } ! #endregion ! } ! } --- 1,115 ---- using System.Collections; using System.Security.Principal; namespace DotNetMock.Framework.Security.Principal { ! /// <summary> ! /// Mock Object to implement the IPrincipal interface ! /// </summary> ! public class MockIPrincipal : MockObject, IPrincipal ! { ! /// <summary> ! /// Current Identity associated with this Principal ! /// </summary> ! private IIdentity _expectedIdentity = null; ! /// <summary> ! /// Expected number of IsInRole() calls ! /// </summary> ! private ExpectationCounter _isInRoleCalls = new ExpectationCounter("MockIPrincipal.IsIsRoleCalls"); ! ! /// <summary> ! /// Lists of roles the current Principal belongs to ! /// </summary> ! private ArrayList _roles = null; ! ! /// <summary> ! /// Default Constructor ! /// </summary> ! public MockIPrincipal() : base("MockIPrincipal") ! { ! _roles = new ArrayList(); ! } ! ! #region MockMethods ! ! /// <summary> ! /// Sets the expected value of Identity to return ! /// </summary> ! /// <param name="identity">Identity for current Principal</param> ! public void SetExpectedIdentity(IIdentity identity) ! { ! _expectedIdentity = identity; ! } ! ! /// <summary> ! /// Sets the number of calls to IsInRole() ! /// </summary> ! /// <param name="count">expected number of calls to IsInRol()</param> ! public void SetExpectedIsInRoleCount(int count) ! { ! _isInRoleCalls.Expected = count; ! } ! ! /// <summary> ! /// Adds the given role to the list of roles this Principal belongs to ! /// </summary> ! /// <param name="role">role to add</param> ! public void AddExpectedRole(string role) ! { ! _roles.Add(role); ! } ! ! /// <summary> ! /// Adds the given roles to the list of roles this Principal belongs to ! /// </summary> ! /// <param name="roles"></param> ! public void AddExpectedRoles(string[] roles) ! { ! for (int i = 0; i < roles.Length; i++) ! { ! AddExpectedRole(roles[i]); ! } ! } ! ! #endregion ! ! #region Implementation of IPrincipal ! ! /// <summary> ! /// Returns true/false if the current principal belongs to the given role ! /// </summary> ! /// <param name="roleToSearch">Role to check for</param> ! /// <returns>True/False</returns> ! public bool IsInRole(string roleToSearch) ! { ! _isInRoleCalls.Inc(); ! bool found = false; ! foreach (string role in _roles) ! { ! if (role.Equals(roleToSearch)) ! { ! found = true; ! } ! } ! return found; ! } ! ! /// <summary> ! /// Returns the current Identity associated with this Principal ! /// </summary> ! public IIdentity Identity ! { ! get ! { ! if (_expectedIdentity == null) ! { ! return new MockIIdentity(); ! } ! return _expectedIdentity; ! } ! } ! ! #endregion ! } ! } \ No newline at end of file Index: MockIIdentity.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Security/Principal/MockIIdentity.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MockIIdentity.cs 5 Feb 2005 22:05:09 -0000 1.5 --- MockIIdentity.cs 6 Jun 2006 03:06:52 -0000 1.6 *************** *** 1,90 **** - using System; - using DotNetMock; using System.Security.Principal; namespace DotNetMock.Framework.Security.Principal { ! /// <summary> ! /// MockObject implementing the IIdentity interface. Since the IIdentity interface only includes getters, ! /// this MockObject does not do much. ! /// </summary> ! public class MockIIdentity : MockObject, IIdentity ! { ! /// <summary> ! /// The expected AuthenticationType ! /// </summary> ! private string _expectedAuthType = ""; ! /// <summary> ! /// The expected Name ! /// </summary> ! private string _expectedName = ""; ! /// <summary> ! /// The expected value for IsAuthenticated ! /// </summary> ! private bool _expectedIsAuth = false; ! /// <summary> ! /// Default Constructor ! /// </summary> ! public MockIIdentity() : base("MockIdentity") ! { ! } ! #region Mock Methods ! /// <summary> ! /// Sets the expected AuthenticationType value to return ! /// </summary> ! /// <param name="authType">Authentication Type to return</param> ! public void SetExpectedAuthenticationType( string authType ) ! { ! _expectedAuthType = authType; ! } ! /// <summary> ! /// Sets the expected IsAuthenticated value to return ! /// </summary> ! /// <param name="isAuth">IsAuthenticated value to return</param> ! public void SetExpectedIsAuthenticated( bool isAuth ) ! { ! _expectedIsAuth = isAuth; ! } ! /// <summary> ! /// Sets the expected Name value to return ! /// </summary> ! /// <param name="name">Name value to return</param> ! public void SetExpectedName( string name ) ! { ! _expectedName = name; ! } ! #endregion ! #region Implementation of IIdentity ! /// <summary> ! /// Returns true/false if the current Identity is Authenticated or not ! /// </summary> ! public bool IsAuthenticated ! { ! get ! { ! return _expectedIsAuth; ! } ! } ! /// <summary> ! /// Returns the name of the current Identity ! /// </summary> ! public string Name ! { ! get ! { ! return _expectedName; ! } ! } ! /// <summary> ! /// Returns the current Authentication Type ! /// </summary> ! public string AuthenticationType ! { ! get ! { ! return _expectedAuthType; ! } ! } ! #endregion ! } ! } --- 1,92 ---- using System.Security.Principal; namespace DotNetMock.Framework.Security.Principal { ! /// <summary> ! /// MockObject implementing the IIdentity interface. Since the IIdentity interface only includes getters, ! /// this MockObject does not do much. ! /// </summary> ! public class MockIIdentity : MockObject, IIdentity ! { ! /// <summary> ! /// The expected AuthenticationType ! /// </summary> ! private string _expectedAuthType = ""; ! ! /// <summary> ! /// The expected Name ! /// </summary> ! private string _expectedName = ""; ! ! /// <summary> ! /// The expected value for IsAuthenticated ! /// </summary> ! private bool _expectedIsAuth = false; ! ! /// <summary> ! /// Default Constructor ! /// </summary> ! public MockIIdentity() : base("MockIdentity") ! { ! } ! ! #region Mock Methods ! ! /// <summary> ! /// Sets the expected AuthenticationType value to return ! /// </summary> ! /// <param name="authType">Authentication Type to return</param> ! public void SetExpectedAuthenticationType(string authType) ! { ! _expectedAuthType = authType; ! } ! ! /// <summary> ! /// Sets the expected IsAuthenticated value to return ! /// </summary> ! /// <param name="isAuth">IsAuthenticated value to return</param> ! public void SetExpectedIsAuthenticated(bool isAuth) ! { ! _expectedIsAuth = isAuth; ! } ! ! /// <summary> ! /// Sets the expected Name value to return ! /// </summary> ! /// <param name="name">Name value to return</param> ! public void SetExpectedName(string name) ! { ! _expectedName = name; ! } ! ! #endregion ! ! #region Implementation of IIdentity ! ! /// <summary> ! /// Returns true/false if the current Identity is Authenticated or not ! /// </summary> ! public bool IsAuthenticated ! { ! get { return _expectedIsAuth; } ! } ! ! /// <summary> ! /// Returns the name of the current Identity ! /// </summary> ! public string Name ! { ! get { return _expectedName; } ! } ! ! /// <summary> ! /// Returns the current Authentication Type ! /// </summary> ! public string AuthenticationType ! { ! get { return _expectedAuthType; } ! } ! ! #endregion ! } ! } \ No newline at end of file |