Mock version of IFileOS that lets us simulate existing files and directories.
Inheritance: IFileOS
		public void Setup()
		{
			m_origOs = (IFileOS)ReflectionHelper.GetField(typeof(FileUtils), "s_fileos");
			// Need a new one each time so tests don't affect each other.
			m_fileOs = new MockFileOS();
			ReflectionHelper.SetField(typeof(FileUtils), "s_fileos", m_fileOs);
		}
		public void AddFileAndCheckAccessibility_Locked()
		{
			IScrImportSet importSettings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create();
			Cache.LanguageProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
			importSettings.ImportTypeEnum = TypeOfImport.Other;

			var fileOs = new MockFileOS();
			try
			{
				FileUtils.Manager.SetFileAdapter(fileOs);
				string filename = fileOs.MakeSfFile("EPH", @"\c 1", @"\v 1");
				fileOs.LockFile(filename);

				IScrImportFileInfo info = importSettings.AddFile(filename, ImportDomain.Main, null, null);
				Assert.AreEqual(Encoding.ASCII, info.FileEncoding);
				Assert.AreEqual(1, importSettings.GetImportFiles(ImportDomain.Main).Count);
				StringCollection notFound;
				Assert.IsFalse(importSettings.ImportProjectIsAccessible(out notFound));
				Assert.AreEqual(1, notFound.Count);
				Assert.AreEqual(filename, notFound[0]);
			}
			finally
			{
				FileUtils.Manager.Reset();
			}
		}
Ejemplo n.º 3
0
        public void AreFilesIdentical()
        {
            MockFileOS fileOs = new MockFileOS();
            string     junk1  = fileOs.MakeFile("bla", Encoding.Default);
            string     junk2  = fileOs.MakeFile("bla", Encoding.Default);
            string     junk3  = fileOs.MakeFile("alb", Encoding.Default);

            FileUtils.Manager.SetFileAdapter(fileOs);
            try
            {
                Assert.IsTrue(FileUtils.AreFilesIdentical(junk1, junk2));
                Assert.IsFalse(FileUtils.AreFilesIdentical(junk1, junk3));
            }
            finally
            {
                FileUtils.Manager.Reset();
            }
        }
Ejemplo n.º 4
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Create a CmPicture from a dummy file.
		/// </summary>
		/// -------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			base.CreateTestData();

			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);

			m_fileOs.AddFile(m_internalPath, "123", Encoding.Default);

			m_pictureFactory = Cache.ServiceLocator.GetInstance<ICmPictureFactory>();
			m_pict = m_pictureFactory.Create(m_internalPath,
				Cache.TsStrFactory.MakeString("Test picture", Cache.DefaultVernWs),
				CmFolderTags.LocalPictures);

			Assert.IsNotNull(m_pict);
			Assert.AreEqual("Test picture", m_pict.Caption.VernacularDefaultWritingSystem.Text);
			Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.InternalPath, "Internal path not set correctly");
			Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths");
		}
		public void ImportProjectIsAccessible_Paratext6()
		{
			IScrImportSet importSettings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create();
			Cache.LanguageProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
			importSettings.ImportTypeEnum = TypeOfImport.Paratext6;

			var fileOs = new MockFileOS();
			MockParatextHelper ptHelper = null;
			try
			{
				FileUtils.Manager.SetFileAdapter(fileOs);
				ptHelper = new MockParatextHelper();
				ParatextHelper.Manager.SetParatextHelperAdapter(ptHelper);
				string paratextDir = ParatextHelper.ProjectsDirectory;

				ptHelper.AddProject("TEV", null, null, true, false, "100001");

				fileOs.AddExistingFile(Path.Combine(paratextDir, "TEV.ssf"));

				importSettings.ParatextScrProj = "KAM";
				importSettings.ParatextBTProj = "TEV";

				StringCollection projectsNotFound;
				Assert.IsFalse(importSettings.ImportProjectIsAccessible(out projectsNotFound));
				Assert.AreEqual(1, projectsNotFound.Count);
				Assert.AreEqual("KAM", projectsNotFound[0]);

				fileOs.AddExistingFile(Path.Combine(paratextDir, "KAM.ssf"));
				ptHelper.AddProject("KAM", null, null, true, false, "000101");
				Assert.IsTrue(importSettings.ImportProjectIsAccessible(out projectsNotFound));
			}
			finally
			{
				ParatextHelper.Manager.Reset();
				if (ptHelper != null)
					ptHelper.Dispose();
				FileUtils.Manager.Reset();
			}
		}
Ejemplo n.º 6
0
		public override void TestSetup()
		{
			base.TestSetup();

			m_mockFileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_mockFileOs);
			string fileGen = m_mockFileOs.MakeSfFile("GEN", @"\c 1");
			string fileRev = m_mockFileOs.MakeSfFile("REV", @"\c 1");
			m_settings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Other);
			m_settings.AddFile(fileGen, ImportDomain.Main, null, null);
			m_settings.AddFile(fileRev, ImportDomain.Main, null, null);
			m_dlg = new DummyImportDialog(null, Cache, m_settings);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Unit test helper to set up environment in which to test EnsureValidLinkedFilesFolderCore.
		/// testToExecute takes (string defaultFolder, FdoCache cache).
		/// </summary>
		public void EnsureValidLinkedFilesFolderCore_TestHelper(Action<string> testToExecute)
		{
			var defaultFolder = FileUtils.ChangePathToPlatform("/ProjectDir/LinkedFiles");

			var fileOs = new MockFileOS();
			try
			{
				FileUtils.Manager.SetFileAdapter(fileOs);

				testToExecute(defaultFolder);
			}
			finally
			{
				FileUtils.Manager.Reset();
			}
		}
Ejemplo n.º 8
0
		public override void TestSetup()
		{
			base.TestSetup();

			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);

			m_projectName = Cache.ProjectId.Handle;
			m_pathExtension = ".desktop";
			var pathDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
			var pathTmp = Path.GetTempPath();
			m_expectedPathDesktop = Path.Combine(pathDesktop, m_projectName + m_pathExtension);
			m_expectedPathTmp = Path.Combine(pathTmp, m_projectName + m_pathExtension);

			// Create these directories in mock filesystem
			m_fileOs.ExistingDirectories.Add(pathDesktop);
			m_fileOs.ExistingDirectories.Add(pathTmp.TrimEnd(
				new char[] {Path.DirectorySeparatorChar}));
		}
Ejemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Test setup stuff
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestSetup()
		{
			base.TestSetup();

			m_importSettings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create();
			m_scr.ImportSettingsOC.Add(m_importSettings);
			m_translatorNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().TranslatorAnnotationDefn;
			m_consultantNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().ConsultantAnnotationDefn;

			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);
		}
Ejemplo n.º 10
0
		public void Setup()
		{
			m_defaultBepType = FDOBackendProviderType.kXML;
			m_mockFileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_mockFileOs);
		}
Ejemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			m_settings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create();
			Cache.LangProject.TranslatedScriptureOA.ImportSettingsOC.Add(m_settings);
			m_settings.ImportTypeEnum = TypeOfImport.Other;
			m_converters = null;
			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);
		}
		public void Setup()
		{
			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);
		}
Ejemplo n.º 13
0
		public void AreFilesIdentical()
		{
			MockFileOS fileOs = new MockFileOS();
			string junk1 = fileOs.MakeFile("bla", Encoding.Default);
			string junk2 = fileOs.MakeFile("bla", Encoding.Default);
			string junk3 = fileOs.MakeFile("alb", Encoding.Default);
			FileUtils.Manager.SetFileAdapter(fileOs);
			try
			{
				Assert.IsTrue(FileUtils.AreFilesIdentical(junk1, junk2));
				Assert.IsFalse(FileUtils.AreFilesIdentical(junk1, junk3));
			}
			finally
			{
				FileUtils.Manager.Reset();
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Test to see if the ImportProjectIsAccessible method works for projects other than
		/// Paratext 6.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ImportProjectIsAccessible_helper(IScrImportSet importSettings)
		{
			var fileOs = new MockFileOS();
			try
			{
				FileUtils.Manager.SetFileAdapter(fileOs);
				string scrFile1 = fileOs.MakeSfFile("GEN", @"\p", @"\c 1", @"\v 1", @"\v 2");
				string scrFile2 = fileOs.MakeSfFile("EXO", @"\p", @"\c 1", @"\v 1", @"\v 2");
				string scrFile3 = fileOs.MakeSfFile("LEV", @"\p", @"\c 1", @"\v 1", @"\v 2");
				string btFileDef = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1");
				string btFileSpan = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1");
				string annotFileCons = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1");
				string annotFileTrans = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1");

				importSettings.AddFile(scrFile1, ImportDomain.Main, null, null);
				importSettings.AddFile(scrFile2, ImportDomain.Main, null, null);
				importSettings.AddFile(scrFile3, ImportDomain.Main, null, null);
				importSettings.AddFile(btFileDef, ImportDomain.BackTrans, null, null);
				importSettings.AddFile(btFileSpan, ImportDomain.BackTrans, "es", null);
				var annDefnRepo = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>();
				importSettings.AddFile(annotFileCons, ImportDomain.Annotations, null,
					annDefnRepo.ConsultantAnnotationDefn);
				importSettings.AddFile(annotFileTrans, ImportDomain.Annotations, null,
					annDefnRepo.TranslatorAnnotationDefn);

				StringCollection filesNotFound;
				Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound));
				Assert.AreEqual(0, filesNotFound.Count);
				importSettings.SaveSettings();

				// Blow away some project files: should still return true, but should
				// report missing files.
				FileUtils.Delete(scrFile2);
				FileUtils.Delete(scrFile3);
				FileUtils.Delete(btFileDef);
				FileUtils.Delete(annotFileCons);
				FileUtils.Delete(annotFileTrans);

				// Now that we've saved the settings, we'll "revert" in order to re-load from the DB
				importSettings.RevertToSaved();

				Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound));
				Assert.AreEqual(5, filesNotFound.Count);

				Assert.IsTrue(filesNotFound.Contains(scrFile2));
				Assert.IsTrue(filesNotFound.Contains(scrFile3));
				Assert.IsTrue(filesNotFound.Contains(btFileDef));
				Assert.IsTrue(filesNotFound.Contains(annotFileCons));
				Assert.IsTrue(filesNotFound.Contains(annotFileTrans));

				importSettings.SaveSettings();

				// Blow away the rest of the project files: should return false and report
				// missing files.
				FileUtils.Delete(scrFile1);
				FileUtils.Delete(btFileSpan);

				// Now that we've saved the settings, we'll "revert" in order to re-load from the DB
				importSettings.RevertToSaved();

				Assert.IsFalse(importSettings.ImportProjectIsAccessible(out filesNotFound));
				Assert.AreEqual(7, filesNotFound.Count);

				Assert.IsTrue(filesNotFound.Contains(scrFile1));
				Assert.IsTrue(filesNotFound.Contains(scrFile2));
				Assert.IsTrue(filesNotFound.Contains(scrFile3));
				Assert.IsTrue(filesNotFound.Contains(btFileDef));
				Assert.IsTrue(filesNotFound.Contains(btFileSpan));
				Assert.IsTrue(filesNotFound.Contains(annotFileCons));
				Assert.IsTrue(filesNotFound.Contains(annotFileTrans));
			}
			finally
			{
				FileUtils.Manager.Reset();
			}
		}
Ejemplo n.º 15
0
		public void Init()
		{
			m_mappingList = new ScrMappingList(MappingSet.Main, null);
			m_factory = new ScrImportFileInfoFactory();
			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);
		}