Ejemplo n.º 1
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        private AllsrvConnector()
        {
            IAdminSession IAS = null;

            // Call into AGCLib to get the AdminSession
            int ErrorCode = GetAdminSession(out IAS);

            if (ErrorCode != 0)
            {
                throw new ApplicationException("Attempt to retrieve Admin Session failed. Error " + ErrorCode.ToString());
            }

            _session = IAS;
            TagTrace.WriteLine(TraceLevel.Verbose, "Admin Session retrieved from Allsrv.");

            // Hook into events
            UCOMIConnectionPointContainer uCOMIConnectionPointContainer = (UCOMIConnectionPointContainer)_session;

            uCOMIConnectionPointContainer.FindConnectionPoint(ref _sessionGuid, out _icp);
            _cookie = 0;
            _icp.Advise(this, out _cookie);
            _session.ActivateAllEvents();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Disconnects from Allsrv
        /// </summary>
        public void Disconnect()
        {
            if (_cookie != 0)
            {
                _connector = null;

                try
                {
                    _session.DeactivateAllEvents();
                }
                catch (Exception)
                {
                    // An exception will be thrown if the session has already been detached
                    // Ignore it!
                    TagTrace.WriteLine(TraceLevel.Verbose, "Error while attempting to detach session. Session is already destroyed.");
                }
                finally
                {
                    _session = null;
                }

                try
                {
                    _icp.Unadvise(_cookie);
                }
                catch (Exception e)
                {
                    // Ignore exceptions if we're already detached
                    TagTrace.WriteLine(TraceLevel.Verbose, "Error while disposing session. Session is already disposed.", e.Message);
                }
                finally
                {
                    _cookie = 0;
                }
            }
        }
Ejemplo n.º 3
0
        public AccountControllerTest()
        {
            Mock <IUserRepository> mockRep = new Mock <IUserRepository>();

            mockRep.Setup(m => m.FindAll()).Returns(new List <UserModel> {
                new UserModel {
                    Id = 1, UserName = "******", Password = "******"
                }
            });

            mockRep.Setup(m => m.FindByUserName(It.Is <string>(name => name == "chenmeiyi"))).Returns(new UserModel {
                Id       = 1,
                UserName = "******",
                Password = "******"
            });

            mockRep.Setup(m => m.IsValid(It.Is <string>(userName => userName == "chenmeiyi"), It.Is <string>(password => password == "cmy123456"))).Returns(true);

            var mockSession = new Mock <IAdminSession>();

            _userRepository = mockRep.Object;

            _adminSession = mockSession.Object;
        }