Esempio n. 1
0
        public GitBackuper(PathAndSpecialFolder directory)
        {
            _directory = directory;
            var directoryInfo = directory.CreateDirectoryInfo();

            Git.InitRepository(directoryInfo);
        }
Esempio n. 2
0
        public void DefaultFor()
        {
            var pathAndSpecialFolder = PathAndSpecialFolder.DefaultFor(GetType().Assembly);

            Assert.AreEqual(Environment.SpecialFolder.ApplicationData, pathAndSpecialFolder.SpecialFolder);
            Assert.AreEqual("Gu.Settings.Core.Tests", pathAndSpecialFolder.Path);
            var expected = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Gu.Settings.Core.Tests");

            Assert.AreEqual(expected, pathAndSpecialFolder.CreateDirectoryInfo().FullName);
        }
Esempio n. 3
0
 internal static void WriteElementString(
     this XmlWriter writer,
     string elementName,
     PathAndSpecialFolder directory)
 {
     writer.WriteStartElement(elementName);
     writer.WriteElementString(nameof(directory.Path), directory.Path);
     writer.WriteElementString(nameof(directory.SpecialFolder), directory.SpecialFolder?.ToString());
     writer.WriteEndElement();
 }
Esempio n. 4
0
        public void AppDataWithoutSubDirThrows()
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            Assert.Throws <ArgumentException>(() => new PathAndSpecialFolder(path, null));
            Assert.Throws <ArgumentException>(() => new PathAndSpecialFolder(path, Environment.SpecialFolder.ApplicationData));
            Assert.Throws <ArgumentException>(() => new PathAndSpecialFolder("", Environment.SpecialFolder.ApplicationData));
            Assert.Throws <ArgumentException>(() => new PathAndSpecialFolder(null, Environment.SpecialFolder.ApplicationData));
            Assert.Throws <ArgumentException>(() => PathAndSpecialFolder.Create(path));
            Assert.Throws <ArgumentException>(() => PathAndSpecialFolder.Create(new DirectoryInfo(path)));
        }
 public JsonRepositorySettings(
     PathAndSpecialFolder directoryPath,
     JsonSerializerSettings jsonSerializerSettings,
     bool isTrackingDirty,
     bool isCaching,
     BackupSettings backupSettings,
     string extension     = ".cfg",
     string tempExtension = ".tmp")
     : base(directoryPath, isTrackingDirty, isCaching, backupSettings, extension, tempExtension)
 {
     JsonSerializerSettings = jsonSerializerSettings;
 }
Esempio n. 6
0
        public void AbsolutePath()
        {
            var path = @"C:\Foo";
            var pathAndSpecialFolder = PathAndSpecialFolder.Create(path);
            var info = pathAndSpecialFolder.CreateDirectoryInfo();

            Assert.AreEqual(path, info.FullName);
            var actual = PathAndSpecialFolder.Create(info);

            Assert.AreEqual(path, actual.Path);
            Assert.AreEqual(null, actual.SpecialFolder);
        }
 public JsonRepositorySettings(
     DirectoryInfo directory,
     JsonSerializerSettings jsonSerializerSettings,
     bool isTrackingDirty,
     bool isCaching,
     BackupSettings backupSettings,
     string extension     = ".cfg",
     string tempExtension = ".tmp")
     : this(PathAndSpecialFolder.Create(directory),
            jsonSerializerSettings,
            isTrackingDirty,
            isCaching,
            backupSettings,
            extension,
            tempExtension)
 {
 }
Esempio n. 8
0
        public void CurrentDirectorySubDirectory()
        {
            var path     = @".\Settings";
            var fullName = System.IO.Path.Combine(Environment.CurrentDirectory, "Settings");
            var actuals  = new[]
            {
                PathAndSpecialFolder.Create(path),
                PathAndSpecialFolder.Create(new DirectoryInfo(fullName)),
                new PathAndSpecialFolder(path, null),
                new PathAndSpecialFolder(fullName, null),
            };

            foreach (var actual in actuals)
            {
                Assert.AreEqual(path, actual.Path);
                Assert.AreEqual(null, actual.SpecialFolder);
                var info = actual.CreateDirectoryInfo();
                Assert.AreEqual(fullName, info.FullName);
            }
        }
Esempio n. 9
0
        public void CurrentDirectory()
        {
            var path     = @".";
            var fullName = Environment.CurrentDirectory;
            var actuals  = new[]
            {
                PathAndSpecialFolder.Create(path),
                PathAndSpecialFolder.Create(new DirectoryInfo(fullName)),
                new PathAndSpecialFolder(path, null),
                new PathAndSpecialFolder(fullName, null),
            };

            foreach (var actual in actuals)
            {
                Assert.AreEqual(@".", actual.Path);
                Assert.AreEqual(null, actual.SpecialFolder);
                var info = actual.CreateDirectoryInfo();
                Assert.AreEqual(fullName, info.FullName);
            }
        }
Esempio n. 10
0
        public void AppDataNestedSubfolder()
        {
            var path    = Environment.ExpandEnvironmentVariables(@"%AppData%\Level1\Level2");
            var actuals = new[]
            {
                PathAndSpecialFolder.Create(path),
                PathAndSpecialFolder.Create(new DirectoryInfo(path)),
                new PathAndSpecialFolder(path, Environment.SpecialFolder.ApplicationData),
                new PathAndSpecialFolder(@"Level1\Level2", Environment.SpecialFolder.ApplicationData),
                new PathAndSpecialFolder(@"\Level1\Level2", Environment.SpecialFolder.ApplicationData),
                new PathAndSpecialFolder(path, null),
            };

            foreach (var actual in actuals)
            {
                Assert.AreEqual(@"Level1\Level2", actual.Path);
                Assert.AreEqual(Environment.SpecialFolder.ApplicationData, actual.SpecialFolder);
                var info = actual.CreateDirectoryInfo();
                Assert.AreEqual(path, info.FullName);
            }
        }
 public static JsonRepositorySettings DefaultFor(DirectoryInfo directory, JsonSerializerSettings jsonSettings)
 {
     return(new JsonRepositorySettings(PathAndSpecialFolder.Create(directory), jsonSettings, true, true, BackupSettings.DefaultFor(directory.CreateSubdirectory(DefaultBackupDirectoryName))));
 }