Example #1
0
        public void EnsureModelRelationshipEntryInSavedFileTest()
        {
            var file = new ThreeMfFile();

            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                file = ThreeMfFile.Load(ms);
                Assert.Equal(0, file.Models.Count);
            }

            file.Models.Add(new ThreeMfModel());
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                file = ThreeMfFile.Load(ms);
                Assert.Equal(1, file.Models.Count);
            }

            file.Models.Add(new ThreeMfModel());
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                file = ThreeMfFile.Load(ms);
                Assert.Equal(2, file.Models.Count);
            }
        }
Example #2
0
        private ZipArchive GetArchiveFromFile(ThreeMfFile file)
        {
            var ms = new MemoryStream();

            file.Save(ms);
            ms.Seek(0, SeekOrigin.Begin);
            return(GetArchiveFromStream(ms));
        }
 public static ThreeMfFile RoundTripFile(ThreeMfFile file)
 {
     using (var ms = new MemoryStream())
     {
         file.Save(ms);
         ms.Seek(0, SeekOrigin.Begin);
         var file2 = ThreeMfFile.Load(ms);
         return(file2);
     }
 }
Example #4
0
        public void FileSystemAPITest()
        {
            var filePath = Path.GetTempFileName();
            var file     = new ThreeMfFile();

            file.Save(filePath);
            var roundTripFile = ThreeMfFile.Load(filePath);

            try
            {
                File.Delete(filePath);
            }
            catch
            {
            }
        }
Example #5
0
        public void EnsureThumbnailRelationshipsArePresentTest()
        {
            var file  = new ThreeMfFile();
            var model = new ThreeMfModel();

            model.Resources.Add(new ThreeMfObject()
            {
                ThumbnailData = new byte[0], ThumbnailContentType = ThreeMfImageContentType.Jpeg
            });
            model.Resources.Add(new ThreeMfObject()
            {
                ThumbnailData = new byte[0], ThumbnailContentType = ThreeMfImageContentType.Png
            });
            file.Models.Add(model);

            using (var zipStream = new MemoryStream())
                using (var packageStream = new MemoryStream())
                {
                    // save file to stream and duplicate it so it can be re-opened as both a simple zip file and a package to validate structure
                    file.Save(zipStream);
                    zipStream.Seek(0, SeekOrigin.Begin);
                    zipStream.CopyTo(packageStream);
                    zipStream.Seek(0, SeekOrigin.Begin);
                    packageStream.Seek(0, SeekOrigin.Begin);
                    using (var archive = GetArchiveFromStream(zipStream))
                        using (var package = Package.Open(packageStream))
                        {
                            // get the actual thumbnail paths
                            var jpegPath  = "/" + archive.Entries.Single(e => e.Name.EndsWith(".jpg")).FullName;
                            var pngPath   = "/" + archive.Entries.Single(e => e.Name.EndsWith(".png")).FullName;
                            var modelPart = package.GetPart(new Uri("/3D/3dmodel.model", UriKind.RelativeOrAbsolute));
                            var rels      = modelPart.GetRelationships().ToList();
                            Assert.Equal(2, rels.Count);
                            Assert.Equal(jpegPath, rels[0].TargetUri.ToString());
                            Assert.Equal(pngPath, rels[1].TargetUri.ToString());
                        }
                }
        }