Ejemplo n.º 1
0
        public async Task TestSinglesPreserveFavAndInk()
        {
            var failMessage  = string.Empty;
            var ev           = new ManualResetEventSlim();
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                try
                {
                    foreach (var fileToAdd in new[] { "12th Street", "Black Cat", "Freckles" }) // insert before, between and after 14,40
                    {
                        AddLogEntry($"Doing = {fileToAdd}");
                        int num = 0;
                        using (var helper = new SinglesTesthelper(this, (str) =>
                        {
                            var include = false;
                            if (str.Contains("Crazy Bone") || str.Contains("Banana Peel"))
                            {
                                include = true;
                            }
                            num++;
                            return(include);
                        }))
                        {
                            var strComposer = "Charles L Johnson GREAT COMPOSER GREAT COMPOSER GREAT COMPOSER";
                            {
                                var curmetadata = await helper.CreateAndSaveBmkAsync();

                                Assert.AreEqual(2, curmetadata.lstVolInfo.Count);
                                Assert.AreEqual(2, curmetadata.lstTocEntries.Count);
                                for (int i = 0; i < curmetadata.MaxPageNum; i += 2)
                                {
                                    var volno = curmetadata.GetVolNumFromPageNum(i);
                                    curmetadata.ToggleFavorite(i, IsFavorite: true, FavoriteName: curmetadata.lstVolInfo[volno].FileNameVolume);
                                }
                                DumpVolAndToc("Start", curmetadata);
                                curmetadata.lstTocEntries.Where(t => t.SongName.Substring(0, 5) == "Crazy").First().Composer = strComposer;
                                curmetadata.SaveIfDirty(ForceDirty: true);
                                var fileToAddFullPath = helper.sourceFiles.Where(f => f.Contains(fileToAdd)).First();
                                AddLogEntry($"Adding file  = {fileToAddFullPath}");
                                File.Copy(fileToAddFullPath,
                                          Path.Combine(helper.singlesFolder, Path.GetFileName(fileToAddFullPath))
                                          );
                            }
                            {
                                (var lstPdfMetaFileData, var lstFolders) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(helper.pdfViewerWindow._RootMusicFolder);
                                Assert.AreEqual(1, lstPdfMetaFileData.Count);
                                var curmetadata = lstPdfMetaFileData[0];
                                DumpVolAndToc("Done", curmetadata);
                                Assert.AreEqual(3, curmetadata.lstVolInfo.Count);
                                Assert.AreEqual(3, curmetadata.lstTocEntries.Count);
                                Assert.AreEqual(strComposer, curmetadata.lstTocEntries.Where(t => t.SongName.Substring(0, 5) == "Crazy").First().Composer);
                                var lastone = string.Empty;
                                foreach (var vol in curmetadata.lstVolInfo)
                                {
                                    Assert.IsTrue(string.Compare(lastone, vol.FileNameVolume) < 0, $"sequence {lastone} {vol}");
                                    lastone = vol.FileNameVolume;
                                }
                                Assert.AreEqual("Crazy Bone Rag.pdf", curmetadata.dictFav.Values.ToList()[2].FavoriteName);
                                curmetadata.SaveIfDirty(ForceDirty: true);
                                AddLogEntry(File.ReadAllText(curmetadata.PdfBmkMetadataFileName));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    failMessage = ex.ToString();
                }
                AddLogEntry("set event");
                ev.Set();
            });

            ev.Wait();
            AddLogEntry("Done wait event");
            Assert.IsTrue(string.IsNullOrEmpty(failMessage), failMessage);
        }
Ejemplo n.º 2
0
        public async Task TestSinglesInsert1File()
        {
            var failMessage  = string.Empty;
            var ev           = new ManualResetEventSlim();
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                try
                {
                    foreach (var fileToAdd in new[] { "12th Street", "Black Cat", "Freckles" }) // insert before, between and after 14,40
                    {
                        AddLogEntry($"Doing = {fileToAdd}");
                        int num = 0;
                        using (var helper = new SinglesTesthelper(this, (str) =>
                        {
                            var include = false;
                            if (str.Contains("Crazy Bone") || str.Contains("Banana Peel"))
                            {
                                include = true;
                            }
                            num++;
                            return(include);
                        }))
                        {
                            var curmetadata = await helper.CreateAndSaveBmkAsync();
                            DumpVolAndToc("Start", curmetadata);
                            Assert.AreEqual(2, curmetadata.lstVolInfo.Count, $"{fileToAdd}");
                            Assert.AreEqual(2, curmetadata.lstTocEntries.Count, $"{fileToAdd}");
                            if (fileToAdd == "12th Street")
                            {
                                Assert.AreEqual("Crazy Bone Rag", curmetadata.lstTocEntries[1].SongName, $"{fileToAdd}");
                                Assert.AreEqual(3, curmetadata.lstTocEntries[1].PageNo, $"{fileToAdd}");
                            }

                            var fileToAddFullPath = helper.sourceFiles.Where(f => f.Contains(fileToAdd)).First();
                            AddLogEntry($"Adding file  = {fileToAddFullPath}");
                            File.Copy(fileToAddFullPath,
                                      Path.Combine(helper.singlesFolder, Path.GetFileName(fileToAddFullPath))
                                      );
                            (var lstPdfMetaFileData, var lstFolders) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(helper.pdfViewerWindow._RootMusicFolder);
                            Assert.AreEqual(1, lstPdfMetaFileData.Count, $"{fileToAdd}");
                            curmetadata = lstPdfMetaFileData[0];
                            DumpVolAndToc("Done", curmetadata);
                            Assert.AreEqual(3, curmetadata.lstVolInfo.Count, $"{fileToAdd}");
                            Assert.AreEqual(3, curmetadata.lstTocEntries.Count, $"{fileToAdd}");
                            var lastone = string.Empty;
                            foreach (var vol in curmetadata.lstVolInfo)
                            {
                                Assert.IsTrue(string.Compare(lastone, vol.FileNameVolume) < 0, $" nskip {fileToAdd} sequence {lastone} {vol}");
                                lastone = vol.FileNameVolume;
                            }
                            if (fileToAdd == "12th Street" || fileToAdd == "Black Cat")
                            {
                                Assert.AreEqual("Crazy Bone Rag", curmetadata.lstTocEntries[2].SongName, $"{fileToAdd}");
                                Assert.AreEqual(6, curmetadata.lstTocEntries[2].PageNo, $"{fileToAdd}");
                            }
                            else
                            {
                                Assert.AreEqual("Freckles Rag", curmetadata.lstTocEntries[2].SongName, $"{fileToAdd}");
                                Assert.AreEqual(6, curmetadata.lstTocEntries[2].PageNo, $"{fileToAdd}");
                            }
                            curmetadata.SaveIfDirty(ForceDirty: true);
                            AddLogEntry(File.ReadAllText(curmetadata.PdfBmkMetadataFileName));
                        }
                    }
                }
                catch (Exception ex)
                {
                    failMessage = ex.ToString();
                }
                AddLogEntry("set event");
                ev.Set();
            });

            ev.Wait();
            AddLogEntry("Done wait event");
            Assert.IsTrue(string.IsNullOrEmpty(failMessage), failMessage);
        }