public void LiftFileIsUpdatedWhenServiceQuits()
		{
			using (
					ProjectDirectorySetupForTesting projectDirectorySetup =
							new ProjectDirectorySetupForTesting(string.Empty))
			{
				LaunchDictionaryServiceApp(kStartInServerMode, projectDirectorySetup);

				IDictionaryService dictionaryService =
						GetDictionaryService(projectDirectorySetup.PathToLiftFile,
											 Process.GetCurrentProcess().Id);
				dictionaryService.AddEntry("v",
										   "dontLooseThisWord",
										   string.Empty,
										   string.Empty,
										   string.Empty,
										   string.Empty);
				dictionaryService.DeregisterClient(Process.GetCurrentProcess().Id);
				Thread.Sleep(1000);
				AssertServiceIsClosed(projectDirectorySetup.PathToLiftFile);

				Assert.IsTrue(
						File.ReadAllText(projectDirectorySetup.PathToLiftFile).Contains(
								"dontLooseThisWord"));
			}
		}
示例#2
0
            public BackupScenario(string testName)
            {
                Palaso.Reporting.ErrorReport.IsOkToInteractWithUser = false;
                _projDir = new ProjectDirectorySetupForTesting("");

                _backupMaker = new ChorusBackupMaker(new CheckinDescriptionBuilder());
                _backupDir   = new TemporaryFolder(testName);

                _backupMaker.PathToParentOfRepositories = _backupDir.Path;
            }
示例#3
0
			public BackupScenario(string testName)
			{
				_projDir = new ProjectDirectorySetupForTesting("");

				_backupMaker = new ChorusBackupMaker();
				_backupDir = new TemporaryFolder(testName);

				_backupMaker.PathToParentOfRepositories = _backupDir.FolderPath;

			}
		public Db4oProjectSetupForTesting(string xmlOfEntries)
		{
			_projectDirectory = new ProjectDirectorySetupForTesting(xmlOfEntries);

			_project = new WeSayWordsProject();
			_project.LoadFromLiftLexiconPath(_projectDirectory.PathToLiftFile);
			//CacheBuilder cacheBuilder = new CacheBuilder(_projectDirectory.PathToLiftFile);
			//cacheBuilder.DoWork(new NullProgressState());

			_lexEntryRepository = new LexEntryRepository(_project.PathToRepository);
			// InMemoryRecordListManager();
		}
示例#5
0
		public void MakeWritingSystemIdChange_FileLocked_NotifiesUser()
		{
			using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>"))
			{
				WeSayWordsProject project = p.CreateLoadedProject();
				using (File.OpenWrite(p.PathToLiftFile))
				{
					WritingSystem ws = project.WritingSystems["v"];
					ws.Id = "newIdForV";
					using (new Palaso.Reporting.ErrorReport.NonFatalErrorReportExpected())
					{
						Assert.IsFalse(project.MakeWritingSystemIdChange(ws, "v"));
					}
				}
			}
		}
示例#6
0
            public EnvironmentForTest()
            {
                _projectDir = new ProjectDirectorySetupForTesting("");
                var project = _projectDir.CreateLoadedProject();

                _outputFile           = new TempFile();
                Repo                  = new LexEntryRepository(_projectDir.PathToLiftFile);
                WritingSystemIds      = new List <string>(new[] { Red, Green, Blue, Voice });
                HeadwordWritingSystem = WritingSystemDefinition.Parse(Red);
                project.WritingSystems.Set(HeadwordWritingSystem);
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Green));
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Blue));
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Voice));

                Template = new ViewTemplate
                {
                    new Field(
                        LexEntry.WellKnownProperties.Citation,
                        "LexEntry",
                        new[] { Blue, Red, Voice }),
                    new Field(
                        LexEntry.WellKnownProperties.LexicalUnit,
                        "LexEntry",
                        new[] { Red, Green, Blue, Voice }),
                    new Field(
                        LexEntry.WellKnownProperties.BaseForm,
                        "LexEntry",
                        WritingSystemIds),
                    new Field(
                        "brother",
                        "LexEntry",
                        WritingSystemIds)
                };

                var visibleCustom = new Field(
                    "VisibleCustom",
                    "LexEntry",
                    WritingSystemIds,
                    Field.MultiplicityType.ZeroOr1,
                    "MultiText"
                    );

                visibleCustom.Visibility  = CommonEnumerations.VisibilitySetting.Visible;
                visibleCustom.DisplayName = "VisibleCustom";
                Template.Add(visibleCustom);
            }
示例#7
0
		public void MakeWritingSystemIdChange_WritingSystemFoundInLift_Changed()
		{
			using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>"))
			{
				WeSayWordsProject project = p.CreateLoadedProject();
				XmlDocument doc = new XmlDocument();
				doc.Load(p.PathToLiftFile);
				Assert.IsNotNull(doc.SelectNodes("//form[lang='v']"));
				WritingSystem ws = project.WritingSystems["v"];
				ws.Id = "newIdForV";
				Assert.IsTrue(project.MakeWritingSystemIdChange(ws, "v"));
				doc.Load(p.PathToLiftFile);
				Assert.IsNotNull(doc.SelectNodes("//form[lang='newIdForV']"));
				Assert.AreEqual("newIdForV", ws.Id);

			}
		}
		public void Setup()
		{
			string entriesXml =
					@"<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>
								<entry id='foo2'><lexical-unit><form lang='v'><text>fooTwo</text></form></lexical-unit></entry>
								<entry id='foo3'><lexical-unit><form lang='v'><text>fooThree</text></form></lexical-unit></entry>";
			_projectDirectory = new ProjectDirectorySetupForTesting(entriesXml);

			_project = new WeSayWordsProject();
			_project.LoadFromLiftLexiconPath(_projectDirectory.PathToLiftFile);
			_tabbedForm = new TabbedForm();
			_project.Tasks = new List<ITask>();
			_dashboardTask = new MockTask("Dashboard", "The control center.", true);
			_project.Tasks.Add(_dashboardTask);
			_dictionaryTask = new MockTask("Dictionary blah blah", "The whole lexicon.", true);
			_project.Tasks.Add(_dictionaryTask);

			_tabbedForm.InitializeTasks(_project.Tasks);
		}
示例#9
0
		public void CorrectFieldToOptionListNameDictionary()
		{
			using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting(""))
			{
				Field f = new Field();
				f.OptionsListFile = "PartsOfSpeech.xml";
				WeSayWordsProject project = p.CreateLoadedProject();
				Dictionary<string, string> dict = project.GetFieldToOptionListNameDictionary();
				Assert.AreEqual("PartsOfSpeech", dict[LexSense.WellKnownProperties.PartOfSpeech]);
			}
		}
示例#10
0
		public void SetupFixture()
		{
			_projectDirectory = new ProjectDirectorySetupForTesting("does not matter");
		}
示例#11
0
		public void GetOptionsListFromFieldName()
		{

			using (var x = new ProjectDirectorySetupForTesting(""))
			{
				WeSayWordsProject p = x.CreateLoadedProject();

				OptionsList list = p.GetOptionsList("POS");
				Assert.IsNotNull(list);
				Assert.IsNotNull(list.Options);
				Assert.Greater(list.Options.Count, 2);
			}
		}
示例#12
0
		public void MigrateAndSaveProduceSameVersion()
		{

			using (ProjectDirectorySetupForTesting projectDir = new ProjectDirectorySetupForTesting(""))
			{
				string configPath = Path.Combine(projectDir.PathToDirectory, "TestProj.WeSayConfig");
				File.WriteAllText(configPath,
								  "<?xml version='1.0' encoding='utf-8'?><tasks><components><viewTemplate></viewTemplate></components><task id='Dashboard' class='WeSay.CommonTools.DashboardControl' assembly='CommonTools' default='true'></task></tasks>");
				XPathDocument doc = new XPathDocument(configPath);
				string outputPath = Path.Combine(projectDir.PathToDirectory, Path.GetTempFileName());
				WeSayWordsProject.MigrateConfigurationXmlIfNeeded(doc, outputPath);
				XmlDocument docFile = new XmlDocument();
				docFile.Load(outputPath);
				XmlNode node = docFile.SelectSingleNode("configuration");
				string migrateVersion = node.Attributes["version"].Value;

				WeSayWordsProject p = projectDir.CreateLoadedProject();
				p.Save();
				docFile.Load(p.PathToConfigFile);
				node = docFile.SelectSingleNode("configuration");
				string saveVersion = node.Attributes["version"].Value;

				Assert.AreEqual(saveVersion, migrateVersion);
			}
		}
		private static void RunTest(bool startInServerMode,
									string entriesXml,
									ServiceTestingMethod serviceTestingMethod)
		{
			using (
					ProjectDirectorySetupForTesting projectDirectorySetup =
							new ProjectDirectorySetupForTesting(entriesXml))
			{
				Process p = LaunchDictionaryServiceApp(startInServerMode, projectDirectorySetup);
				//enhance: is ther a way to know when the process is quiescent?
				Thread.Sleep(2000);

				IDictionaryService dictionaryService =
						GetDictionaryService(projectDirectorySetup.PathToLiftFile,
											 Process.GetCurrentProcess().Id);
				Assert.IsNotNull(dictionaryService,
								 "Could not get ahold of a dictionary service from a launch of WeSay.  This can fail as a result of a timeout, if wesay was just too slow coming up.");
				try
				{
					serviceTestingMethod(dictionaryService);
				}
				finally
				{
					Thread.Sleep(100);
					if (dictionaryService.IsInServerMode())
					{
						dictionaryService.DeregisterClient(Process.GetCurrentProcess().Id);
					}
					else
					{
						if (p.HasExited)
						{
							//may hit this case if we make a test run multiple copies of wesay... not sure
						}
						else
						{
							p.CloseMainWindow();
						}
					}
				}
			}
		}
		private static Process LaunchDictionaryServiceApp(bool launchInServerMode,
														  ProjectDirectorySetupForTesting
																  projectDirectorySetup)
		{
			// System.Diagnostics.Process.Start("SampleDictionaryServicesApplication.exe", "-server");
			string arguments = '"' + projectDirectorySetup.PathToLiftFile + '"';
			if (launchInServerMode)
			{
				arguments += " -server";
			}
			ProcessStartInfo psi = new ProcessStartInfo(@"WeSay.App.exe", arguments);
			Process p = Process.Start(psi);

			//this only works because we only launch it once... wouldn't be adequate logic if we
			//might just be joining an existing process
			if (!launchInServerMode)
			{
				Assert.IsTrue(p.WaitForInputIdle(25000), "Gave up waiting for the UI to come up.");
			}
			else
			{
				Thread.Sleep(2000); // wait for process to start up
			}
			return p;
		}
		public void ServiceExitsWhenLastClientDeregisters()
		{
			using (
					ProjectDirectorySetupForTesting projectDirectorySetup =
							new ProjectDirectorySetupForTesting(string.Empty))
			{
				LaunchDictionaryServiceApp(kStartInServerMode, projectDirectorySetup);
				int firstClientId = Process.GetCurrentProcess().Id;

				IDictionaryService dictionaryService =
						GetDictionaryService(projectDirectorySetup.PathToLiftFile, firstClientId);
				Assert.IsNotNull(dictionaryService, "Could not get dictionary service, first time.");
				int secondClientId = firstClientId + 1; //bad thing to do in a non-test setting
				IDictionaryService dictionaryService2 =
						GetDictionaryService(projectDirectorySetup.PathToLiftFile, secondClientId);
				Assert.IsNotNull(dictionaryService2,
								 "Could not get dictionary service, second time.");
				AssertServerIsRunning(projectDirectorySetup.PathToLiftFile);
				dictionaryService.DeregisterClient(firstClientId);
				AssertServerIsRunning(projectDirectorySetup.PathToLiftFile);

				//now close the last client
				dictionaryService2.DeregisterClient(secondClientId);
				AssertServiceIsClosed(projectDirectorySetup.PathToLiftFile);
			}
		}
示例#16
0
		public void LoadPartsOfSpeechList()
		{
			using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting(""))
			{
			   // WeSayWordsProject p = CreateAndLoad();
				Field f = new Field();
				f.OptionsListFile = "PartsOfSpeech.xml";
				OptionsList list = p.CreateLoadedProject().GetOptionsList(f, false);
				Assert.IsTrue(list.Options.Count > 2);
			}
		}
示例#17
0
		private static void TryFieldNameChangeAfterMakingSafe(string oldName, string newName)
		{
			using (
					ProjectDirectorySetupForTesting dir =
							new ProjectDirectorySetupForTesting(string.Empty))
			{
				WeSayWordsProject p = dir.CreateLoadedProject();
				p.ViewTemplates.Add(new ViewTemplate());
				oldName = Field.MakeFieldNameSafe(oldName);
				newName = Field.MakeFieldNameSafe(newName);
				Field f = new Field(oldName, "LexEntry", new string[] {"en"});
				p.ViewTemplates[0].Add(f);


				using (File.OpenWrite(dir.PathToConfigFile))
				{
				}
				p.Save();
				f.FieldName = newName;
				p.MakeFieldNameChange(f, oldName);
			}
		}
示例#18
0
		public void PathProvidedAsSimpleFileName_GetsConverted()
		{
			using (ProjectDirectorySetupForTesting dir = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>"))
			{
				string oldWorkingDir= System.Environment.CurrentDirectory;
				try
				{
					using (WeSayWordsProject project = new WeSayWordsProject())
					{
						System.Environment.CurrentDirectory = dir.PathToDirectory;
						project.LoadFromLiftLexiconPath(Path.GetFileName(dir.PathToLiftFile));

						Assert.AreEqual(dir.PathToLiftFile, project.PathToLiftFile);
					}
				}
				finally
				{
					System.Environment.CurrentDirectory = oldWorkingDir;
				}

			}
		}
示例#19
0
		public void MakeFieldNameChange_FileLocked_NotifiesUser()
		{
			using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>"))
			{
				WeSayWordsProject project = p.CreateLoadedProject();
				using (File.OpenWrite(p.PathToLiftFile))
				{
					using (new Palaso.Reporting.ErrorReport.NonFatalErrorReportExpected())
					{
						Field f = new Field("old", "LexEntry", new string[] {"en"});
						project.ViewTemplates[0].Add(f);
						project.Save();
						f.FieldName = "new";
						Assert.IsFalse(project.MakeFieldNameChange(f, "old"));
					}
				}
			}
		}