コード例 #1
0
        public void InputTemplateToAbstractConfigurationNodeCfgSerializer_Test()
        {
            var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                             "TEST_CONTROLLER",
                                                             InputDriver.Keyboard,
                                                             IDeviceEnumerator.VirtualVendorID,
                                                             new XInputDeviceInstance(0).DefaultLayout);
            IDeviceInputMapping mapping = new TestInputMapping();
            var input =
                new InputConfiguration <IRetroArchInput>(mapcol);


            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext();

            var list = context.TraverseInputTemplate(input, mapping, 0);


            var    cfgSerializer = new SimpleCfgConfigurationSerializer();
            string outputCfg     = cfgSerializer.Visit(list);

            Assert.NotEqual(string.Empty, outputCfg);
            // todo: test cfg parse
        }
コード例 #2
0
        public async Task CopyFile_Test()
        {
            var fs = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));
            var temp2 = Path.GetTempFileName();
            await System.IO.File.WriteAllBytesAsync(temp2, Data);
            // Execute the results.
            await foreach (var res in EmitCopyResult(temp2, dir))
            {
                Assert.Equal(await res.Description, $"Copied {new FileInfo(temp2).FullName} to directory {dir.Name}");
                Assert.Equal(await res.Description, $"Copied {new FileInfo(temp2).FullName} to directory {dir.Name}");
            }

            Assert.True(dir.ContainsFile(Path.GetFileName(temp2)));

            using (var stream = dir.OpenFile(Path.GetFileName(temp2)).OpenStream())
            {
                Assert.Equal(Data.Length, stream.Length);
            }

            dir.OpenFile(Path.GetFileName(temp2)).Delete();
            Assert.False(dir.ContainsFile(Path.GetFileName(temp2)));
        }
コード例 #3
0
ファイル: LinkTests.cs プロジェクト: Krashner/snowflake
        public void LinkRename_Test()
        {
            var fs = new PhysicalFileSystem();

            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var tempFile  = Path.GetTempFileName();
            var tempFile2 = Path.GetTempFileName();

            using (var str = new FileInfo(tempFile).OpenWrite())
            {
                str.WriteByte(255);
            }

            var link = dir.LinkFrom(new FileInfo(tempFile));

            Guid oldGuid = link.FileGuid;

            Assert.True(dir.ContainsFile(".manifest"));


            link.Rename(tempFile2);
            Assert.Equal(Path.GetFileName(tempFile2), link.Name);
            Assert.Equal(link.FileGuid, dir.OpenFile(tempFile2).FileGuid);
            Assert.True(new FileInfo(tempFile).Exists);
        }
コード例 #4
0
ファイル: LinkTests.cs プロジェクト: Krashner/snowflake
        public void LinkOverwritesCreatedFile_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var tempFile = Path.GetTempFileName();

            using (var str = new FileInfo(tempFile).OpenWrite())
            {
                str.WriteByte(255);
            }

            var file = dir.OpenFile(tempFile);

            using (var f = file.OpenStream())
            {
                f.WriteByte(254);
            }

            Assert.Throws <IOException>(() => dir.LinkFrom(new FileInfo(tempFile)));
            var link = dir.LinkFrom(new FileInfo(tempFile), true);

            Assert.IsAssignableFrom <Link>(link);
            using (var str = link.OpenReadStream())
            {
                Assert.Equal(255, str.ReadByte());
            }
            Assert.Equal(file.FileGuid, link.FileGuid);
        }
コード例 #5
0
        public void CollectionToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var configuration =
                new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection());

            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            string test = Path.GetRandomFileName();
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            dir.OpenDirectory("program")
            .OpenFile("RMGE01.wbfs").OpenStream().Close();
            configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648;
            var context = new ConfigurationTraversalContext(("game", dir));
            var list    = context.TraverseCollection(configuration);
            IAbstractConfigurationNode dolphinList = list["#dolphin"];

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Visit(dolphinList);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
コード例 #6
0
        public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var mapcol = new ControllerElementMappingProfile("Keyboard",
                                                             "TEST_CONTROLLER",
                                                             InputDriver.Keyboard,
                                                             IDeviceEnumerator.VirtualVendorID,
                                                             new XInputDeviceInstance(0).DefaultLayout);
            IDeviceInputMapping mapping = new TestInputMapping();
            var input =
                new InputTemplate <IRetroArchInput>(mapcol).Template;


            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext();

            var list = context.TraverseInputTemplate(input, mapping, 0);

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Transform(list);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
コード例 #7
0
        public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"];
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var           mapcol   = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            string        _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping  = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           input    =
                new InputTemplate <IRetroArchInput>(mapcol).Template;


            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext();

            var list = context.TraverseInputTemplate(input, mapping, 0);

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Transform(list);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
コード例 #8
0
ファイル: DirectoryTests.cs プロジェクト: Krashner/snowflake
        public void DirectoryMoveFromManaged_Test()
        {
            var fs  = new PhysicalFileSystem();
            var fs2 = new PhysicalFileSystem();

            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var dir2 = new FS.Directory("test2", pfs, pfs.GetDirectoryEntry("/"));

            var  tempFile = Path.GetTempFileName();
            var  file     = dir.OpenFile(tempFile);
            Guid oldGuid  = file.FileGuid;

            Assert.True(dir.ContainsFile(".manifest"));
            using (var str = file.OpenStream())
            {
                str.WriteByte(255);
            }// safe the file

            var file2 = dir2.CopyFrom(file);

            Assert.Throws <IOException>(() => dir2.MoveFrom(file));
            Assert.Equal(1, dir2.MoveFrom(file, true).Length);

            Assert.Equal(oldGuid, file2.FileGuid);
            Assert.Equal(1, file2.Length);

            Assert.False(file.Created);
            Assert.False(dir.ContainsFile(file.Name));
        }
コード例 #9
0
        public void DirectoryMoveFromManagedAndRename_Test()
        {
            var fs  = new PhysicalFileSystem();
            var fs2 = new PhysicalFileSystem();

            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var  tempFile = Path.GetTempFileName();
            var  file     = dir.OpenFile(tempFile);
            Guid oldGuid  = file.FileGuid;

            using (var str = file.OpenStream())
            {
                str.WriteByte(255);
            }// safe the file

            var newFile = dir2.MoveFrom(file, "newNonConflictingName", false);

            Assert.Throws <FileNotFoundException>(() => dir2.MoveFrom(file));
            Assert.Equal(1, newFile.Length);

            Assert.False(file.Created);
            Assert.False(dir.ContainsFile(file.Name));

            Assert.True(newFile.Created);
            Assert.Equal(newFile.FileGuid, file.FileGuid);
            Assert.Equal(newFile.FileGuid, dir2.OpenFile("newNonConflictingName").FileGuid);
        }
コード例 #10
0
        public void DirectoryCopyFromManaged_Test()
        {
            var fs  = new PhysicalFileSystem();
            var fs2 = new PhysicalFileSystem();

            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var tempFile = Path.GetTempFileName();
            var file     = dir.OpenFile(tempFile);

            using (var str = file.OpenStream())
            {
                str.WriteByte(255);
            }// safe the file

            var file2 = dir2.CopyFrom(file);

            Assert.Equal(file.FileGuid, file2.FileGuid);
            Assert.Equal(1, file2.Length);

            Assert.Throws <IOException>(() => dir2.CopyFrom(file));
            Assert.Equal(1, dir2.CopyFrom(file, true).Length);
        }
コード例 #11
0
        public async Task DirectoryCopyFromAsyncManaged_Test()
        {
            var fs  = new PhysicalFileSystem();
            var fs2 = new PhysicalFileSystem();

            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));

            var tempFile = Path.GetTempFileName();
            var file     = dir.OpenFile(tempFile);

            Assert.NotEqual(Guid.Empty, file.FileGuid);
            using (var str = file.OpenStream())
            {
                str.WriteByte(255);
            }// safe the file

            var file2 = await dir2.CopyFromAsync(file);

            Assert.Equal(file.FileGuid, file2.FileGuid);
            Assert.True(file.Created);
            Assert.Equal(1, file2.Length);

            await Assert.ThrowsAsync <IOException>(async() => await dir2.CopyFromAsync(file));

            Assert.Equal(1, (await dir2.CopyFromAsync(file, true)).Length);
        }
コード例 #12
0
        public async Task CopyFileJobQueue_Test()
        {
            var fs    = new PhysicalFileSystem();
            var temp  = Path.GetTempPath();
            var pfs   = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir   = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));
            var temp2 = Path.GetTempFileName();
            await System.IO.File.WriteAllBytesAsync(temp2, Data);

            // Execute the results.
            var tq    = new AsyncJobQueue <TaskResult <IFile> >();
            var token = await tq.QueueJob(EmitCopyResult(temp2, dir));

            for ((TaskResult <IFile> val, bool next) = await tq.GetNext(token); next; (val, next) = await tq.GetNext(token))
            {
            }

            Assert.True(dir.ContainsFile(Path.GetFileName(temp2)));

            using (var stream = dir.OpenFile(Path.GetFileName(temp2)).OpenStream())
            {
                Assert.Equal(Data.Length, stream.Length);
            }

            dir.OpenFile(Path.GetFileName(temp2)).Delete();
            Assert.False(dir.ContainsFile(Path.GetFileName(temp2)));
        }
コード例 #13
0
        public void CollectionToAbstractConfigurationNode_Test()
        {
            var configuration =
                new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection());

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648;
            var context = new ConfigurationTraversalContext(("game", dir));

            var list = context.TraverseCollection(configuration.Configuration);

            Assert.Equal(2, list.Count);
            Assert.Equal(2, list["#dolphin"].Value.Count);
            Assert.DoesNotContain("TestCycle1", list.Keys);
            Assert.DoesNotContain("TestCycle2", list.Keys);

            var dolphinList = list["#dolphin"];

            foreach (var node in dolphinList.Value)
            {
                if (node.Key == "Display")
                {
                    var confList = (node as ListConfigurationNode).Value;
                    Assert.Equal(7, confList.Count);
                    Assert.Equal("FullscreenResolution", confList[0].Key);
                    Assert.IsType <EnumConfigurationNode>(confList[0]);
                    Assert.Equal("1152x648", ((EnumConfigurationNode)confList[0]).Value);
                    Assert.Equal(FullscreenResolution.Resolution1152X648, confList[0].Value);

                    Assert.Equal("Fullscreen", confList[1].Key);
                    Assert.IsType <BooleanConfigurationNode>(confList[1]);

                    Assert.Equal("RenderToMain", confList[2].Key);
                    Assert.IsType <BooleanConfigurationNode>(confList[2]);

                    Assert.Equal("RenderWindowWidth", confList[3].Key);
                    Assert.IsType <IntegralConfigurationNode>(confList[3]);

                    Assert.Equal("RenderWindowHeight", confList[4].Key);
                    Assert.IsType <IntegralConfigurationNode>(confList[4]);

                    Assert.Equal("ISOPath0", confList[5].Key);
                    Assert.IsType <StringConfigurationNode>(confList[5]);

                    Assert.Equal("InternalCpuRatio", confList[6].Key);
                    Assert.IsType <DecimalConfigurationNode>(confList[6]);
                }

                if (node.Key == "TestNestedSection")
                {
                    Assert.Equal("TestNestedNestedSection", (node as ListConfigurationNode).Value[0].Key);
                }
            }
        }
コード例 #14
0
        public async Task ExtractZipJobQueue_Test()
        {
            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            string test = Path.GetRandomFileName();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            var    dirToCopy    = new DirectoryInfo(temp).CreateSubdirectory(Path.GetRandomFileName());
            var    subDirToCopy = dirToCopy.CreateSubdirectory(Path.GetRandomFileName());
            string fileName;

            using (var file = System.IO.File.Create(Path.Combine(subDirToCopy.FullName, Path.GetRandomFileName())))
            {
                fileName = Path.GetFileName(file.Name);
                await file.WriteAsync(Data, 0, Data.Length);
            }

            var subSubDirToCopy = subDirToCopy
                                  .CreateSubdirectory(Path.GetRandomFileName());

            string zipFile = Path.GetTempFileName();

            System.IO.File.Delete(zipFile); // hack to get around file existing.
            ZipFile.CreateFromDirectory(dirToCopy.FullName, zipFile, CompressionLevel.Fastest, true);

            var tq    = new AsyncJobQueue <TaskResult <IFile> >();
            var token = await tq.QueueJob(EmitZipResult(zipFile, dir));

            await foreach (var res in tq.AsEnumerable(token))
            {
                var val = await res;
                if (res.Error != null)
                {
                    throw res.Error.InnerException;
                }
            }


            Assert.True(dir.ContainsDirectory(dirToCopy.Name), "Did not extract parent successfully");
            Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");
            using (var file = dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).OpenStream()) {
                Assert.Equal(Data.Length, file.Length);
            }
            Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsDirectory(subSubDirToCopy.Name), "Did not copy nested folder successfully");

            dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).Delete();
            Assert.False(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not cleanup file successfully");

            try
            {
                // nothing to do with tests here if this fails
                System.IO.File.Delete(zipFile);
            } catch
            {
            }
        }
コード例 #15
0
        /// <inheritdoc/>
        public IPluginProvision GetProvision <T>(IModule composableModule)
            where T : IPlugin
        {
            var appDataPath = rootFs.ConvertPathFromInternal(this.contentDirectory.ApplicationData.FullName);

            var resourcePath = rootFs.ConvertPathFromInternal(composableModule.ContentsDirectory.FullName) / "resource";

            var pluginAttr = typeof(T).GetTypeInfo().GetCustomAttribute <PluginAttribute>();

            if (pluginAttr == null)
            {
                throw new InvalidOperationException(
                          $"Can not load provision for {typeof(T)} without a PluginAttribute");
            }

            if (pluginAttr.PluginName == "common")
            {
                throw new UnauthorizedAccessException("Plugin name can not be 'common'.");
            }

            var pluginResourceDirectory       = resourcePath / pluginAttr.PluginName;
            var pluginCommonResourceDirectory = resourcePath / "common";

            var pluginResourceFs  = rootFs.GetOrCreateSubFileSystem(pluginResourceDirectory);
            var pluginResourceDir = new FS.Directory(pluginResourceFs);

            var pluginCommonFs  = rootFs.GetOrCreateSubFileSystem(pluginCommonResourceDirectory);
            var pluginCommonDir = new FS.Directory(pluginCommonFs);

            var pluginJsonFile = pluginResourceDir.EnumerateFilesRecursive()
                                 .FirstOrDefault(f => f.Name == "plugin.json");

            if (pluginJsonFile == null)
            {
                throw new FileNotFoundException($"Unable to find plugin.json for {pluginAttr.PluginName}");
            }

            IPluginProperties properties = new JsonPluginProperties(JObject
                                                                    .FromObject(JsonConvert
                                                                                .DeserializeObject(pluginJsonFile.ReadAllText()),
                                                                                new JsonSerializer {
                Culture = CultureInfo.InvariantCulture
            }));

            var pluginDataFs = rootFs.GetOrCreateSubFileSystem(appDataPath / "plugindata" / pluginAttr.PluginName);

            return(new PluginProvision(this.logProvider.GetLogger($"Plugin:{pluginAttr.PluginName}"),
                                       properties,
                                       this.configurationStore,
                                       pluginAttr.PluginName,
                                       properties.Get(PluginInfoFields.Author) ?? pluginAttr.Author,
                                       properties.Get(PluginInfoFields.Description) ?? pluginAttr.Description,
                                       pluginAttr.Version, composableModule.ContentsDirectory,
                                       new FS.Directory(pluginDataFs),
                                       pluginCommonDir, pluginResourceDir));
        }
コード例 #16
0
        public void DirectoryManifestCreated_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            dir.OpenFile("test.txt");
            Assert.True(dir.ContainsFile(".manifest"));
        }
コード例 #17
0
        public void LinkFromDirectoryNotFoundPath_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();

            var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));

            using var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")).AsDisposable();

            Assert.Throws <DirectoryNotFoundException>(() => dir.LinkFrom(new DirectoryInfo(Path.GetRandomFileName())));
        }
コード例 #18
0
ファイル: DirectoryTests.cs プロジェクト: Krashner/snowflake
        public void DirectoryManifestPersist_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));
            var file = dir.OpenFile("test.txt");

            Assert.True(dir.ContainsFile(".manifest"));
            Assert.Equal(file.FileGuid, dir.RetrieveManifestRecord(dir.ThisDirectory.Path / Path.GetFileName("test.txt"), false).guid);
        }
コード例 #19
0
        public void LinkFromInvalidFilePath_Test()
        {
            var fs            = new PhysicalFileSystem();
            var temp          = Path.GetTempPath();
            var unmanagedFile = Path.GetTempFileName();
            var pfs           = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));

            using var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")).AsDisposable();

            System.IO.File.WriteAllText(unmanagedFile, "Hello World!");
            Assert.Throws <DirectoryNotFoundException>(() => dir.LinkFrom(new FileInfo(unmanagedFile), "$$::\0^"));
        }
コード例 #20
0
        public void ProjectionSuccess_Test()
        {
            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            string test = Path.GetRandomFileName();
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            var file1 = dir.OpenFile("MyFirstFile");

            file1.OpenStream().Close();
            var file2 = dir.OpenFile("MySecondFile");

            file2.OpenStream().Close();
            var dirProj = dir.OpenDirectory("MyDirectory");

            dirProj
            .OpenFile("MyThirdFile")
            .OpenStream().Close();

            var p = new DirectoryProjection();

            p.Project("RootFile", file1)
            .Enter("SomeDirectory")
            .Project("project1", file1)
            .Enter("DeeperDirectory")
            .Project("project2", file2)
            .Project("deeperThree", dirProj)
            .Exit()
            .Project("project3", file2)
            .Exit();

            using var mountdir = dir.OpenDirectory("mountPoint")
                                 .AsDisposable();
            var mountedDirectory = p.Mount(mountdir);

            Assert.True(mountedDirectory.ContainsDirectory("SomeDirectory"));
            Assert.True(mountedDirectory.ContainsFile("RootFile"));
            var someDir = mountedDirectory.OpenDirectory("SomeDirectory");

            Assert.True(someDir.ContainsFile("project1"));
            Assert.True(someDir.ContainsDirectory("DeeperDirectory"));
            Assert.True(someDir.ContainsFile("project3"));

            var deeper = someDir.OpenDirectory("DeeperDirectory");

            Assert.True(deeper.ContainsDirectory("deeperThree"));
            Assert.True(deeper.ContainsFile("project2"));

            var deeperLink = deeper.OpenDirectory("deeperThree");

            Assert.True(deeperLink.ContainsFile("MyThirdFile"));
        }
コード例 #21
0
        public void DirectoryCanNotMountSubprojection_Test()
        {
            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            string test = Path.GetRandomFileName();
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            using var mountdir = dir.OpenDirectory("mountPoint")
                                 .AsDisposable();
            Assert.Throws <InvalidOperationException>(() => new DirectoryProjection().Enter("no").Mount(mountdir));
        }
コード例 #22
0
        public void LinkFromNonExistentFilePath_Test()
        {
            var fs            = new PhysicalFileSystem();
            var temp          = Path.GetTempPath();
            var unmanagedFile = Path.GetTempFileName();

            System.IO.File.Delete(unmanagedFile);
            var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));

            using var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")).AsDisposable();

            Assert.Throws <FileNotFoundException>(() => dir.LinkFrom(new FileInfo(unmanagedFile)));
        }
コード例 #23
0
        public void DirectoryFileGuidPersist_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));
            var file = dir.OpenFile("test.txt");
            var guid = file.FileGuid;

            Assert.NotEqual(Guid.Empty, guid);
            file.OpenStream().Close();
            Assert.Equal(dir.OpenFile("test.txt").FileGuid, guid);
        }
コード例 #24
0
        public void DirectoryMustBeEmptyToMount_Test()
        {
            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            string test = Path.GetRandomFileName();
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            using var mountdir = dir.OpenDirectory("mountPoint")
                                 .AsDisposable();
            mountdir.OpenDirectory("dummydir");
            Assert.Throws <IOException>(() => new DirectoryProjection().Mount(mountdir));
        }
コード例 #25
0
        public void TopTraversalNotAllowedTarget_Test()
        {
            var configuration =
                new ConfigurationCollection <DoubleTargetConfigurationCollection>(new ConfigurationValueCollection());

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext(("game", dir));

            Assert.Throws <InvalidOperationException>(() => context.TraverseCollection(configuration));
        }
コード例 #26
0
        public void DirectoryRecursiveFileOpen_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));
            var file = dir.OpenFile("test.txt");

            file.OpenStream().Close();
            dir.OpenDirectory(Path.GetRandomFileName()).OpenFile("test2.txt").OpenStream().Close();
            var iter = dir.EnumerateFilesRecursive();

            Assert.True(iter.Count() >= 2);
        }
コード例 #27
0
        public void DirectoryManifestRemove_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));
            var file = dir.OpenFile("test.txt");

            file.Delete();
            var newFile = dir.OpenFile("test.txt");

            Assert.NotEqual(newFile.FileGuid, file.FileGuid);
            //  Assert.True(dir.Manifest.ContainsKey("test.txt"));
        }
コード例 #28
0
ファイル: DirectoryTests.cs プロジェクト: Krashner/snowflake
        public void DirectoryDelete_Test()
        {
            var fs = new PhysicalFileSystem();

            var temp    = Path.GetTempPath();
            var pfs     = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir     = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));
            var nested  = dir.OpenDirectory("nested");
            var nested2 = nested.OpenDirectory("nested2");

            nested.Delete();
            Assert.Throws <InvalidOperationException>(() => nested.EnumerateFiles());
            Assert.Throws <InvalidOperationException>(() => nested2.EnumerateFiles());
        }
コード例 #29
0
        public void RecursiveTarget_Test()
        {
            var configuration =
                new ConfigurationCollection <DoubleTargetConfigurationCollection>(new ConfigurationValueCollection());

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext(("game", dir));

            var targets = context.TraverseCollection(configuration.Configuration);
        }
コード例 #30
0
ファイル: DirectoryTests.cs プロジェクト: Krashner/snowflake
        public void DirectoryDeepCreatePath_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var deep = dir.OpenDirectory("test/test");

#pragma warning disable CS0618                                         // Type or member is obsolete
            Assert.Equal(NormalizePath(deep.UnsafeGetPath().FullName), // lgtm [cs/call-to-obsolete-method]
                         NormalizePath(Path.Combine(temp, "test", "test", "test")));
#pragma warning restore CS0618                                         // Type or member is obsolete
        }