public void DeleteAllStatisticsTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } learnLogic.OnLearningModuleOptionsChanged(); learnLogic.ResetLearningProgress(); LearnStats learnStats = learnLogic.Dictionary.Statistics.GetCurrentStats(); Assert.AreEqual <int>(0, learnStats.NumberOfRights, "DeleteAllStatistics() did not delete all Stats!"); Assert.AreEqual <int>(0, learnStats.NumberOfWrongs, "DeleteAllStatistics() did not delete all Stats!"); Assert.IsTrue(learnLogic.Dictionary.Statistics.GetNewestStatistic().StartTimestamp == learnLogic.Dictionary.Statistics.GetOldestStatistic().StartTimestamp, "GetNewestStatistic() and GetOldestStatistic seems to be not equal. There should be only ONE stat in the restarted LM"); } }
public void DoubleLoginTest() { if (TestInfrastructure.IsActive(TestContext)) { switch (TestInfrastructure.ConnectionType(TestContext)) { case "File": case "sqlce": throw new DoubleLoginException(); default: break; } ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionString(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); learnLogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, connectionString, (DataAccessErrorDelegate) delegate { return; }); //Doesn't throw the Exception because the UserFactory logs out the previous user LearnLogic lLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); lLogic.User.Authenticate((GetLoginInformation)GetLoginErrorMethod, connectionString, (DataAccessErrorDelegate) delegate { return; }); //Check instead if old user is logged out properly if (!learnLogic.UserSessionAlive) { throw new DoubleLoginException(); } } else { throw new DoubleLoginException(); } }
/// <summary> /// Gets the connection string. /// </summary> /// <param name="testContex">The test contex.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-01-30</remarks> public static ConnectionStringStruct GetConnectionString(TestContext testContex) { using (Dictionary dictionary = TestInfrastructure.GetConnection(testContex)) { dictionary.Save(); return(dictionary.DictionaryDAL.Parent.CurrentUser.ConnectionString); } }
public static void MyClassCleanup() { try { Directory.Delete(TestFolder, true); } catch { } TestInfrastructure.MyClassCleanup(); }
/// <summary> /// Gets the connection string for LM with dummy data. /// </summary> /// <param name="testContex">The test contex.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-01-30</remarks> public static ConnectionStringStruct GetConnectionStringWithDummyData(TestContext testContext) { using (Dictionary dictionary = TestInfrastructure.GetConnection(testContext)) { DAL.ICardsTests.FillDummyDic(dictionary.DictionaryDAL); dictionary.Save(); MLifter.DAL.Log.CloseUserSession(dictionary.DictionaryDAL.Parent); return(dictionary.DictionaryDAL.Parent.CurrentUser.ConnectionString); } }
public static void FillDummyDic(Dictionary dictionary) { List <int> chapters = new List <int>(); for (int k = 0; k < 10; k++) { int chapterId = dictionary.Chapters.AddChapter("Chapter " + Convert.ToString(k + 1), "Chapter Description" + Convert.ToString(k + 1)); chapters.Add(chapterId); dictionary.QueryChapters.Add(chapterId); } for (int i = 0; i < TestInfrastructure.LoopCount; i++) { bool hasQImage = TestInfrastructure.RandomBool, hasAImage = TestInfrastructure.RandomBool; bool hasQAudio = TestInfrastructure.RandomBool, hasAAudio = TestInfrastructure.RandomBool; bool hasQEAudio = TestInfrastructure.RandomBool, hasAEAudio = TestInfrastructure.RandomBool; bool hasQVideo = TestInfrastructure.RandomBool, hasAVideo = TestInfrastructure.RandomBool; bool hasQExample = TestInfrastructure.RandomBool, hasAExample = TestInfrastructure.RandomBool; int cardId = dictionary.Cards.AddCard("question " + i, "answer " + i, (hasQExample) ? "question example " + i : String.Empty, (hasAExample) ? "answer example " + i : String.Empty, String.Empty, String.Empty, chapters[TestInfrastructure.Random.Next(0, chapters.Count)]); if (hasQImage) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestImage(), EMedia.Image, Side.Question, true, true, false); } if (hasAImage) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestImage(), EMedia.Image, Side.Answer, true, true, false); } if (hasQAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Question, true, true, false); } if (hasAAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Answer, true, true, false); } if (hasQEAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Question, true, false, true); } if (hasAEAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Answer, true, false, true); } if (hasQVideo) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestVideo(), EMedia.Video, Side.Question, true, true, false); } if (hasAVideo) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestVideo(), EMedia.Video, Side.Answer, true, true, false); } } }
public void LearnLogicLearnModeTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); //learnLogic.User.Authenticate(OpenUserProfileTests.GetUserAdmin, connectionString, (DataAccessErrorDelegate)delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") //success { return; } else { throw; } } learnLogic.User.Dictionary.Settings.QueryTypes.ImageRecognition = true; learnLogic.User.Dictionary.Settings.QueryTypes.ListeningComprehension = true; learnLogic.User.Dictionary.Settings.QueryTypes.Sentence = true; for (int i = 0; i < TestInfrastructure.LoopCount; i++) { learnLogic.OnLearningModuleOptionsChanged(); Card card = learnLogic.User.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); switch (learnLogic.User.Dictionary.LearnMode) { case LearnModes.ImageRecognition: Assert.IsTrue(card.ContainsImage(Side.Question.ToString()), "Card must contain image for ImageRecognition mode."); break; case LearnModes.ListeningComprehension: Assert.IsTrue(card.ContainsAudio(Side.Question.ToString()), "Card must contain audio for ListeningComprehension mode."); break; case LearnModes.Sentence: Assert.IsTrue(card.CurrentQuestionExample.Words.Count > 0, "Card must contain example for Sentence mode."); break; default: continue; } } } }
public void GetBoxContentTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); //learnLogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, // connectionString, (DataAccessErrorDelegate)delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } learnLogic.OnLearningModuleOptionsChanged(); learnLogic.ResetLearningProgress(); Card currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); //Answer Card correct UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, currentCard.CurrentAnswer.Words.Count, currentCard.CurrentAnswer.Words.Count, true, currentCard.CurrentAnswer.Words.ToString()); learnLogic.OnUserInputSubmit(this, e); learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs()); Assert.AreEqual <int>(1, learnLogic.Dictionary.Statistics.GetBoxContent(2, DateTime.Now.AddDays(1)), "GetBoxContent() did not return the correct number of cards"); for (int i = 1; i < 10; i++) { if (i == 2) { continue; } else { Assert.AreEqual <int>(0, learnLogic.Dictionary.Statistics.GetBoxContent(i, DateTime.Now.AddDays(1)), "GetBoxContent() says the Box " + i + " is NOT 0 (although it should)"); } } } }
public void CardStackUnitTest() { if (TestInfrastructure.IsActive(TestContext)) { using (Dictionary dictionary = TestInfrastructure.GetConnection(TestContext)) { DictionaryTest.FillDictionary(dictionary); CardStack target = new CardStack(new LearnLogic(MLifterTest.DAL.OpenUserProfileTests.GetUserAdmin, (MLifter.DAL.DataAccessErrorDelegate) delegate { return; })); target.StackChanged += new EventHandler(CardStack_StackChanged); cardstackChanged = false; target.Clear(); Assert.IsTrue(cardstackChanged, "CardStackChanged event did not fire for Clear."); int cardcount = 0; int rightcount = 0; TimeSpan duration = new TimeSpan(0); foreach (ICard card in dictionary.Cards.Cards) { for (int i = 0; i < 100; i++) { cardcount++; bool promoted = GetRandBool(); if (promoted) { rightcount++; } DateTime asked = DateTime.Now - new TimeSpan(0, 0, random.Next(1000)); DateTime answered = DateTime.Now; duration += (answered - asked); AnswerResult result = promoted ? AnswerResult.Correct : AnswerResult.Wrong; StackCard stackCard = new StackCard(card, result, promoted, EQueryDirection.Question2Answer, LearnModes.Word, asked, answered, Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentCulture, card.Answer.ToString(), 0, 0, false, dictionary, 0); cardstackChanged = false; target.Push(stackCard); Assert.IsTrue(cardstackChanged, "CardStackChanged event did not fire for Push."); } } Assert.AreEqual(cardcount, target.Count, "Not all cards were added to the stack."); Assert.AreEqual(duration, target.SessionDuration, "Session duration sum does not match."); Assert.AreEqual(rightcount, target.RightCount, "RightCount does not match."); Assert.AreEqual(cardcount - rightcount, target.WrongCount, "WrongCount does not match."); Assert.IsTrue(rightcount > 0 && target.VisibleStack.Count > 0, "No StackCards in VisibleStack property."); } } }
public void OpenLearningModuleCannotCloseTest() { if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext).ToLower() != "file") { LearnLogic llogic = new LearnLogic((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, (DataAccessErrorDelegate) delegate { return; }); LearningModulesIndexEntry module = new LearningModulesIndexEntry(); module.ConnectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); llogic.LearningModuleClosing += new LearnLogic.LearningModuleClosingEventHandler(llogic_LearningModuleClosing); llogic.OpenLearningModule(module); llogic.OpenLearningModule(module); } else { throw new CouldNotCloseLearningModuleException(); } }
public void GradeCardTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic llogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); //llogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, // connectionString, (DataAccessErrorDelegate)delegate { return; }); try { llogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } llogic.OnLearningModuleOptionsChanged(); Card card = llogic.Dictionary.Cards.GetCardByID(llogic.CurrentCardID); int oldBox = card.BaseCard.Box = 5; UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, card.CurrentAnswer.Words.Count, card.CurrentAnswer.Words.Count, true, card.CurrentAnswer.Words.ToString()); llogic.OnUserInputSubmit(this, e); Assert.AreEqual <int>(oldBox + 1, card.BaseCard.Box, "Card was not correctly promoted!"); card.BaseCard.Box = oldBox; e = new UserInputSubmitTextEventArgs(5, 0, 5, false, string.Empty); llogic.OnUserInputSubmit(this, e); Assert.AreEqual <int>(1, card.BaseCard.Box, "Card was not demoted!"); } }
public void GetCurrentStatsTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } learnLogic.OnLearningModuleOptionsChanged(); learnLogic.Dictionary.ResetLearningProgress(); //Answer Card correct Card currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, currentCard.CurrentAnswer.Words.Count, currentCard.CurrentAnswer.Words.Count, true, currentCard.CurrentAnswer.Words.ToString()); learnLogic.OnUserInputSubmit(this, e); learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs()); //Answer Card wrong currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); e = new UserInputSubmitTextEventArgs(0, 0, currentCard.CurrentAnswer.Words.Count, false, string.Empty); learnLogic.OnUserInputSubmit(this, e); learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs()); LearnStats stats = learnLogic.Dictionary.Statistics.GetCurrentStats(); Assert.AreEqual <int>(1, stats.NumberOfRights, "GetCurrentStats() did not return the correct LearnStats.NumberOfRights"); Assert.AreEqual <int>(1, stats.NumberOfWrongs, "GetCurrentStats() did not return the correct LearnStats.NumberOfWrongs"); } }
public void CardContainsMediaTest() { if (TestInfrastructure.IsActive(TestContext)) { using (Dictionary dictionary = TestInfrastructure.GetConnection(TestContext)) { int chapterId = dictionary.Chapters.AddChapter("test chapter", "test chapter Description"); for (int i = 0; i < TestInfrastructure.LoopCount; i++) { bool hasQImage = TestInfrastructure.RandomBool, hasAImage = TestInfrastructure.RandomBool; bool hasQAudio = TestInfrastructure.RandomBool, hasAAudio = TestInfrastructure.RandomBool; bool hasQEAudio = TestInfrastructure.RandomBool, hasAEAudio = TestInfrastructure.RandomBool; bool hasQVideo = TestInfrastructure.RandomBool, hasAVideo = TestInfrastructure.RandomBool; int cardId = dictionary.Cards.AddCard("question", "answer", "question example", "answer example", String.Empty, String.Empty, chapterId); if (hasQImage) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestImage(), EMedia.Image, Side.Question, true, true, false); } if (hasAImage) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestImage(), EMedia.Image, Side.Answer, true, true, false); } if (hasQAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Question, true, true, false); } if (hasAAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Answer, true, true, false); } if (hasQEAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Question, true, false, true); } if (hasAEAudio) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestAudio(), EMedia.Audio, Side.Answer, true, false, true); } if (hasQVideo) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestVideo(), EMedia.Video, Side.Question, true, true, false); } if (hasAVideo) { dictionary.Cards.AddMedia(cardId, TestInfrastructure.GetTestVideo(), EMedia.Video, Side.Answer, true, true, false); } Card card = dictionary.Cards.GetCardByID(cardId); if (hasQImage) { Assert.IsTrue(card.ContainsImage(Side.Question.ToString()), "Card does not contain question image!"); } else { Assert.IsFalse(card.ContainsImage(Side.Question.ToString()), "Card contains question image!"); } if (hasAImage) { Assert.IsTrue(card.ContainsImage(Side.Answer.ToString()), "Card does not contain answer image!"); } else { Assert.IsFalse(card.ContainsImage(Side.Answer.ToString()), "Card contains answer image!"); } if (hasQAudio) { Assert.IsTrue(card.ContainsAudio(Side.Question.ToString()), "Card does not contain question audio!"); } else { Assert.IsFalse(card.ContainsAudio(Side.Question.ToString()), "Card contains question audio!"); } if (hasAAudio) { Assert.IsTrue(card.ContainsAudio(Side.Answer.ToString()), "Card does not contain answer audio!"); } else { Assert.IsFalse(card.ContainsAudio(Side.Answer.ToString()), "Card contains answer audio!"); } if (hasQEAudio) { Assert.IsTrue(card.ContainsExampleAudio(Side.Question.ToString()), "Card does not contain question example audio!"); } else { Assert.IsFalse(card.ContainsExampleAudio(Side.Question.ToString()), "Card contains question example audio!"); } if (hasAEAudio) { Assert.IsTrue(card.ContainsExampleAudio(Side.Answer.ToString()), "Card does not contain answer example audio!"); } else { Assert.IsFalse(card.ContainsExampleAudio(Side.Answer.ToString()), "Card contains answer example audio!"); } if (hasQVideo) { Assert.IsTrue(card.ContainsVideo(Side.Question.ToString()), "Card does not contain question video!"); } else { Assert.IsFalse(card.ContainsVideo(Side.Question.ToString()), "Card contains question video!"); } if (hasAVideo) { Assert.IsTrue(card.ContainsVideo(Side.Answer.ToString()), "Card does not contain answer video!"); } else { Assert.IsFalse(card.ContainsVideo(Side.Answer.ToString()), "Card contains answer video!"); } } } } }
public static void MyClassCleanup() { TestInfrastructure.MyClassCleanup(); }
public void CopyToBasicTest() { //Perform Test only if we use a db connection otherwise test case makes no sense if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext) != "File") { IUser sourceUser = null; IUser targetUser = null; try { string repositoryNameFinal = "finalTargetForCopyTest" + System.Environment.MachineName.ToLower(); //Do we have a target to copy from Assert.IsTrue(File.Exists(TestDic), "Test Learning Module file cannot be found."); ConnectionStringStruct sourceConnection = new ConnectionStringStruct(DatabaseType.Xml, CopyToTest.TestDic, false); sourceUser = UserFactory.Create((GetLoginInformation) delegate(UserStruct u, ConnectionStringStruct c) { return(u); }, sourceConnection, (DataAccessErrorDelegate) delegate { return; }, this); if (!authenticationUsers.ContainsKey(sourceConnection.ConnectionString)) { authenticationUsers.Add(sourceConnection.ConnectionString, sourceUser.AuthenticationStruct); } //Copy the reference LM to the new persistent LM ConnectionStringStruct dbConnection; using (Dictionary dbTarget = TestInfrastructure.GetConnection(TestContext)) { IUser dbUser = dbTarget.DictionaryDAL.Parent.CurrentUser; dbConnection = dbUser.ConnectionString; if (!authenticationUsers.ContainsKey(dbConnection.ConnectionString)) { authenticationUsers.Add(dbConnection.ConnectionString, dbUser.AuthenticationStruct); } dbTarget.Dispose(); finished = false; LearnLogic.CopyToFinished += new EventHandler(LearnLogic_CopyToFinished); LearnLogic.CopyLearningModule(sourceConnection, dbConnection, GetUser, (MLifter.DAL.Tools.CopyToProgress) delegate(string m, double p) { return; }, (DataAccessErrorDelegate) delegate { return; }, null); while (!finished) { System.Threading.Thread.Sleep(100); } ; LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished); } //copy to another persistent LM where we use Save to store as odx again ConnectionStringStruct targetConnection; using (Dictionary target = TestInfrastructure.GetPersistentLMConnection(TestContext, "sqlce")) { targetUser = target.DictionaryDAL.Parent.CurrentUser; targetConnection = targetUser.ConnectionString; if (!authenticationUsers.ContainsKey(targetConnection.ConnectionString)) { authenticationUsers.Add(targetConnection.ConnectionString, targetUser.AuthenticationStruct); } target.Dispose(); finished = false; LearnLogic.CopyToFinished += new EventHandler(LearnLogic_CopyToFinished); LearnLogic.CopyLearningModule(dbConnection, targetConnection, GetUser, (MLifter.DAL.Tools.CopyToProgress) delegate(string m, double p) { return; }, (DataAccessErrorDelegate) delegate { return; }, null); while (!finished) { System.Threading.Thread.Sleep(100); } ; LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished); } using (Dictionary source = new Dictionary(sourceUser.Open(), null)) using (Dictionary target = new Dictionary(targetUser.Open(), null)) { CompareChapters(source.Chapters.Chapters, target.Chapters.Chapters); //Verification Code compare finalTarget with the reference target CompareCards(source.Cards.Cards, target.Cards.Cards, source, target); //Compare Settings CompareSettings(source.Settings, target.Settings); if ((source.Settings != null) && (target.Settings != null)) { //Compare Styles CompareStyles(source.Settings.Style, target.Settings.Style); } } } finally { if (sourceUser != null) { sourceUser.Logout(); } if (targetUser != null) { targetUser.Logout(); } } } }