示例#1
0
        public void SaveMediaMultiple()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository);

                IMediaType mediaType = mediaTypeRepository.Get(1032);
                Media      file      = MediaBuilder.CreateMediaFile(mediaType, -1);

                // Act
                repository.Save(file);

                Media image = MediaBuilder.CreateMediaImage(mediaType, -1);
                repository.Save(image);

                // Assert
                Assert.That(file.HasIdentity, Is.True);
                Assert.That(image.HasIdentity, Is.True);
                Assert.That(file.Name, Is.EqualTo("Test File"));
                Assert.That(image.Name, Is.EqualTo("Test Image"));
                Assert.That(file.ContentTypeId, Is.EqualTo(mediaType.Id));
                Assert.That(image.ContentTypeId, Is.EqualTo(mediaType.Id));
            }
        }
示例#2
0
        public void Export_Zip()
        {
            var mt = MediaTypeBuilder.CreateImageMediaType("testImage");

            MediaTypeService.Save(mt);
            var m1 = MediaBuilder.CreateMediaFile(mt, -1);

            MediaService.Save(m1);

            //Ensure a file exist
            var fullPath = HostingEnvironment.MapPathWebRoot(m1.Properties[Constants.Conventions.Media.File].GetValue().ToString());

            using (StreamWriter file1 = File.CreateText(fullPath))
            {
                file1.WriteLine("hello");
            }

            var def = new PackageDefinition
            {
                Name      = "test",
                MediaUdis = new List <GuidUdi>()
                {
                    m1.GetUdi()
                }
            };

            bool result = PackageBuilder.SavePackage(def);

            Assert.IsTrue(result);
            Assert.IsTrue(def.PackagePath.IsNullOrWhiteSpace());

            string packageXmlPath = PackageBuilder.ExportPackage(def);

            def = PackageBuilder.GetById(def.Id); // re-get
            Assert.IsNotNull(def.PackagePath);

            using (FileStream packageZipStream = File.OpenRead(packageXmlPath))
                using (ZipArchive zipArchive = PackageMigrationResource.GetPackageDataManifest(packageZipStream, out XDocument packageXml))
                {
                    string test = "test-file.txt";
                    Assert.Multiple(() =>
                    {
                        var mediaEntry = zipArchive.GetEntry("media/media/test-file.txt");
                        Assert.AreEqual("umbPackage", packageXml.Root.Name.ToString());
                        Assert.IsNotNull(mediaEntry);
                        Assert.AreEqual(test, mediaEntry.Name);
                        Assert.IsNotNull(zipArchive.GetEntry("package.xml"));
                        Assert.AreEqual(
                            $"<MediaItems><MediaSet><testImage id=\"{m1.Id}\" key=\"{m1.Key}\" parentID=\"-1\" level=\"1\" creatorID=\"-1\" sortOrder=\"0\" createDate=\"{m1.CreateDate.ToString("s")}\" updateDate=\"{m1.UpdateDate.ToString("s")}\" nodeName=\"Test File\" urlName=\"test-file\" path=\"{m1.Path}\" isDoc=\"\" nodeType=\"{mt.Id}\" nodeTypeAlias=\"testImage\" writerName=\"\" writerID=\"0\" udi=\"{m1.GetUdi()}\" mediaFilePath=\"/media/test-file.txt\"><umbracoFile><![CDATA[/media/test-file.txt]]></umbracoFile><umbracoBytes><![CDATA[100]]></umbracoBytes><umbracoExtension><![CDATA[png]]></umbracoExtension></testImage></MediaSet></MediaItems>",
                            packageXml.Element("umbPackage").Element("MediaItems").ToString(SaveOptions.DisableFormatting));
                        Assert.AreEqual(2, zipArchive.Entries.Count());
                        Assert.AreEqual(ZipArchiveMode.Read, zipArchive.Mode);
                        Assert.IsNull(packageXml.DocumentType);
                        Assert.IsNull(packageXml.NextNode);
                        Assert.IsNull(packageXml.Parent);
                        Assert.IsNull(packageXml.PreviousNode);
                    });
                }
        }
示例#3
0
        public void CreateTestData()
        {
            // Create and Save folder-Media -> (1051)
            IMediaType folderMediaType = MediaTypeService.Get(1031);

            _testFolder = MediaBuilder.CreateMediaFolder(folderMediaType, -1);
            MediaService.Save(_testFolder, 0);

            // Create and Save image-Media -> (1052)
            IMediaType imageMediaType = MediaTypeService.Get(1032);

            _testImage = MediaBuilder.CreateMediaImage(imageMediaType, _testFolder.Id);
            MediaService.Save(_testImage, 0);

            // Create and Save file-Media -> (1053)
            IMediaType fileMediaType = MediaTypeService.Get(1033);

            _testFile = MediaBuilder.CreateMediaFile(fileMediaType, _testFolder.Id);
            MediaService.Save(_testFile, 0);
        }