FillInMapForPossibilities() private method

Fills the in map of English name to CmPossibility object.
Allow access to tests.
private FillInMapForPossibilities ( ICmPossibility>.Dictionary mapNameToItem, IFdoOwningSequence possibilities ) : void
mapNameToItem ICmPossibility>.Dictionary
possibilities IFdoOwningSequence
return void
		public void ImportTranslatedListWithDuplicateSubitemNames()
		{
			var listDomains = m_cache.LangProject.LexDbOA.DomainTypesOA;
			Assert.AreEqual(0, listDomains.PossibilitiesOS.Count, "The Academic Domains list should be empty to start.");

			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => CreateStandardEnglishOnlyDomainTypes(listDomains));
			var xtl = new XmlTranslatedLists();
			var mapNameToItem = new Dictionary<string, ICmPossibility>();
			xtl.m_wsEn = m_wsEn;
			xtl.FillInMapForPossibilities(mapNameToItem, listDomains.PossibilitiesOS);
			Assert.AreEqual(3, listDomains.PossibilitiesOS.Count, "There should be only three toplevel Academic Domain possibilities.");
			Assert.AreEqual(11, mapNameToItem.Count, "There should be eleven Academic Domain possibilities in all for this test.");

			var reader = new StringReader(s_ksAcademicDomainTranslations);
			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => xtl.ImportTranslatedLists(reader, m_cache, null));

			var mapNameToItem2 = new Dictionary<string, ICmPossibility>();
			xtl.FillInMapForPossibilities(mapNameToItem2, listDomains.PossibilitiesOS);
			Assert.AreEqual(11, mapNameToItem2.Count, "Import should not add any new items: there should still be eleven Academic Domain possibilities.");

			foreach (var key in mapNameToItem.Keys)
			{
				var item = mapNameToItem[key];
				var item2 = mapNameToItem2[key];
				Assert.AreSame(item, item2, "The import should retain the existing items.");
				var keypath = key.Split(':');
				var name = keypath[keypath.Length - 1];
				var nameEnglish = item.Name.get_String(m_wsEn).Text;
				Assert.AreEqual(name, nameEnglish, "Import should not change the English name.");
				var nameFrench = item.Name.get_String(m_wsFr).Text;
				Assert.IsNotNullOrEmpty(nameFrench, "Every item should have a French name after import.");
				var abbrEnglish = item.Abbreviation.get_String(m_wsEn).Text;
				Assert.IsNotNullOrEmpty(abbrEnglish, "Every item should still have an English abbreviation after import.");
				var abbrFrench = item.Abbreviation.get_String(m_wsFr).Text;
				Assert.IsNotNullOrEmpty(abbrFrench, "Every item should have an French abbreviation after import.");
			}
			// Check first occurrence of "applied linguistics"
			var poss = mapNameToItem[":linguistics:applied linguistics"];
			var frenchName = poss.Name.get_String(m_wsFr).Text.Normalize(System.Text.NormalizationForm.FormC);
			Assert.AreEqual("linguistique appliquée", frenchName);
			var frenchAbbr = poss.Abbreviation.get_String(m_wsFr).Text;
			Assert.AreEqual("Ling app", frenchAbbr);
			// Check second occurrenence of "applied linguistics"
			poss = mapNameToItem[":sociolinguistics:applied linguistics"];
			frenchName = poss.Name.get_String(m_wsFr).Text.Normalize(System.Text.NormalizationForm.FormC);
			Assert.AreEqual("linguistique appliquée", frenchName);
			frenchAbbr = poss.Abbreviation.get_String(m_wsFr).Text;
			Assert.AreEqual("Ling app", frenchAbbr);
		}
		public void ImportTranslatedListWithSubclassTypes()
		{
			var listTypes = m_cache.LangProject.LexDbOA.VariantEntryTypesOA;

			var xtl = new XmlTranslatedLists();
			var mapNameToItem = new Dictionary<string, ICmPossibility>();

			xtl.m_wsEn = m_wsEn;
			xtl.FillInMapForPossibilities(mapNameToItem, listTypes.PossibilitiesOS);

			Assert.AreEqual(6, mapNameToItem.Count, "We should start with six variant types.");
			int countSubtypeItems = 0;
			foreach (var key in mapNameToItem.Keys)
			{
				var keypath = key.Split(':');
				var name = keypath[keypath.Length - 1];
				var item = mapNameToItem[key];
				var nameEnglish = item.Name.get_String(m_wsEn).Text;
				Assert.AreEqual(name, nameEnglish, "The list should have English names before import.");
				var nameFrench = item.Name.get_String(m_wsFr).Text;
				Assert.IsNullOrEmpty(nameFrench, "The original list should have no French names.");
				var abbrEnglish = item.Abbreviation.get_String(m_wsEn).Text;
				Assert.IsNotNullOrEmpty(abbrEnglish, "The list should have English abbreviations before import.");
				var abbrFrench = item.Abbreviation.get_String(m_wsFr).Text;
				Assert.IsNullOrEmpty(abbrFrench, "The original list should have no French abbreviations.");
				var descFrench = item.Description.get_String(m_wsFr).Text;
				Assert.IsNullOrEmpty(descFrench, "The original list should have no French descriptions.");
				var inflType = item as ILexEntryInflType;
				if (inflType != null)
				{
					++countSubtypeItems;
					var glossEnglish = inflType.GlossAppend.get_String(m_wsEn).Text;
					if (String.IsNullOrEmpty(glossEnglish))
					{
						// Test data isn't set up quite like default new project data, so tweak it a bit for later on.
						if (name == "Plural Variant")
							NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => inflType.GlossAppend.set_String(m_wsEn, ".pl"));
						else if (name == "Past Variant")
							NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => inflType.GlossAppend.set_String(m_wsEn, ".pst"));
					}
					var glossFrench = inflType.GlossAppend.get_String(m_wsFr).Text;
					Assert.IsNullOrEmpty(glossFrench, "The original list should have no French 'GlossAppend' values.");
				}
			}
			Assert.AreEqual(3, countSubtypeItems, "The list should have three ILexEntryInflType objects.");

			var reader = new StringReader(s_ksVariantTypesTranslations);
			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => xtl.ImportTranslatedLists(reader, m_cache, null));

			var mapNameToItem2 = new Dictionary<string, ICmPossibility>();
			xtl.FillInMapForPossibilities(mapNameToItem2, listTypes.PossibilitiesOS);
			Assert.AreEqual(6, mapNameToItem2.Count, "Import should not add any new items: there should still be six variant types.");

			int countNoFrench = 0;
			foreach (var key in mapNameToItem.Keys)
			{
				var item = mapNameToItem[key];
				var item2 = mapNameToItem2[key];
				Assert.AreSame(item, item2, "The import should retain the existing items.");
				var keypath = key.Split(':');
				var name = keypath[keypath.Length - 1];
				var nameEnglish = item.Name.get_String(m_wsEn).Text;
				Assert.AreEqual(name, nameEnglish, "Import should not change the English name.");
				var nameFrench = item.Name.get_String(m_wsFr).Text;
				Assert.IsNotNullOrEmpty(nameFrench, "The list should have French names after import.");
				var abbrEnglish = item.Abbreviation.get_String(m_wsEn).Text;
				Assert.IsNotNullOrEmpty(abbrEnglish, "The list should still have English abbreviations after import.");
				var abbrFrench = item.Abbreviation.get_String(m_wsFr).Text;
				Assert.IsNotNullOrEmpty(abbrFrench, "The list should have French abbreviations after import.");
				var descFrench = item.Description.get_String(m_wsFr).Text;
				Assert.IsNotNullOrEmpty(descFrench, "The list should have French descriptions after import.");
				var inflType = item as ILexEntryInflType;
				if (inflType != null)
				{
					var ga = inflType.GlossAppend;
					var cws = ga.StringCount;
					var ui = ga.UiString;
					var glossEnglish = inflType.GlossAppend.get_String(m_wsEn).Text;
					var glossFrench = inflType.GlossAppend.get_String(m_wsFr).Text;
					if (String.IsNullOrEmpty(glossEnglish))
					{
						++countNoFrench;
						Assert.IsNullOrEmpty(glossFrench, "The list should have no French if it has no English for 'GlossAppend' values.");
					}
					else
					{
						Assert.IsNotNullOrEmpty(glossFrench, "The list should have French if it has English for 'GlossAppend' values.");
					}
				}
			}
			Assert.AreEqual(1, countNoFrench, "Only one item should lack a French translation due to no English.");

			// Finally, just to be exhaustive, let's examine a few specific values.

			var type = mapNameToItem[":Dialectal Variant"] as ILexEntryType;
			var frenchName = type.Name.get_String(m_wsFr).Text;
			Assert.AreEqual("Variante Dialectale", frenchName);
			var typeinfl = type as ILexEntryInflType;
			Assert.IsNull(typeinfl);

			type = mapNameToItem[":Free Variant"] as ILexEntryType;
			frenchName = type.Name.get_String(m_wsFr).Text;
			Assert.AreEqual("Variante Gratuitement", frenchName);
			typeinfl = type as ILexEntryInflType;
			Assert.IsNull(typeinfl);

			type = mapNameToItem[":Irregular Inflectional Variant"] as ILexEntryType;
			frenchName = type.Name.get_String(m_wsFr).Text.Normalize(System.Text.NormalizationForm.FormC);
			Assert.AreEqual("Irrégulière Forme Fléchie", frenchName);
			typeinfl = type as ILexEntryInflType;
			Assert.IsNotNull(typeinfl);
			var frenchGlossAppend = typeinfl.GlossAppend.get_String(m_wsFr).Text;
			Assert.IsNullOrEmpty(frenchGlossAppend, "Irregular Inflectional Variant should not have a GlossAppend value.");

			type = mapNameToItem[":Plural Variant"] as ILexEntryType;
			frenchName = type.Name.get_String(m_wsFr).Text;
			Assert.AreEqual("Pluriel", frenchName);
			typeinfl = type as ILexEntryInflType;
			Assert.IsNotNull(typeinfl);
			frenchGlossAppend = typeinfl.GlossAppend.get_String(m_wsFr).Text;
			Assert.AreEqual(".plu", frenchGlossAppend);

			type = mapNameToItem[":Past Variant"] as ILexEntryType;
			frenchName = type.Name.get_String(m_wsFr).Text.Normalize(System.Text.NormalizationForm.FormC);
			Assert.AreEqual("Passé", frenchName);
			typeinfl = type as ILexEntryInflType;
			Assert.IsNotNull(typeinfl);
			frenchGlossAppend = typeinfl.GlossAppend.get_String(m_wsFr).Text;
			Assert.AreEqual(".pas", frenchGlossAppend);

			type = mapNameToItem[":Spelling Variant"] as ILexEntryType;
			frenchName = type.Name.get_String(m_wsFr).Text;
			Assert.AreEqual("Orthographe Variant", frenchName);
			typeinfl = type as ILexEntryInflType;
			Assert.IsNull(typeinfl);
		}