Exemplo n.º 1
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.º 2
0
        public void ICardAddMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            IMedia media;

            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetTestImage();
                    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();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (image) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (image) to an QuestionMedia");
                    card.ClearAllMedia();

                    string testAudio = TestInfrastructure.GetTestAudio();
                    //With the following parameters, the audiofile is saved 2 times
                    media = card.CreateMedia(EMedia.Audio, testAudio, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, false, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, true, false);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, false, false);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    string testVideo = TestInfrastructure.GetTestVideo();
                    media = card.CreateMedia(EMedia.Video, testVideo, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (video) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (video) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (video) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (video) to an QuestionMedia");
                    card.ClearAllMedia();

                    try { File.Delete(testImage); }
                    catch { }
                    try { File.Delete(testAudio); }
                    catch { }
                    try { File.Delete(testVideo); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemplo n.º 3
0
        public void ExportHelperTest()
        {
            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>();
                    List <string> testImages      = new List <string>();
                    List <string> testAudios      = new List <string>();
                    List <string> largeTestAudios = new List <string>();
                    List <string> testVideos      = new List <string>();
                    List <string> exportFiles     = new List <string>();
                    for (int i = 0; i < 10; i++)
                    {
                        ICard card = target.Cards.AddNew();
                        card.Chapter = chapter.Id;
                        cardIds.Add(card.Id);
                        string testImage = TestInfrastructure.GetTestImage();
                        IMedia image     = card.CreateMedia(EMedia.Image, testImage, true, true, true);
                        card.AddMedia(image, Side.Question);
                        card.AddMedia(image, Side.Answer);
                        string testAudio = TestInfrastructure.GetTestAudio();
                        IMedia audio     = card.CreateMedia(EMedia.Audio, testAudio, true, true, false);
                        card.AddMedia(audio, Side.Question);
                        card.AddMedia(audio, Side.Answer);
                        string largeTestAudio = TestInfrastructure.GetLargeTestAudio();
                        IMedia exaudio        = card.CreateMedia(EMedia.Audio, largeTestAudio, true, false, true);
                        card.AddMedia(exaudio, Side.Question);
                        card.AddMedia(exaudio, Side.Answer);
                        string testVideo = TestInfrastructure.GetTestVideo();
                        IMedia video     = card.CreateMedia(EMedia.Video, testVideo, true, false, false);
                        card.AddMedia(video, Side.Question);
                        card.AddMedia(video, Side.Answer);

                        testImages.Add(testImage);
                        testAudios.Add(testAudio);
                        largeTestAudios.Add(largeTestAudio);
                        testVideos.Add(testVideo);
                    }

                    MLifter.DAL.ImportExport.Exporter.ExportHelper exportHelper = new MLifter.DAL.ImportExport.Exporter.ExportHelper(target, Path.Combine(Path.GetTempPath(), "export.csv"));

                    for (int j = 0; j < target.Cards.Count; j++)
                    {
                        ICard card = target.Cards.Get(cardIds[j]);
                        foreach (IMedia media in card.QuestionMedia)
                        {
                            string fileName  = Path.Combine(Path.GetTempPath(), exportHelper.GetLocalFile(media.Filename, media.MediaType.ToString()));
                            string fileName2 = String.Empty;
                            exportFiles.Add(fileName);
                            switch (media.MediaType)
                            {
                            case EMedia.Audio:
                                if (media.Default.Value)
                                {
                                    fileName2 = testAudios[j];
                                }
                                else if (media.Example.Value)
                                {
                                    fileName2 = largeTestAudios[j];
                                }
                                else
                                {
                                    continue;
                                }
                                break;

                            case EMedia.Image:
                                fileName2 = testImages[j];
                                break;

                            case EMedia.Video:
                                fileName2 = testVideos[j];
                                break;

                            default:
                                continue;
                            }
                            byte[] eb = File.ReadAllBytes(fileName);
                            byte[] ib = File.ReadAllBytes(fileName2);

                            Assert.AreEqual <int>(ib.Length, eb.Length, String.Format("{0} and {1} are different in size! (loop={2})", fileName, fileName2, j));
                        }
                    }

                    foreach (string file in testImages)
                    {
                        try { File.Delete(file); }
                        catch { }
                    }
                    foreach (string file in testAudios)
                    {
                        try { File.Delete(file); }
                        catch { }
                    }
                    foreach (string file in largeTestAudios)
                    {
                        try { File.Delete(file); }
                        catch { }
                    }
                    foreach (string file in testVideos)
                    {
                        try { File.Delete(file); }
                        catch { }
                    }
                    foreach (string file in exportFiles)
                    {
                        try { File.Delete(file); }
                        catch { }
                    }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }