/// <summary>
        /// Logs out the user in session.
        /// </summary>
        /// <param name="returnUrl">The return URL.</param>
        /// <returns></returns>
        public ActionResult LogOut(string returnUrl)
        {
            IUserContext userContext = SessionHandler.UserContext;

            if (userContext != null)
            {
                if (SessionHandler.MySettings != null)
                {
                    MySettingsManager.SaveLastSettings(userContext, SessionHandler.MySettings);
                    MySettingsManager.SaveToDisk(userContext, MySettingsManager.SettingsName, SessionHandler.MySettings);
                }

                CoreData.UserManager.Logout(userContext);
                SessionHandler.UserContext = null;
                // When logged out mySettings must be cleared
                SessionHandler.MySettings = new MySettings();
                FormsService.SignOut();
            }

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#2
0
        private void Session_End(object sender, EventArgs e)
        {
            var userContext = Session["userContext"] as IUserContext;
            var mySettings  = Session["mySettings"] as MySettings;

            if (userContext != null && mySettings != null)
            {
                LastUserSessionIdManager.UpdateLastUserSessionId(userContext.User.UserName, Session.SessionID);
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                MySettingsManager.SaveToDisk(userContext, MySettingsManager.SettingsName, mySettings);
            }
        }
        // This test expects that it can write to "C:\Temp\myTempFile.txt".
        public void DoesLastSettingsExist_SettingsExists_ReturnTrue()
        {
            using (ShimsContext.Create())
            {
                ShimFilePath();
                IUserContext userContext;
                Boolean      doesLastSettingsExist;
                AnalysisPortal.MySettings.MySettings mySettings;

                // Arrange
                userContext = GetTestUserContext();
                mySettings  = CreateMySettingsObjectWithTaxonFilter(1, 2, 5);

                // Act
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                doesLastSettingsExist = MySettingsManager.DoesLastSettingsExist(userContext);

                // Assert
                Assert.IsTrue(doesLastSettingsExist);
            }
        }
        // This test expects that it can write to "C:\Temp\myTempFile.txt"
        public void GetLastSettingsSaveTime_LastSettingsExists_ReturnDateTimeNow()
        {
            using (ShimsContext.Create())
            {
                ShimFilePath();
                IUserContext userContext;
                AnalysisPortal.MySettings.MySettings mySettings;
                DateTime?lastSettingsSaveTime;

                // Arrange
                userContext = GetTestUserContext();
                mySettings  = CreateMySettingsObjectWithTaxonFilter(1, 2, 5);

                // Act
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                lastSettingsSaveTime = MySettingsManager.GetLastSettingsSaveTime(userContext);
                TimeSpan timeSpan = DateTime.Now - lastSettingsSaveTime.Value;

                // Assert
                Assert.IsTrue(timeSpan.TotalMilliseconds < 1000);
            }
        }
        // This test expects that it can write to "C:\Temp\myTempFile.txt"
        public void SaveAndGetLastUsedSettings_CreateMySettingsWithTaxa_LastSettingsSavedToFileAndReturnedOnLoad()
        {
            using (ShimsContext.Create())
            {
                ShimFilePath();

                IUserContext userContext;
                AnalysisPortal.MySettings.MySettings mySettings;
                AnalysisPortal.MySettings.MySettings loadedSettings;

                // Arrange
                userContext = GetTestUserContext();
                mySettings  = CreateMySettingsObjectWithTaxonFilter(1, 2, 5);

                // Act
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                loadedSettings = MySettingsManager.LoadLastSettings(userContext);

                // Assert
                CollectionAssert.AreEqual(new List <int> {
                    1, 2, 5
                }, loadedSettings.Filter.Taxa.TaxonIds);
            }
        }
        // This test expects that it can write to "C:\Temp\myTempFile.txt"
        public void SaveLastSettings_SaveTwoTimes_LastSavedSettingsIsOverwritten()
        {
            using (ShimsContext.Create())
            {
                ShimFilePath();
                IUserContext userContext;
                AnalysisPortal.MySettings.MySettings mySettings;
                AnalysisPortal.MySettings.MySettings loadedSettings;

                // Arrange
                userContext = GetTestUserContext();
                mySettings  = CreateMySettingsObjectWithTaxonFilter(1, 2, 5);

                // Act
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                loadedSettings = MySettingsManager.LoadLastSettings(userContext);

                // Assert
                CollectionAssert.AreEqual(new List <int> {
                    1, 2, 5
                }, loadedSettings.Filter.Taxa.TaxonIds);


                // Arrange
                mySettings = CreateMySettingsObjectWithTaxonFilter(10, 12, 22);

                // Act
                MySettingsManager.SaveLastSettings(userContext, mySettings);
                loadedSettings = MySettingsManager.LoadLastSettings(userContext);

                // Assert
                CollectionAssert.AreEqual(new List <int> {
                    10, 12, 22
                }, loadedSettings.Filter.Taxa.TaxonIds);
            }
        }