예제 #1
0
        public override void SetUp()
        {
            base.SetUp();

            root          = CreateOneItem <Items.NormalPage>(1, "root", null);
            start         = CreateOneItem <Items.NormalPage>(2, "start", root);
            part          = CreateOneItem <Items.NormalItem>(3, "part", root);
            part.ZoneName = "Zone";

            adapter = new NodeAdapter();
            adapter.ManagementPaths = new EditUrlManager(null, new N2.Configuration.EditSection());
            adapter.FileSystem      = fs = new FakeMemoryFileSystem();
            adapter.NodeFactory     = new VirtualNodeFactory();
            adapter.WebContext      = new Fakes.FakeWebContextWrapper();
            adapter.Security        = new SecurityManager(adapter.WebContext, new N2.Configuration.EditSection());
            adapter.Host            = new Host(null, root.ID, start.ID);
            adapter.Settings        = new FakeNavigationSettings();
            adapter.Sources         = TestSupport.SetupContentSource(adapter.WebContext, adapter.Host, persister.Repository);
        }
예제 #2
0
        private void SetupFileSystem(out RootDirectory rootDir, out FakeMemoryFileSystem fs)
        {
            rootDir = CreateOneItem <RootDirectory>(4, "FileSystem", root);
            ((IInjectable <IUrlParser>)rootDir).Set(TestSupport.Setup(persister, new FakeWebContextWrapper(), new Host(null, 1, 1)));
            fs = new FakeMemoryFileSystem();
            fs.directories["/FileSystem/upload/"] = new DirectoryData {
                Name = "upload"
            };

            rootDir.Set(fs);
            rootDir.Set(new ImageSizeCache(new ConfigurationManagerWrapper {
                Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, new EditSection())
            }));

            var injector = new FakeDependencyInjector();

            injector.injectors.Add(new EntityDependencySetter <IFileSystem>(fs));
            injector.injectors.Add(new EntityDependencySetter <ImageSizeCache>(new ImageSizeCache(new ConfigurationManagerWrapper())));
            rootDir.Set(injector);
        }
예제 #3
0
        public void CanExport_SimpleItem_WithFileAttachment()
        {
            XmlableItem destination = new XmlableItem();
            XmlableItem item        = CreateOneItem <XmlableItem>(1, "item", null);
            string      file        = "TestFile.txt";
            string      path        = "/Serialization/" + file;

            item.TextFile = "/Serialization/TestFile.txt";
            var sourceFs = new FakeMemoryFileSystem();

            sourceFs.files.Add(path, new N2.Edit.FileSystem.FileData {
                Name = file, VirtualPath = path
            });
            sourceFs.contents.Add(path, Encoding.UTF8.GetBytes("Just a little file."));

            string xml = ExportToString(item, CreateExporter(sourceFs), ExportOptions.Default);
            //string path = AppDomain.CurrentDomain.BaseDirectory + @"\Serialization\TestFile.txt";

            var           destinationFs = new FakeMemoryFileSystem();
            IImportRecord record        = ImportFromString(xml, CreateImporter(destinationFs));
            XmlableItem   readItem      = (XmlableItem)record.RootItem;

            Assert.AreEqual(item.ID, readItem.ID);
            Assert.That(!destinationFs.FileExists(path));

            CreateImporter(destinationFs).Import(record, destination, ImportOption.All);
            Assert.AreEqual(0, readItem.ID);
            Assert.AreEqual(item.Title, readItem.Title);
            Assert.AreEqual(item.Name, readItem.Name);
            Assert.AreEqual("/Serialization/TestFile.txt", readItem.TextFile);

            var temp   = new byte[1000];
            var size   = destinationFs.OpenFile(path).Read(temp, 0, 1000);
            var buffer = new byte[size];

            Array.Copy(temp, buffer, size);

            Assert.That(destinationFs.FileExists("/Serialization/TestFile.txt"));
            Assert.AreEqual("Just a little file.", Encoding.UTF8.GetString(buffer));
        }
예제 #4
0
        public void TracksUrl_ToItemsWithoutId()
        {
            RootDirectory rootDir = CreateOneItem <RootDirectory>(4, "FileSystem", root);

            ((IInjectable <IUrlParser>)rootDir).Set(TestSupport.Setup(persister, new FakeWebContextWrapper(), new Host(null, 1, 1)));
            var fs = new FakeMemoryFileSystem();

            fs.files["/FileSystem/upload/File.txt"] = new FileData {
                Name = "File.txt"
            };
            rootDir.Set(fs);
            rootDir.Set(new ImageSizeCache(new ConfigurationManagerWrapper {
                Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, new EditSection())
            }));

            root["TestDetail"] = @"<a href=""/FileSystem/upload/File.txt"">download pdf</a>";
            persister.Save(root);

            DetailCollection links = root.GetDetailCollection("TrackedLinks", false);

            Assert.That(links, Is.Not.Null);
            Assert.That(links.Details[0].LinkedItem, Is.Null);
            Assert.That(links.Details[0].StringValue, Is.EqualTo("/FileSystem/upload/File.txt"));
        }