Exemplo n.º 1
0
        public void ToNewlineStringTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card  = writeLM.Cards.AddNew();
                    IWords words = card.Question;

                    for (int i = 0; i < TestInfrastructure.Random.Next(10, 50); i++)
                    {
                        IWord word = words.CreateWord("Word " + i.ToString(), WordType.Word, true);
                        words.AddWord(word);
                    }

                    string newLineStringClone = string.Empty;
                    foreach (IWord var in words.Words)
                    {
                        newLineStringClone += var.Word + "\r\n";
                    }
                    newLineStringClone = newLineStringClone.Substring(0, newLineStringClone.Length - 2);

                    Assert.AreEqual <string>(newLineStringClone, words.ToNewlineString(), "IWords.ToNewlineStringTest does not match with expected output.");
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 2
0
        public void ICardsTestsClearAllBoxesTest()
        {
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
                {
                    target.Cards.ClearAllBoxes();

                    foreach (ICard card in target.Cards.Cards)
                    {
                        Assert.AreEqual(0, card.Box, "Not all cards are in box 0.");
                    }

                    foreach (IBox box in target.Boxes.Box)
                    {
                        if (box.Id == 0)
                        {
                            Assert.AreEqual(target.Cards.Cards.Count, box.CurrentSize, "The size of the pool is not equal to the amount of cards.");
                        }
                        else
                        {
                            Assert.AreEqual(0, box.Size, "Not all boxes are of size 0.");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void AddWordsListTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    IChapter chapter = writeLM.Chapters.AddNew();
                    chapter.Title = "A chapter";

                    ICard card = writeLM.Cards.AddNew();
                    card.Chapter = chapter.Id;
                    List <IWord> wordList = new List <IWord>();

                    for (int i = 0; i < TestInfrastructure.Random.Next(10, 50); i++)
                    {
                        IWord word = card.Question.CreateWord("Word " + i.ToString(), WordType.Word, true);
                        wordList.Add(word);
                    }

                    card.Question.AddWords(wordList);

                    for (int i = 0; i < wordList.Count; i++)
                    {
                        Assert.AreEqual <string>("Word " + i.ToString(), writeLM.Cards.Get(card.Id).Question.Words[i].Word, "IWords.AddWords(List) does not add a list of words.");
                    }
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 4
0
        public void ICardStyleCloneTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    IChapter   chapter = writeLM.Chapters.AddNew();
                    ICardStyle style1  = writeLM.CreateCardStyle();
                    style1.Answer.BackgroundColor = Color.Red;
                    style1.Answer.FontFamily      = new FontFamily("Arial");

                    writeLM.UserSettings.Style = style1;

                    ICardStyle style2 = writeLM.UserSettings.Style.Clone();

                    //Check if style1 and style2 are equal
                    Assert.AreEqual <Color>(writeLM.UserSettings.Style.Answer.BackgroundColor, style2.Answer.BackgroundColor, "ICardStyle.Clone does not clone the original instance");
                    Assert.AreEqual <FontFamily>(writeLM.UserSettings.Style.Answer.FontFamily, style2.Answer.FontFamily, "ICardStyle.Clone does not clone the original instance");

                    style2.Answer.BackgroundColor = Color.Blue;
                    style2.Answer.FontFamily      = new FontFamily("Courier New");

                    //Check if style 1 and style2 are independent
                    Assert.AreNotEqual <Color>(writeLM.UserSettings.Style.Answer.BackgroundColor, style2.Answer.BackgroundColor, "ICardStyle.Clone does not make an independent copy of the original instance");
                    Assert.AreNotEqual <FontFamily>(writeLM.UserSettings.Style.Answer.FontFamily, style2.Answer.FontFamily, "ICardStyle.Clone does not make an independent copy of the original instance");
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 5
0
        public void ICardAddImagePerformanceTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            IMedia media;

            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    Tools.TestStopWatch.Start(TestContext);
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetLargeTestImage();
                    media = card.CreateMedia(EMedia.Image, testImage, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (image) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (image) to an AnswerMedia");
                    card.ClearAllMedia();
                    Tools.TestStopWatch.Stop(TestContext);
                    try { File.Delete(testImage); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
 public void IDictionaryMediaDirectoryTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
         {
             try
             {
                 String myBadPath = "C:/��j/fluppipath\\backagainhttp://somewhere";
                 testLM.MediaDirectory = myBadPath;
                 Assert.AreNotEqual <String>(myBadPath, testLM.MediaDirectory, "Bad directory path did get accepted.");
             }
             catch (NotSupportedException)
             {
                 //throw expected exception for the test to run successful
                 throw new DirectoryNotFoundException();
             }
         }
     }
     else
     {
         throw new DirectoryNotFoundException();                     //if tests are disabled, nevertheless the test should run successfully.
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 7
0
        public void ICardsTestsCopyCardTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser, true))
                {
                    IChapter chapter = target.Chapters.AddNew();
                    ICard    card    = target.Cards.AddNew();
                    card.Chapter = chapter.Id;

                    LMConnectionParameter param = new LMConnectionParameter(TestContext);
                    param.Callback         = TestInfrastructure.GetAdminUser;
                    param.ConnectionType   = string.Empty;
                    param.IsProtected      = false;
                    param.LearningModuleId = -1;
                    param.Password         = string.Empty;
                    param.RepositoryName   = string.Empty;
                    param.standAlone       = true;

                    using (IDictionary target2 = TestInfrastructure.GetLMConnection(param))
                    {
                        //IChapter chapter2 = target2.Chapters.AddNew();
                        //card.Chapter = chapter2.Id;

                        int before = target2.Cards.Count;
                        int id     = target2.Cards.CopyCard(card);

                        Assert.IsTrue(target2.Cards.Count == before + 1, "Card count should be " + (before + 1) + " but is " + target2.Cards.Count.ToString());
                    }
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 8
0
        public void ICardClearAllMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetTestImage();
                    IMedia media     = card.CreateMedia(EMedia.Image, testImage, true, true, true);

                    for (int i = 0; i < 5; i++)
                    {
                        card.AddMedia(media, Side.Question);
                        card.AddMedia(media, Side.Answer);
                    }
                    card.ClearAllMedia();
                    Assert.AreEqual(0, card.AnswerMedia.Count, "Media couldn't be cleared from ICard");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "Media couldn't be cleared from ICard");
                    try { File.Delete(testImage); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 9
0
 public void IChaptersMoveChapterFirstIDequalSecondID()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             for (int i = 0; i < 10; i++)
             {
                 IChapter chapter = writeLM.Chapters.AddNew();
                 chapter.Title = "Chapter " + i.ToString();
             }
             for (int i = 0; i < 10; i++)
             {
                 IList <IChapter> chapters = writeLM.Chapters.Chapters;
                 int idx      = TestInfrastructure.Random.Next(0, chapters.Count);
                 int randomId = chapters[idx].Id;
                 writeLM.Chapters.Move(randomId, randomId);
                 IList <IChapter> chapters2 = writeLM.Chapters.Chapters;
                 int newIdx = -1;
                 for (int k = 0; k < chapters2.Count; k++)
                 {
                     if (chapters2[k].Id == randomId)
                     {
                         newIdx = k;
                     }
                 }
                 Assert.IsTrue(idx == newIdx, "Chapter was moved!");
             }
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 10
0
        public void IChaptersAddNewCheckChapterContent()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    List <TitleDesc> test = new List <TitleDesc>();
                    int numberOfTestData  = 10;

                    for (int i = 0; i < numberOfTestData; i++)
                    {
                        TitleDesc td = new TitleDesc();
                        td.title = "Chapter - " + Guid.NewGuid().ToString();
                        td.desc  = "Description - " + Guid.NewGuid().ToString();
                        test.Add(td);
                    }

                    for (int i = 0; i < 10; i++)
                    {
                        IChapter chapter = writeLM.Chapters.AddNew();
                        chapter.Title       = test[i].title;
                        chapter.Description = test[i].desc;

                        Assert.AreEqual <string>(chapter.Title, test[i].title, "IChapter does not save the Title to IDictionary");
                        Assert.AreEqual <string>(chapter.Description, test[i].desc, "IChapter does not save the Description to IDictionary");
                    }
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 11
0
        public void LoginUserProfileTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty))
                {
                    IList <UserStruct> users;
                    if (writeLM.IsDB)
                    {
                        users = UserFactory.GetUserList(writeLM.Parent.CurrentUser.ConnectionString);
                    }

                    if (writeLM.Parent.CurrentUser.ConnectionString.Typ != DatabaseType.MsSqlCe)
                    {
                        IUser user = (IUser)UserFactory.Create((GetLoginInformation)GetUserAdmin, writeLM.Parent.CurrentUser.ConnectionString,
                                                               (DataAccessErrorDelegate) delegate { return; }, TestContext);

                        //before: 7ff135854376850e9711bd75ce942e07
                        Assert.AreEqual <string>(TestInfrastructure.SupportsNullableValues(TestContext) ? "21232f297a57a5a743894a0e4a801fc3" : string.Empty,
                                                 user.Password, "Password isnt't encrypted properly");
                        Assert.AreEqual <string>(TestInfrastructure.SupportsNullableValues(TestContext) ?
                                                 GetUserAdmin(new UserStruct(), new ConnectionStringStruct()).Value.UserName : string.Empty,
                                                 user.UserName, "UserName isn't saved properly");
                    }
                    else
                    {
                        Assert.AreEqual <string>(WindowsIdentity.GetCurrent().Name.ToLower(), writeLM.Parent.CurrentUser.UserName.ToLower());
                    }
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 12
0
 public void IChaptersMoveChapterUnknownSecondID()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     //This test moves 10 chapters from 1,2,3,4,5,6,7,8,9,10 to 10,9,8,7,6,5,4,3,2,1 :-)
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             List <int> chapters = new List <int>();
             for (int i = 0; i < 10; i++)
             {
                 IChapter chapter = writeLM.Chapters.AddNew();
                 chapter.Title = "Chapter " + (i + 1);
                 chapters.Add(chapter.Id);
             }
             int unknown = chapters[chapters.Count - 1] + 1000;  //probably unknown
             int first   = chapters[TestInfrastructure.Random.Next(0, chapters.Count)];
             writeLM.Chapters.Move(first, unknown);
         }
     }
     else
     {
         throw new IdAccessException(0);
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 13
0
 public void ICardsTestsGetTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             IChapter   chapter = target.Chapters.AddNew();
             List <int> cardIds = new List <int>();
             for (int i = 0; i < TestInfrastructure.Loopcount; i++)
             {
                 ICard card = target.Cards.AddNew();
                 card.Chapter = chapter.Id;
                 cardIds.Add(card.Id);
             }
             for (int i = 0; i < TestInfrastructure.Loopcount; i++)
             {
                 int   nextId = cardIds[TestInfrastructure.Random.Next(0, cardIds.Count)];
                 ICard card   = target.Cards.Get(nextId);
                 Assert.IsNotNull(card, "Card Id could not be found.");
                 Assert.IsInstanceOfType(card, typeof(ICard), "Card was not of type ICard.");
                 Assert.IsTrue(card.Id == nextId, "Card Id should be " + nextId + " but is " + card.Id);
             }
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 14
0
        public void ICardRemoveMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card       = writeLM.Cards.AddNew();
                    string testImage  = TestInfrastructure.GetTestImage();
                    IMedia mediaImage = card.CreateMedia(EMedia.Image, testImage, true, true, true);
                    card.AddMedia(mediaImage, Side.Question);
                    string testAudio  = TestInfrastructure.GetTestAudio();
                    IMedia mediaAudio = card.CreateMedia(EMedia.Audio, testAudio, true, true, true);
                    card.AddMedia(mediaAudio, Side.Answer);
                    card.RemoveMedia(mediaAudio);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "Media was removed at the wrong Place (QuestionSide instead of AnswerSide)");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "Media couldn't be removed from ICard");
                    try { File.Delete(testImage); }
                    catch { }
                    try { File.Delete(testAudio); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 15
0
        public void MediaServerTestGetMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                if (!(TestContext.DataRow["type"].ToString().ToLower() == "file"))
                {
                    using (MLifter.DAL.Interfaces.IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                    {
                        Dictionary <int, int>       mediaIds = new Dictionary <int, int>();                 //key: idCounter, value: mediaId
                        Dictionary <string, byte[]> testData = new Dictionary <string, byte[]>();
                        //Filling DB with Test Data
                        for (int i = 0; i < TestInfrastructure.Loopcount; i++)
                        {
                            string testMedia = TestInfrastructure.GetTestImage();
                            testData.Add(testMedia, File.ReadAllBytes(testMedia));
                        }
                        int idCounter = 0;
                        //Putting Test Data into db
                        foreach (string testMedia in testData.Keys)
                        {
                            ICard  card  = testLM.Cards.Create();
                            IMedia media = card.AddMedia(card.CreateMedia(EMedia.Image, testMedia, true, true, false), Side.Question);
                            mediaIds[idCounter++] = media.Id;
                        }

                        //Create a new MediaServerInstance
                        DbMediaServer myMediaServer = DbMediaServer.Instance(8080, testLM.Parent);
                        myMediaServer.Start();

                        //Wait until server is ready
                        while (!myMediaServer.IsReady)
                        {
                            ;
                        }

                        //Verify
                        idCounter = 0;
                        foreach (string testMedia in testData.Keys)
                        {
                            Uri       theServerUri_itme = DbMediaServer.Instance(testLM.Parent).GetMediaURI(mediaIds[idCounter++]);
                            WebClient client            = new WebClient();
                            byte[]    downloadData_item = client.DownloadData(theServerUri_itme.ToString());
                            byte[]    b = testData[testMedia];

                            for (int i = 0; i < b.Length; i++)
                            {
                                Assert.IsTrue(b[i].Equals(downloadData_item[i]), "Test Data does not match");
                            }
                        }

                        //Stop the Media Server again
                        myMediaServer.Stop();
                    }
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 16
0
        public void ICardStyleWatermarkTest01()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext) && !(TestContext.DataRow["type"].ToString().ToLower() == "file"))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    IChapter   chapter = writeLM.Chapters.AddNew();
                    ICardStyle style   = writeLM.CreateCardStyle();
                    ICard      card    = writeLM.Cards.AddNew();
                    card.Chapter = chapter.Id;

                    string image     = TestInfrastructure.GetTestImage();
                    string image2    = TestInfrastructure.GetTestImage();
                    string image3    = TestInfrastructure.GetTestImage();
                    Uri    imageUri  = new Uri(image, UriKind.Absolute);
                    Uri    imageUri2 = new Uri(image2, UriKind.Absolute);
                    style.Question.OtherElements.Add("background", String.Format("url({0}) repeat-x", imageUri.AbsoluteUri));
                    style.Answer.OtherElements.Add("background-image", String.Format("url({0})", imageUri2.AbsolutePath));
                    style.AnswerExample.OtherElements.Add("background-image", String.Format("url({0})", TestInfrastructure.GetTestImage()));
                    card.Settings.Style = style;

                    writeLM.Save();

                    ICard card2 = writeLM.Cards.Get(card.Id);

                    string css = card2.Settings.Style.ToString();

                    MatchCollection mc = cssUrlEntry.Matches(css);
                    if (mc.Count != 3)
                    {
                        Assert.Fail("Invalid number of media objects found! (Should be 3)");
                    }
                    foreach (Match m in mc)
                    {
                        string url = m.Groups["url"].Value.Trim(new char[] { '"', '\'' });
                        Uri    uri;
                        if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                        {
                            uri = new Uri(url);
                            WebClient client = new WebClient();
                            byte[]    data   = client.DownloadData(uri);
                            if (data.Length <= 0)
                            {
                                Assert.Fail("Invalid media file size! (0)");
                            }
                        }
                        else
                        {
                            Assert.Fail("Invalid media URI found! ({0})", url);
                        }
                    }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 17
0
 public void IDictionaryAuthorPropertyTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         IDictionary testLM   = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false);
         String      myAuthor = "The author was a creazy guy";
         testLM.Author = myAuthor;
         Assert.AreEqual <String>(myAuthor, testLM.Author, "Author String give back does not match with input");
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 18
0
 public void IDictionaryDescriptionPropertyTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         IDictionary testLM        = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false);
         String      myDescription = "Ich hatte 18 Flaschen Whisky im Keller. Meine Frau befahl mir, den Inhalt jeder einzelnen Flasche ins Sp�lbecken zu gie�en, sonst k�nnte ich was erlebe. Ich fing also mit der unangenehmen Arbeit an. Ich zog den Korken von der ersten Flasche und goss den Inhalt ins Becken, mit Ausnahme von einem Glas, das ich trank. Dann extrahierte ich den Korken von der zweiten Flasche und tat desselbe mit Ausnahme eines Glases, das ich trank. Dann zog ich den Korken von der dritten Flasche und goss den Whisky ins Becken, das ich trank. Ich zog den Korken von der vierten ins Becken und goss die Flasche ins Glas, das ich trank. Ich zog die Flasche vom n�chsten Korken, trank ein Becken daraus und warf den Rest ins Glas. Ich zog das Becken aus dem n�chsten Glas und goss den Korken in die Flasche. Dann korkte ich das Becken mit dem Glas, flachte den Trank und trinkte den Genuss. Als ich alles entleert hatte, hielt ich das Haus mit der einen Hand fest, z�hlte die Gl�ser, Korken und Flaschen und Becken mit der anderen und stellte fest, dass es 39 waren. Und als das Haus wieder vorbeikam, z�hlte ich sie nochmals und hatte dann alle H�user in der Flasche, die ich trank. Ich stehe gar nicht unter Alfluss von Einkohol wie manche Denker leuten, ich bin nicht halb so bedenkt wie trinken k�nntet, aber ich, ich habe so ein f�hlsames Geselt.. aaaaaaaaahhhhhhhhhhhh.............. ";
         testLM.Description = myDescription;
         Assert.AreEqual <String>(myDescription, testLM.Description, "Description String give back does not match with input");
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 19
0
 public void IDictionaryFactoryCreateInstanceTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty);
         Assert.IsNotNull(testLM, "Factory returned a null reference.");
         //Better would be if instead of XmlDictionary something is typed that extends IDictionary
         Assert.IsTrue(testLM is IDictionary);
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 20
0
 public void IChapterCreateCardStyle()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             IChapter chapter = writeLM.Chapters.AddNew();
             Assert.IsInstanceOfType(chapter.CreateCardStyle(), typeof(ICardStyle), "CreateCardStyle() does not return the correct format!");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 21
0
 public void IDictionaryChapters()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
         {
             Assert.IsNotNull(testLM.Chapters, "Chapters property is null");
             Assert.IsTrue(testLM.Chapters is IChapters, "Chapters not of type IChapters");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 22
0
 public void IDictionaryCommentAudioTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
         {
             Assert.AreEqual(typeof(Dictionary <CommentarySoundIdentifier, IMedia>), testLM.DefaultSettings.CommentarySounds.GetType(),
                             "CommentarySounds were not a Dictionary<CommentarySoundIdentifier,IMedia> type.");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 23
0
        public void IDictionaryAnswerCaptionTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false);

                String myAnswerCaption = "Klingon language";
                testLM.DefaultSettings.AnswerCaption = myAnswerCaption;
                Assert.AreEqual <String>(myAnswerCaption, testLM.DefaultSettings.AnswerCaption, "AnswerCaptionTest does not match");
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 24
0
        public void IExtensionTestAddExtensionToLM()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext) != "File")
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    byte[] bufCheck    = new byte[5];
                    byte[] bufOriginal = new byte[5] {
                        (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o'
                    };

                    ExtensionAction extensionAction = new ExtensionAction()
                    {
                        Kind = ExtensionActionKind.Install, Execution = ExtensionActionExecution.Once
                    };

                    IExtension extension = writeLM.Parent.CurrentUser.List().ExtensionFactory();
                    extension.Type      = ExtensionType.Skin;
                    extension.Name      = "TheurySkin";
                    extension.Version   = new Version("1.0.0.0");
                    extension.StartFile = "TheurySkin.style";
                    extension.Data      = new System.IO.MemoryStream(bufOriginal);
                    extension.Actions.Add(extensionAction);

                    writeLM.Extensions.Add(extension);

                    ////////////////////////////////////////////////////////////////

                    Assert.AreEqual <int>(1, writeLM.Extensions.Count, "The Extension is not correctly saved to the database/LM");
                    Assert.AreEqual <ExtensionType>(ExtensionType.Skin, writeLM.Extensions[0].Type, "The ExtensionType is wrong");
                    Assert.AreEqual <string>("TheurySkin", writeLM.Extensions[0].Name, "The ExtensionName is wrong");
                    Assert.AreEqual <Version>(new Version("1.0.0.0"), writeLM.Extensions[0].Version, "The ExtensionVersion is wrong");
                    Assert.AreEqual <string>("TheurySkin.style", writeLM.Extensions[0].StartFile, "The ExtensionStartFile is wrong");
                    Assert.AreEqual <ExtensionAction>(extensionAction, writeLM.Extensions[0].Actions[0], "The ExtensionAction is wrong");

                    writeLM.Extensions[0].Data.Read(bufCheck, 0, bufOriginal.Length);
                    for (int i = 0; i < bufCheck.Length; i++)
                    {
                        Assert.AreEqual <byte>(bufCheck[i], bufOriginal[i], "The ExtensionData is wrong");
                    }

                    ////////////////////////////////////////////////////////////////

                    writeLM.Extensions[0].Actions.RemoveAt(0);
                    Assert.AreEqual <int>(0, writeLM.Extensions[0].Actions.Count, "Number of ExtensionActions is wrong");
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 25
0
 public void ICardsTestsCreateTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             ICard card = target.Cards.Create();
             Assert.IsNotNull(card, "Created card was null.");
             Assert.IsInstanceOfType(card, typeof(ICard), "Card was not of type ICard.");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 26
0
        public void IChaptersMoveChapter()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    Tools.TestStopWatch.Start(TestContext);
                    for (int i = 0; i < 10; i++)
                    {
                        IChapter chapter = writeLM.Chapters.AddNew();
                        chapter.Title = "Chapter " + (i + 1);
                    }
                    for (int i = 0; i < 10; i++)
                    {
                        IList <IChapter> chapters = writeLM.Chapters.Chapters;
                        int firstIdx  = TestInfrastructure.Random.Next(0, chapters.Count);
                        int secondIdx = TestInfrastructure.Random.Next(0, chapters.Count);
                        int first     = chapters[firstIdx].Id;
                        int second    = chapters[secondIdx].Id;
                        if (firstIdx == secondIdx)
                        {
                            continue;
                        }

                        writeLM.Chapters.Move(first, second);
                        IList <IChapter> chapters2 = writeLM.Chapters.Chapters;
                        int newIdx = -1;
                        for (int k = 0; k < chapters2.Count; k++)
                        {
                            if (chapters2[k].Id == first)
                            {
                                newIdx = k;
                            }
                        }
                        Assert.IsFalse(newIdx < 0, "Could not find first ID!");
                        if (firstIdx < secondIdx)
                        {
                            Assert.AreEqual <int>(chapters2[newIdx - 1].Id, second, string.Format("IChapters.Move does not work correct. [{0} <-> {1}]", first, second));
                        }
                        else
                        {
                            Assert.AreEqual <int>(chapters2[newIdx + 1].Id, second, string.Format("IChapters.Move does not work correct. [{0} <-> {1}]", first, second));
                        }
                    }
                    Tools.TestStopWatch.Stop(TestContext);
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 27
0
 public void CreateNullWordTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
         {
             ICard card = target.Cards.AddNew();
             IWord word = card.Question.CreateWord(null, WordType.Word, false);
             Assert.AreEqual <string>(word.Word, String.Empty, "The value for word should be empty.");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 28
0
 public void IDictionaryCategoryTest()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext))
     {
         using (IDictionary target = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
         {
             List <Category> categories = Category.GetCategories();
             Category        category   = categories[TestInfrastructure.Random.Next(0, categories.Count)];
             target.Category = category;
             Assert.AreEqual <int>(target.Category.Id, category.Id, "The saved category is not correct.");
         }
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 29
0
 public void LoginFormsUserInvalid3Test()
 {
     TestInfrastructure.DebugLineStart(TestContext);
     if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext) == "pgsql")
     {
         using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, (GetLoginInformation)GetInvalidFormsUser3))
         {
         }
     }
     else
     {
         throw new NoValidUserException();
     }
     TestInfrastructure.DebugLineEnd(TestContext);
 }
Exemplo n.º 30
0
        public void IDictionaryUseDictionaryStyleTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary testLM = TestInfrastructure.GetLMConnection(TestContext, string.Empty, false))
                {
                    testLM.DefaultSettings.UseLMStylesheets = true;
                    Assert.IsTrue(testLM.DefaultSettings.UseLMStylesheets.Value);

                    testLM.DefaultSettings.UseLMStylesheets = false;
                    Assert.IsFalse(testLM.DefaultSettings.UseLMStylesheets.Value);
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }