Exemplo n.º 1
0
        public void TestImportWithEmptyFile()
        {
            try
            {
                m_stateMachine = new DynamicMock(typeof(IStateMachine));

                ImportState import = new ImportState();
                import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

                string pathToEmptyFile = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\TestDocuments\empty.csv");
                Assert.IsTrue(File.Exists(pathToEmptyFile), "The file should exist on disk.");

                XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
                IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
                string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
                Guid guid = policyLanguageStore.AddLanguage(xmlLang);

                import.FileName = pathToEmptyFile;

                Assert.IsTrue(string.IsNullOrEmpty(import.ErrorMessage), "set up failure - already an error message on the import state");
                import.Enter();
                Assert.AreEqual(Properties.Resources.INVALID_CSV_FILE, import.ErrorMessage, "Unexpected error message on the import state");
            }
            finally
            {
                PolicyLanguageCache.Instance.Reset();
                XmlPolicyLanguageStore.Instance.Reset();
            }
        }
Exemplo n.º 2
0
		public void TestEnterImportStateWithExclusiveLockedFile()
		{
			try
			{
				m_stateMachine = new DynamicMock(typeof(IStateMachine));

				ImportState import = new ImportState();
				import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

				string exclusivelyLockedFilePath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\en.csv");
				Assert.IsTrue(File.Exists(exclusivelyLockedFilePath), "The file should exist on disk.");

				XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
				IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
				string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
				Guid guid = policyLanguageStore.AddLanguage(xmlLang);

				import.FileName = exclusivelyLockedFilePath;

				//open the file with no sharing permissions (as if the file was open in another editor)
				using (FileStream fs = new FileStream(exclusivelyLockedFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
				{
					import.Enter();
				}

				Assert.IsFalse(String.IsNullOrEmpty(import.ErrorMessage), "After entering the import state, DoImport should have caught (and failed gracefully) with an error message, because the file was exclusively locked");
			}
			finally
			{
				PolicyLanguageCache.Instance.Reset();
				XmlPolicyLanguageStore.Instance.Reset();
			}
		}