public void GetChangeFor_InLogButNoChange_ReturnsSameId()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aaa", "bbb");
			log.LogChange("bbb", "aaa");
			Assert.That(log.GetChangeFor("aaa"), Is.EqualTo("aaa"));
		}
Ejemplo n.º 2
0
        public void HasChangeFor_NotInLog_ReturnsFalse()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aab", "bba");
            Assert.That(log.HasChangeFor("fff"), Is.False);
        }
		public void HasChangeFor_InLogNoChange_ReturnsFalse()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aaa", "bbb");
			log.LogChange("bbb", "aaa");
			Assert.That(log.HasChangeFor("aaa"), Is.False);
		}
Ejemplo n.º 4
0
        public void LogChange_FromSameAsTo_DoesNotLogChange()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aaa", "aaa");
            Assert.That(log.GetChangeFor("aaa"), Is.EqualTo(null));
        }
Ejemplo n.º 5
0
        public void HasChangeFor_InLogHasChange_ReturnsTrue()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aab", "bba");
            Assert.That(log.HasChangeFor("aab"), Is.True);
        }
Ejemplo n.º 6
0
        public void GetChangeFor_NotInLog_ReturnsNull()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aab", "bba");
            Assert.That(log.GetChangeFor("fff"), Is.EqualTo(null));
        }
Ejemplo n.º 7
0
        public void GetChangeFor_HasChange_ReturnsCorrectWsId()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aab", "bba");
            Assert.That(log.GetChangeFor("aab"), Is.EqualTo("bba"));
        }
            public WritingSystemChangeLog GetSampleWritingSystemChangeLog()
            {
                var log = new WritingSystemChangeLog();

                log.LogChange("aab", "bba");
                log.LogChange("ccc", "ddd");
                return(log);
            }
Ejemplo n.º 9
0
        public void GetChangeFor_InLogButNoChange_ReturnsSameId()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aaa", "bbb");
            log.LogChange("bbb", "aaa");
            Assert.That(log.GetChangeFor("aaa"), Is.EqualTo("aaa"));
        }
Ejemplo n.º 10
0
        public void HasChangeFor_InLogNoChange_ReturnsFalse()
        {
            var log = new WritingSystemChangeLog();

            log.LogChange("aaa", "bbb");
            log.LogChange("bbb", "aaa");
            Assert.That(log.HasChangeFor("aaa"), Is.False);
        }
 public void Read_SampleLogFile_PopulatesChanges()
 {
     using (var e = new TestEnvironment())
     {
         var log = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(e.GetSampleLogFilePath()));
         Assert.That(log.HasChangeFor("aaa"));
         Assert.That(log.GetChangeFor("aaa"), Is.EqualTo("ddd"));
     }
 }
		public void Read_SampleLogFile_PopulatesChanges()
		{
			using (var e = new TestEnvironment())
			{
				var log = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(e.GetSampleLogFilePath()));
				Assert.That(log.HasChangeFor("aaa"));
				Assert.That(log.GetChangeFor("aaa"), Is.EqualTo("ddd"));
			}
		}
		public void Write_NewEmptyFile_WritesModelToLogFile()
		{
			using (var e = new TestEnvironment())
			{
				string tempFilePath = Path.Combine(e._tempFolder.Path, "testchangelog.xml");
				var log = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(tempFilePath));
				log.LogChange("aab", "bba");
				log.LogAdd("aab");
				log.LogDelete("aab");
				log.LogConflate("aab","bba");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/From[text()='aab']");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='bba']");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Add/Id[text()='aab']");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Delete/Id[text()='aab']");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/From[text()='aab']");
				AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/To[text()='bba']");
			}
		}
 public void Write_NewEmptyFile_WritesModelToLogFile()
 {
     using (var e = new TestEnvironment())
     {
         string tempFilePath = Path.Combine(e._tempFolder.Path, "testchangelog.xml");
         var    log          = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(tempFilePath));
         log.LogChange("aab", "bba");
         log.LogAdd("aab");
         log.LogDelete("aab");
         log.LogConflate("aab", "bba");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/From[text()='aab']");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='bba']");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Add/Id[text()='aab']");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Delete/Id[text()='aab']");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/From[text()='aab']");
         AssertThatXmlIn.File(tempFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/To[text()='bba']");
     }
 }
		public LdmlInFolderWritingSystemRepositoryMigrator(
			string ldmlPath,
			LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
			WritingSystemCompatibility compatibilityMode
		) : base(WritingSystemDefinition.LatestWritingSystemDefinitionVersion, ldmlPath)
		{
			SearchPattern = "*.ldml";

			//The first versiongetter checks for the palaso:version node.
			//The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify
			AddVersionStrategy(new WritingSystemLdmlVersionGetter(compatibilityMode));
			AddVersionStrategy(new DefaultVersion(0, 0));

			var auditLog = new WritingSystemChangeLog(
				new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml"))
			);
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 0, compatibilityMode));
			// Version 0 strategy has been enhanced to also migrate version 1.
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 1, compatibilityMode));
		}
Ejemplo n.º 16
0
        public LdmlInFolderWritingSystemRepositoryMigrator(
            string ldmlPath,
            LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler,
            WritingSystemCompatibility compatibilityMode
            ) : base(WritingSystemDefinition.LatestWritingSystemDefinitionVersion, ldmlPath)
        {
            SearchPattern = "*.ldml";

            //The first versiongetter checks for the palaso:version node.
            //The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify
            AddVersionStrategy(new WritingSystemLdmlVersionGetter(compatibilityMode));
            AddVersionStrategy(new DefaultVersion(0, 0));

            var auditLog = new WritingSystemChangeLog(
                new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml"))
                );

            AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 0, compatibilityMode));
            // Version 0 strategy has been enhanced to also migrate version 1.
            AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 1, compatibilityMode));
        }
		public LdmlInFolderWritingSystemRepositoryMigrator(
			string ldmlPath,
			Action<int, IEnumerable<LdmlMigrationInfo>> migrationHandler,
			int versionToMigrateTo = LdmlDataMapper.CurrentLdmlVersion
		) : base(versionToMigrateTo, ldmlPath)
		{
			_removedPropertiesSetters = new Dictionary<string, List<Action<WritingSystemDefinition>>>();
			_migrationHandler = migrationHandler;
			SearchPattern = "*.ldml";

			//The first versiongetter checks for the palaso:version node.
			//The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify
			AddVersionStrategy(new WritingSystemLdmlVersionGetter());
			AddVersionStrategy(new DefaultVersion(0, 0));

			var auditLog = new WritingSystemChangeLog(
				new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml"))
			);
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(OnLdmlMigrated, auditLog, 0));
			// Version 0 strategy has been enhanced to also migrate version 1.
			AddMigrationStrategy(new LdmlVersion0MigrationStrategy(OnLdmlMigrated, auditLog, 1));
			AddMigrationStrategy(new LdmlVersion2MigrationStrategy(OnLdmlMigrated, auditLog));
		}
Ejemplo n.º 18
0
        public LdmlInFolderWritingSystemRepositoryMigrator(
            string ldmlPath,
            Action <int, IEnumerable <LdmlMigrationInfo> > migrationHandler,
            int versionToMigrateTo = LdmlDataMapper.CurrentLdmlLibraryVersion
            ) : base(versionToMigrateTo, ldmlPath)
        {
            _removedPropertiesSetters = new Dictionary <string, List <Action <WritingSystemDefinition> > >();
            _migrationHandler         = migrationHandler;
            SearchPattern             = "*.ldml";

            //The first versiongetter checks for the palaso:version node.
            //The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify
            AddVersionStrategy(new WritingSystemLdmlVersionGetter());
            AddVersionStrategy(new DefaultVersion(0, 0));

            var auditLog = new WritingSystemChangeLog(
                new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml"))
                );

            AddMigrationStrategy(new LdmlVersion0MigrationStrategy(OnLdmlMigrated, auditLog, 0));
            // Version 0 strategy has been enhanced to also migrate version 1.
            AddMigrationStrategy(new LdmlVersion0MigrationStrategy(OnLdmlMigrated, auditLog, 1));
            AddMigrationStrategy(new LdmlVersion2MigrationStrategy(OnLdmlMigrated, auditLog));
        }
		public void LogChange_FromSameAsTo_DoesNotLogChange()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aaa", "aaa");
			Assert.That(log.GetChangeFor("aaa"), Is.EqualTo(null));
		}
Ejemplo n.º 20
0
        public void MigrateIfNecassary()
        {
            if (!File.Exists(_sourceFilePath))
            {
                return;
            }
            string backupFilePath      = _sourceFilePath + ".bak";
            var    filesToDelete       = new List <string>();
            var    directoriesToDelete = new List <string>();

            if (File.Exists(backupFilePath))
            {
                File.Delete(backupFilePath);
            }
            File.Copy(_sourceFilePath, backupFilePath);
            filesToDelete.Add(backupFilePath);

            string writingSystemFolderPath = WritingSystemsFolder(Path.GetDirectoryName(_sourceFilePath));

            var changeLog =
                new WritingSystemChangeLog(
                    new WritingSystemChangeLogDataMapper(Path.Combine(writingSystemFolderPath, "idchangelog.xml")));
            var    strategy       = new WritingSystemPrefsToLdmlMigrationStrategy(_onWritingSystemTagChange, changeLog);
            string sourceFilePath = _sourceFilePath;
            string tempFolderPath = String.Format("{0}.Migrate_{1}_{2}", _sourceFilePath, strategy.FromVersion,
                                                  strategy.ToVersion);

            strategy.Migrate(sourceFilePath, tempFolderPath);

            var filesInTempFolder = Directory.GetFiles(tempFolderPath);

            if (filesInTempFolder.Length != 0)
            {
                if (!Directory.Exists(writingSystemFolderPath))
                {
                    Directory.CreateDirectory(writingSystemFolderPath);
                }
            }

            foreach (string ldmlFilePath in filesInTempFolder)
            {
                var fileName            = Path.GetFileName(ldmlFilePath);
                var destinationFilePath = Path.Combine(writingSystemFolderPath, fileName);
                if (!File.Exists(destinationFilePath))
                {
                    File.Move(ldmlFilePath, destinationFilePath);
                }
                else
                {
                    File.Delete(ldmlFilePath);
                }
            }
            Directory.Delete(tempFolderPath);

            File.Delete(_sourceFilePath);

            foreach (var filePath in filesToDelete)
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
            foreach (var filePath in directoriesToDelete)
            {
                if (Directory.Exists(filePath))
                {
                    Directory.Delete(filePath);
                }
            }
        }
		public void HasChangeFor_NotInLog_ReturnsFalse()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aab", "bba");
			Assert.That(log.HasChangeFor("fff"), Is.False);
		}
		public void GetChangeFor_HasChange_ReturnsCorrectWsId()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aab", "bba");
			Assert.That(log.GetChangeFor("aab"), Is.EqualTo("bba"));
		}
		public void GetChangeFor_NotInLog_ReturnsNull()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aab", "bba");
			Assert.That(log.GetChangeFor("fff"), Is.EqualTo(null));
		}
			public WritingSystemChangeLog GetSampleWritingSystemChangeLog()
			{
				var log = new WritingSystemChangeLog();
				log.LogChange("aab", "bba");
				log.LogChange("ccc", "ddd");
				return log;
			}
		public void HasChangeFor_InLogHasChange_ReturnsTrue()
		{
			var log = new WritingSystemChangeLog();
			log.LogChange("aab", "bba");
			Assert.That(log.HasChangeFor("aab"), Is.True);
		}