Пример #1
0
        public void GetCatalogsTest()
        {
            // IEnumerable<CatalogEntry> GetCatalogs(Stream diskImage, VolumeTableOfContents vtoc);
            //Stage
            using var diskImageStream = this.GetResourceStream("1983_dos33c.dsk");

            //Mock

            //Test
            var dic      = new DiskImageCommands();
            var catalogs = dic.GetCatalogs(diskImageStream).ToArray();

            //Output
            foreach (var catalog in catalogs)
            {
                this.TestContext.WriteLine($"{catalog}");
                foreach (var file in catalog.FileEntries)
                {
                    this.TestContext.WriteLine($"~{file}");
                }
            }

            var files = from c in catalogs
                        from f in c.FileEntries
                        where f.Exists
                        select f.Name.Trim();

            //Assert
            Assert.AreEqual("HELLO|COPY|CONVERT13", string.Join("|", files));

            //Verify
        }
Пример #2
0
        public void GetDataFileEntryTest()
        {
            //Stage
            using var diskImageStream = this.GetResourceStream("1983_dos33c.dsk");

            //Mock

            //Test
            var dic    = new DiskImageCommands();
            var target = (from catalog in dic.GetCatalogs(diskImageStream)
                          from file in catalog.FileEntries
                          where file.Exists
                          select file).First();
            var results = dic.GetDataFileEntry(diskImageStream, target).ToArray();

            //Output
            var base64 = Convert.ToBase64String(results, Base64FormattingOptions.InsertLineBreaks);

            this.TestContext.WriteLine(base64);

            //Assert
            var expectedBase64 = @"owEJCAoAiTqXAB4IFABEJNDnKDQpOrIgQ1RSTC1EADkIHgCiMjpBJNAiQVBQTEUgSUkiOrAxMDAw
AGoIKACiNDpBJNAiRE9TIFZFUlNJT04gMy4zICBTWVNURU0gTUFTVEVSIjqwMTAwMACMCDIAojc6
QSTQIkpBTlVBUlkgMSwgMTk4MyI6sDEwMDAAqAg8ALpEJDsiQkxPQUQgTE9BREVSLk9CSjAiAM8I
RgCMNDA5NjqyIEZBU1QgTE9BRCBJTiBJTlRFR0VSIEJBU0lDABAJUACiMTA6jMk5NTg6QSTQIkNP
UFlSSUdIVCBBUFBMRSBDT01QVVRFUixJTkMuIDE5ODAsMTk4MiI6sDEwMDAATwlaAEPQ4ijJMTEw
MSk6rUPQNsS6Op46QSTQIkJFIFNVUkUgQ0FQUyBMT0NLIElTIERPV04iOrAxMDAwOp0AXglkALrn
KDQpOyJGUCIAdQnoA7IgQ0VOVEVSIFNUUklORyBBJACVCfIDQtDTKDIwySjjKEEkKcsyKSk6rULQ
0TDEQtAxAKIJ/AOWQjq6QSQ6sQAAAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";

            var compare = Convert.FromBase64String(expectedBase64)
                          .Zip(results).Select((v, i) => new
            {
                IsNotMatched = v.First != v.Second,
                Expected     = v.First,
                Found        = v.Second,
                Index        = i,
            }).Where(i => i.IsNotMatched);

            Assert.IsFalse(compare.Any());

            //Verify
        }
Пример #3
0
        public void GetTrackSectorListForFileEntryTest()
        {
            //IEnumerable<TrackSectorList> GetTrackSectorListForFileEntry(Stream diskImage, FileEntry fileEntry)

            // IEnumerable<CatalogEntry> GetCatalogs(Stream diskImage, VolumeTableOfContents vtoc);
            //Stage
            using var diskImageStream = this.GetResourceStream("1983_dos33c.dsk");

            //Mock

            //Test
            var dic    = new DiskImageCommands();
            var target = (from catalog in dic.GetCatalogs(diskImageStream)
                          from file in catalog.FileEntries
                          where file.Exists
                          select file).First();
            var results = dic.GetTrackSectorListForFileEntry(diskImageStream, target).ToArray();

            //Output
            foreach (var tsl in results)
            {
                this.TestContext.WriteLine($"{tsl.NextTrack}/{tsl.NextSector}: {tsl.SectorOffset}");
                foreach (var ts in tsl.TrackSectorPairs.Where(i => i.Track != 0 || i.Sector != 0))
                {
                    this.TestContext.WriteLine($"~{ts}");
                }
            }

            //Assert
            Assert.AreEqual(19, results[0].TrackSectorPairs.ElementAt(0).Track);
            Assert.AreEqual(14, results[0].TrackSectorPairs.ElementAt(0).Sector);
            Assert.AreEqual(19, results[0].TrackSectorPairs.ElementAt(1).Track);
            Assert.AreEqual(13, results[0].TrackSectorPairs.ElementAt(1).Sector);

            //Verify
        }