public void DataMigration7000058Test_SkipNonEmptyGlossAppend()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000058_NonEmptyGlossAppend.xml");
            // Set up mock MDC.
            var mockMdc = new MockMDCForDataMigration();
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000057, dtos, mockMdc, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000058, new DummyProgressDlg());
            Assert.AreEqual(7000058, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // Skip GlossAppend for Irregularly Inflected Form Type (Plural)
            {
                var iifPlural       = dtoRepos.GetDTO(kguidLexTypPluralVar);
                var iifNewPluralElt = XElement.Parse(iifPlural.Xml);
                Assert.That(iifNewPluralElt.XPathSelectElement("GlossAppend/AUni[@ws='en']").Value,
                            Is.EqualTo(".pL"));
            }

            //  Skip GlossAppend for Irregularly Inflected Form Type (Past)
            {
                var iifPast       = dtoRepos.GetDTO(kguidLexTypPastVar);
                var iifNewPastElt = XElement.Parse(iifPast.Xml);
                Assert.That(iifNewPastElt.XPathSelectElement("GlossAppend/AUni[@ws='en']").Value,
                            Is.EqualTo(".pST"));
            }
        }
示例#2
0
        public void DataMigration7000057Test_SubInflTypes()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000057_SubInflTypes.xml");
            // Set up mock MDC.
            var mockMdc = new MockMDCForDataMigration();
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000056, dtos, mockMdc, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000057, new DummyProgressDlg());
            Assert.AreEqual(7000057, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            const string guidNonStandard      = "1df6f9da-7b69-44e4-b98d-13a0cee17b77";
            const string guidNonStandardChild = "208cc589-f10f-485b-bdcc-843f046d4146";
            const string guidPluralChild      = "2bd3437f-8bde-495c-a12b-d0c8feb7c3e9";
            const string guidPastChild        = "7c607ea9-c1a0-4b7f-aee7-06ead42ac299";

            // test that non-standard (user created) Irregularly Inflected Form has the right class
            {
                var nonStandard = dtoRepos.GetDTO(guidNonStandard);
                Assert.That(nonStandard.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var nonStandardElt = XElement.Parse(nonStandard.Xml);
                Assert.That(nonStandardElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("NonStandard"));
            }

            // test that non-standard child has correct class
            {
                var nonStandardChild = dtoRepos.GetDTO(guidNonStandardChild);
                Assert.That(nonStandardChild.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var nonStandardChildElt = XElement.Parse(nonStandardChild.Xml);
                Assert.That(nonStandardChildElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("NonStandardChild"));
            }

            // test that plural child has correct class
            {
                var varTypePluralChild = dtoRepos.GetDTO(guidPluralChild);
                Assert.That(varTypePluralChild.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var varTypePluralChildElt = XElement.Parse(varTypePluralChild.Xml);
                Assert.That(varTypePluralChildElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("PluralChild"));
            }

            // test that past child has correct class
            {
                var varTypePastChild = dtoRepos.GetDTO(guidPastChild);
                Assert.That(varTypePastChild.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var varTypePastChildElt = XElement.Parse(varTypePastChild.Xml);
                Assert.That(varTypePastChildElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("PastChild"));
            }
        }
示例#3
0
        public void DataMigration7000057Test_Normal()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000057_Normal.xml");
            // Set up mock MDC.
            var mockMdc = new MockMDCForDataMigration();
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000056, dtos, mockMdc, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000057, new DummyProgressDlg());
            Assert.AreEqual(7000057, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // check that Irregularly Inflected Form Type has new class
            {
                var iifNew = dtoRepos.GetDTO(kguidLexTypIrregInflectionVar);
                Assert.That(iifNew.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var iifNewElt = XElement.Parse(iifNew.Xml);
                Assert.That(iifNewElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("Irregularly Inflected Form"));
            }

            // check that we haven't changed another owned object class
            {
                // Discussion for Irregularly Inflected Form Type
                var iifDiscussion = dtoRepos.GetDTO("b6f4c056-ea5e-11de-8a9c-0013722f8dec");
                Assert.That(iifDiscussion.Classname, Is.EqualTo(StTextTags.kClassName));
            }

            // check that Irregularly Inflected Form Type (Plural) has new class
            {
                var iifNewPlural = dtoRepos.GetDTO(kguidLexTypPluralVar);
                Assert.That(iifNewPlural, Is.Not.Null);
                Assert.That(iifNewPlural.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var iifNewPluralElt = XElement.Parse(iifNewPlural.Xml);
                Assert.That(iifNewPluralElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("Plural"));
            }

            // check that Irregularly Inflected Form Type (Past) has new class
            {
                var iifNewPast = dtoRepos.GetDTO(kguidLexTypPastVar);
                Assert.That(iifNewPast, Is.Not.Null);
                Assert.That(iifNewPast.Classname, Is.EqualTo(LexEntryInflTypeTags.kClassName));
                var iifNewPastElt = XElement.Parse(iifNewPast.Xml);
                Assert.That(iifNewPastElt.XPathSelectElement("Name/AUni").Value,
                            Is.EqualTo("Past"));
            }
        }
示例#4
0
        public void NonExistantGuidTest()
        {
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(
                1,
                new HashSet <DomainObjectDTO>(),
                m_mdc,
                null, TestDirectoryFinder.LcmDirectories);

            dtoRepos.GetDTO(Guid.NewGuid().ToString());
        }
        public void NonExistantGuidTest()
        {
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(
                1,
                new HashSet <DomainObjectDTO>(),
                m_mdc,
                null, TestDirectoryFinder.LcmDirectories);

            Assert.That(() => dtoRepos.GetDTO(Guid.NewGuid().ToString()),
                        Throws.TypeOf <ArgumentException>());
        }
        public void ExtantGuidFindsDTOTest()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            // 1. Add barebones LP.
            const string lpGuid = "9719A466-2240-4DEA-9722-9FE0746A30A6";
            var          lpDto  = CreatoDTO(dtos, lpGuid, "LangProject", null);
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(1, dtos, m_mdc, null, TestDirectoryFinder.LcmDirectories);
            var resultDto = dtoRepos.GetDTO(lpGuid);

            Assert.AreSame(lpDto, resultDto, "Wrong DTO.");
        }
示例#7
0
        public void DataMigration7000072Test()
        {
            var dtos    = DataMigrationTestServices.ParseProjectFile("DataMigration7000072.xml");
            var mockMdc = new MockMDCForDataMigration();
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000071, dtos, mockMdc, null, TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000072, new DummyProgressDlg());

            // Test to Check whether the given Reversal Index Entry has the added senses
            // Get the Reversal Index Entry with the specified guid
            var aReversalIndexEntry  = dtoRepos.GetDTO("2d1fb89c-5671-43de-8cdd-4624f4648ef4");
            var reversalIndexElement = XElement.Parse(aReversalIndexEntry.Xml);

            // Check for the Senses Tag
            var sensesElement = reversalIndexElement.Element("Senses");

            Assert.NotNull(sensesElement, "No senses‽");
            var objsurElementsList = sensesElement.Elements("objsur");
            var guidList           = new ArrayList();

            foreach (var objsurElement in objsurElementsList)
            {
                guidList.Add(objsurElement.Attribute("guid")?.Value);
            }

            Assert.AreEqual(guidList[0], "c836e945-92d3-4560-9622-bfd9656551c8");
            Assert.AreEqual(guidList[1], "d3d19eae-d840-484e-8de2-0100336808ed");

            // Test to check whether Reversal Entries collection has been removed from LexSense
            var allLexSenses = dtoRepos.AllInstancesWithSubclasses("LexSense");

            foreach (var aLexSense in allLexSenses)
            {
                var lexSenseElement       = XElement.Parse(aLexSense.Xml);
                var reveralEntriesElement = lexSenseElement.Element("ReversalEntries");
                Assert.AreEqual(reveralEntriesElement, null);
            }

            // Test to check whether the Referring Senses value has been changed to Senses under VirtualOrdering
            var allOrderings = dtoRepos.AllInstancesWithSubclasses("VirtualOrdering");

            foreach (var anOrdering in allOrderings)
            {
                var orderingElement = XElement.Parse(anOrdering.Xml);
                var field           = orderingElement.Element("Field");
                Assert.NotNull(field, "field should not be null");
                var uniValue = field.Element("Uni");
                Assert.NotNull(uniValue, "uniValue should not be null");
                Assert.AreEqual("Senses", uniValue.Value);
            }
        }
        public void RemoveDtoTest()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            // 1. Add barebones LP.
            const string lpGuid = "9719A466-2240-4DEA-9722-9FE0746A30A6";
            var          lpDto  = CreatoDTO(dtos, lpGuid, "LangProject", null);
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(1, dtos, m_mdc, null, TestDirectoryFinder.LcmDirectories);

            dtoRepos.Remove(lpDto);
            Assert.IsTrue(((DomainObjectDtoRepository)dtoRepos).Goners.Contains(lpDto), "Goner not in goners set.");
            Assert.IsNull(dtoRepos.AllInstancesSansSubclasses("LexEntry").FirstOrDefault(), "Found goner by class.");
            Assert.That(() => dtoRepos.GetDTO(lpDto.Guid),
                        Throws.ArgumentException, "Found deleted DTO by guid.");
        }
示例#9
0
        public void DataMigration7000015Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000015.xml");

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000014, dtos, mockMdc, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(dtoRepos, 7000015, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000015, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // PhSimpleContextBdry
            var oldClassElementNames = new List <string> {
                "CmObject", "PhContextOrVar", "PhPhonContext", "PhSimpleContext", "PhSimpleContextBdry"
            };
            var expectedPropertyElements = new List <string> {
                "Name", "Description", "FeatureStructure"
            };

            VerifyObject(dtoRepos.GetDTO("9719A466-2240-4DEA-9722-9FE0746A30A6"), oldClassElementNames, expectedPropertyElements);
            // StText
            oldClassElementNames = new List <string> {
                "CmObject", "StText"
            };
            expectedPropertyElements = new List <string>();
            VerifyObject(dtoRepos.GetDTO("C83E33DD-2A79-4A4B-84F6-92343C4F5324"), oldClassElementNames, expectedPropertyElements);
            // PhBdryMarker
            oldClassElementNames = new List <string> {
                "CmObject", "PhTerminalUnit", "PhBdryMarker"
            };
            expectedPropertyElements = new List <string>();
            VerifyObject(dtoRepos.GetDTO("C83E33DD-2A79-4A4B-84F6-92343C4F5325"), oldClassElementNames, expectedPropertyElements);
        }
        public void DataMigration7000014Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000014_Evaluations.xml");

            var mockMDC = SetupMDC();

            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000013, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            // SUT; Do the migration.
            m_dataMigrationManager.PerformMigration(dtoRepos, 7000014, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000014, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            //
            var firstAgent     = dtoRepos.GetDTO("c1ec8357-e382-11de-8a39-0800200c9a66");
            var secondAgent    = dtoRepos.GetDTO("c1ec8357-e382-11de-8a39-0800200c9a67");
            var thirdAgent     = dtoRepos.GetDTO("c1ec8357-e382-11de-8a39-0800200c9a68");
            var emptyAgent     = dtoRepos.GetDTO("c1ec8357-e382-11de-8a39-0800200c9a6c");
            var firstAnalysis  = dtoRepos.GetDTO("c84614e6-168b-4304-a025-0d6ae6573086");
            var secondAnalysis = dtoRepos.GetDTO("c84614e6-168b-4304-a025-0d6ae6573087");

            string firstApprovesGuid,
                   firstDisapprovesGuid,
                   secondApprovesGuid,
                   secondDisapprovesGuid,
                   thirdApprovesGuid,
                   thirdDisapprovesGuid,
                   emptyApprovesGuid,
                   emptyDisapprovesGuid;

            VerifyAgent(firstAgent, dtoRepos, out firstApprovesGuid, out firstDisapprovesGuid);
            VerifyAgent(secondAgent, dtoRepos, out secondApprovesGuid, out secondDisapprovesGuid);
            VerifyAgent(thirdAgent, dtoRepos, out thirdApprovesGuid, out thirdDisapprovesGuid);
            VerifyAgent(emptyAgent, dtoRepos, out emptyApprovesGuid, out emptyDisapprovesGuid);

            VerifyAnalysis(firstAnalysis, new string[] { firstApprovesGuid, secondDisapprovesGuid, thirdApprovesGuid });
            VerifyAnalysis(secondAnalysis, new string[] { firstApprovesGuid });

            var goners = ((DomainObjectDtoRepository)dtoRepos).Goners;

            Assert.AreEqual(4, goners.Count, "Wrong number removed.");
            var gonerGuids = new List <string>
            {
                ("c84614e6-168b-4304-a025-0d6ae6573085").ToLower(),
                ("c84614e6-168b-4304-a025-0d6ae6573088").ToLower(),
                ("8151a002-a32e-476f-9c32-f95ee48fc71c").ToLower(),
                ("c84614e6-168b-4304-a025-0d6ae657308a").ToLower()
            };

            foreach (var goner in goners)
            {
                Assert.Contains(goner.Guid.ToLower(), gonerGuids, "Goner guid not found.");
            }
        }
        public void AddNewDtoTest()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            // 1. Add barebones LP.
            const string lpGuid = "9719A466-2240-4DEA-9722-9FE0746A30A6";

            CreatoDTO(dtos, lpGuid, "LangProject", null);
            const string lexDbGuid = "6C84F84A-5B99-4CF5-A7D5-A308DDC604E0";

            CreatoDTO(dtos, lexDbGuid, "LexDb", null);
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(1, dtos, m_mdc, null, TestDirectoryFinder.LcmDirectories);

            // Create new DTO and add it.
            var newGuid = Guid.NewGuid();
            var newby   = new DomainObjectDTO(newGuid.ToString(), "LexEntry", "<rt />");

            dtoRepos.Add(newby);
            Assert.AreSame(newby, dtoRepos.GetDTO(newGuid.ToString()), "Wrong new DTO from guid.");
            Assert.AreSame(newby, dtoRepos.AllInstancesSansSubclasses("LexEntry").First(), "Wrong new DTO from class.");
            Assert.IsTrue(((DomainObjectDtoRepository)dtoRepos).Newbies.Contains(newby), "Newby not in newbies set.");
        }
示例#12
0
        public void DataMigration7000005Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000005Tests.xml");

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "LangProject", "CmMajorObject",
                "RnGenericRec",
                "RnRoledPartic", "StText", "StPara",
                "CmPossibility"
            });
            mockMDC.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMDC.AddClass(3, "StText", "CmObject", new List <string>());
            mockMDC.AddClass(4, "CmMajorObject", "CmObject", new List <string> {
                "RnResearchNbk", "CmPossibilityList"
            });
            mockMDC.AddClass(5, "RnResearchNbk", "CmMajorObject", new List <string>());
            mockMDC.AddClass(6, "RnGenericRec", "CmObject", new List <string> {
                "RnEvent", "RnAnalysis"
            });
            mockMDC.AddClass(7, "RnRoledPartic", "CmObject", new List <string>());
            mockMDC.AddClass(8, "CmPossibility", "CmObject", new List <string> {
                "CmPerson", "CmAnthroItem"
            });
            mockMDC.AddClass(9, "StPara", "CmObject", new List <string> {
                "StTxtPara"
            });
            mockMDC.AddClass(10, "StTxtPara", "StPara", new List <string>());
            mockMDC.AddClass(11, "CmPossibilityList", "CmMajorObject", new List <string>());
            mockMDC.AddClass(12, "RnEvent", "RnGenericRec", new List <string>());
            mockMDC.AddClass(13, "RnAnalysis", "RnGenericRec", new List <string>());
            mockMDC.AddClass(14, "CmPerson", "CmPossibility", new List <string>());
            mockMDC.AddClass(15, "CmAnthroItem", "CmPossibility", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000004, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000005, new DummyProgressDlg());

            var nbkDto     = dtoRepos.AllInstancesSansSubclasses("RnResearchNbk").First();
            var nbkElement = XElement.Parse(nbkDto.Xml);

            Assert.AreEqual(7000005, dtoRepos.CurrentModelVersion, "Wrong updated version.");
            // Get the RecTypes Element in RnResearchNbk
            Assert.IsNotNull(nbkElement.XPathSelectElement("RnResearchNbk/RecTypes"));
            // Get the EventTypes Element in RnResearchNbk (should be renamed to RecTypes)
            Assert.IsNull(nbkElement.XPathSelectElement("RnResearchNbk/EventTypes"));

            var typesDto     = dtoRepos.GetDTO(nbkElement.XPathSelectElement("RnResearchNbk/RecTypes/objsur").Attribute("guid").Value);
            var typesElement = XElement.Parse(typesDto.Xml);

            // Should be 5 cmPossibility entries in the list
            Assert.AreEqual(5, typesElement.XPathSelectElements("CmPossibilityList/Possibilities/objsur").Count());

            var anaDto     = dtoRepos.GetDTO("82290763-1633-4998-8317-0EC3F5027FBD");
            var anaElement = XElement.Parse(anaDto.Xml);

            Assert.AreEqual("Ana", anaElement.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']").Value);

            foreach (var GenRecDto in dtoRepos.AllInstancesSansSubclasses("RnGenericRec"))
            {
                var recElement     = XElement.Parse(GenRecDto.Xml);
                var typeSurElement = recElement.XPathSelectElement("RnGenericRec/Type/objsur");
                if (typeSurElement.Attribute("guid").Value == "82290763-1633-4998-8317-0EC3F5027FBD")
                {
                    Assert.IsNotNull(recElement.XPathSelectElement("RnGenericRec/Conclusions"));
                    Assert.AreEqual(19, recElement.Element("RnGenericRec").Elements().Count());
                }
                else
                {
                    Assert.IsNotNull(recElement.XPathSelectElement("RnGenericRec/Description"));
                    Assert.AreEqual(21, recElement.Elements("RnGenericRec").Elements().Count());
                }
            }

            // Look for RnEvent records -shouldn't be any
            Assert.AreEqual(0, dtoRepos.AllInstancesSansSubclasses("RnEvent").Count());
            // Look for RnAnalysis records -shouldn't be any
            Assert.AreEqual(0, dtoRepos.AllInstancesSansSubclasses("RnAnalysis").Count());
        }
        public void DataMigration7000027Test()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            var sb   = new StringBuilder();

            // 1. Add barebones LP.
            sb.Append("<rt class=\"LangProject\" guid=\"9719A466-2240-4DEA-9722-9FE0746A30A6\">");
            sb.Append("<Texts>");
            StTextAndParaInfo lpTextsGuids = new StTextAndParaInfo("9719A466-2240-4DEA-9722-9FE0746A30A6", "Normal", false, false);

            sb.Append("<objsur guid=\"" + lpTextsGuids.textGuid + "\" t=\"o\" />");
            sb.Append("</Texts>");
            sb.Append("<TranslatedScripture>");
            sb.Append("<objsur guid=\"2c5c1f5f-1f08-41d7-99fe-23893ee4ceef\" t=\"o\" />");
            sb.Append("</TranslatedScripture>");
            sb.Append("</rt>");
            var lpDto = new DomainObjectDTO("9719A466-2240-4DEA-9722-9FE0746A30A6",
                                            "LangProject", sb.ToString());

            dtos.Add(lpDto);

            // Add text dto.
            var txtDto = new DomainObjectDTO(lpTextsGuids.textGuid.ToString(), "StText",
                                             lpTextsGuids.textXml);

            dtos.Add(txtDto);
            // Add text para dto.
            var txtParaDto = new DomainObjectDTO(lpTextsGuids.paraGuid.ToString(), "ScrTxtPara",
                                                 lpTextsGuids.paraXml);

            dtos.Add(txtParaDto);

            // 2. Add Scripture
            sb = new StringBuilder();
            sb.Append("<rt class=\"Scripture\" guid=\"2c5c1f5f-1f08-41d7-99fe-23893ee4ceef\" ownerguid=\"9719A466-2240-4DEA-9722-9FE0746A30A6\" owningflid=\"6001040\" owningord=\"0\">");
            sb.Append("<Books>");
            sb.Append("<objsur guid=\"f213db11-7007-4a2f-9b94-06d6c96014ca\" t=\"o\" />");
            sb.Append("</Books>");
            sb.Append("</rt>");
            var scrDto = new DomainObjectDTO("2c5c1f5f-1f08-41d7-99fe-23893ee4ceef", "Scripture",
                                             sb.ToString());

            dtos.Add(scrDto);

            // 3. Add a ScrBook
            sb = new StringBuilder();
            sb.Append("<rt class=\"ScrBook\" guid=\"f213db11-7007-4a2f-9b94-06d6c96014ca\" ownerguid=\"2c5c1f5f-1f08-41d7-99fe-23893ee4ceef\" owningflid=\"3001001\" owningord=\"0\">");
            sb.Append("<Name>");
            sb.Append("<AUni ws=\"fr\">Genesis</AUni>");
            sb.Append("</Name>");
            sb.Append("<Title>");
            StTextAndParaInfo titleTextGuids = new StTextAndParaInfo("f213db11-7007-4a2f-9b94-06d6c96014ca", "Title Main", true, false);

            sb.Append("<objsur guid=\"" + titleTextGuids.textGuid + "\" t=\"o\" />");
            sb.Append("</Title>");
            sb.Append("<Sections>");
            sb.Append("<objsur guid=\"834e1bf8-3a25-47d6-9f92-806b38b5f815\" t=\"o\" />");
            sb.Append("</Sections>");
            sb.Append("<Footnotes>");
            StTextAndParaInfo footnoteGuids = new StTextAndParaInfo("ScrFootnote", "f213db11-7007-4a2f-9b94-06d6c96014ca", "Title Main", null, true, false);

            sb.Append("<objsur guid=\"" + footnoteGuids.textGuid + "\" t=\"o\" />");
            sb.Append("</Footnotes>");
            sb.Append("</rt>");
            var bookDto = new DomainObjectDTO("f213db11-7007-4a2f-9b94-06d6c96014ca", "ScrBook", sb.ToString());

            dtos.Add(bookDto);

            // Add title
            var titleDto = new DomainObjectDTO(titleTextGuids.textGuid.ToString(), "StText",
                                               titleTextGuids.textXml);

            dtos.Add(titleDto);
            // Title para
            var titleParaDto = new DomainObjectDTO(titleTextGuids.paraGuid.ToString(), "ScrTxtPara",
                                                   titleTextGuids.paraXml);

            dtos.Add(titleParaDto);

            // Add footnote
            var footnoteDto = new DomainObjectDTO(footnoteGuids.textGuid.ToString(), "ScrFootnote",
                                                  footnoteGuids.textXml);

            dtos.Add(footnoteDto);
            // Footnote para
            var footnoteParaDto = new DomainObjectDTO(footnoteGuids.paraGuid.ToString(), "ScrTxtPara",
                                                      footnoteGuids.paraXml);

            dtos.Add(footnoteParaDto);

            // 4. Add a section to the book
            sb = new StringBuilder();
            sb.Append("<rt class=\"ScrSection\" guid=\"834e1bf8-3a25-47d6-9f92-806b38b5f815\" ownerguid=\"f213db11-7007-4a2f-9b94-06d6c96014ca\" owningflid=\"3002001\" owningord=\"0\">");
            sb.Append("<Content>");
            StTextAndParaInfo contentsTextGuids = new StTextAndParaInfo("StText", "834e1bf8-3a25-47d6-9f92-806b38b5f815", "Paragraph",
                                                                        "<Run ws=\"fr\" ownlink=\"" + footnoteGuids.textGuid + "\"></Run>", true, false);

            sb.Append("<objsur guid=\"" + contentsTextGuids.textGuid + "\" t=\"o\" />");
            sb.Append("</Content>");
            sb.Append("<Heading>");
            StTextAndParaInfo headingTextGuids = new StTextAndParaInfo("834e1bf8-3a25-47d6-9f92-806b38b5f815", "Section Head", true, false);

            sb.Append("<objsur guid=\"" + headingTextGuids.textGuid + "\" t=\"o\" />");
            sb.Append("</Heading>");
            sb.Append("</rt>");
            var sectionDto = new DomainObjectDTO("834e1bf8-3a25-47d6-9f92-806b38b5f815", "ScrSection",
                                                 sb.ToString());

            dtos.Add(sectionDto);

            // Add the contents
            var contentsDto = new DomainObjectDTO(contentsTextGuids.textGuid.ToString(), "StText",
                                                  contentsTextGuids.textXml);

            dtos.Add(contentsDto);
            // Contents para
            var contentsParaDto = new DomainObjectDTO(contentsTextGuids.paraGuid.ToString(), "ScrTxtPara",
                                                      contentsTextGuids.paraXml);

            dtos.Add(contentsParaDto);

            // Add the heading to the xml
            var headingDto = new DomainObjectDTO(headingTextGuids.textGuid.ToString(), "StText",
                                                 headingTextGuids.textXml);

            dtos.Add(headingDto);
            // heading para
            var headingParaDto = new DomainObjectDTO(headingTextGuids.paraGuid.ToString(), "ScrTxtPara",
                                                     headingTextGuids.paraXml);

            dtos.Add(headingParaDto);

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "LangProject", "StText", "Scripture",
                "ScrBook", "StFootnote", "ScrSection", "StPara"
            });
            mockMDC.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMDC.AddClass(3, "StText", "CmObject", new List <string> {
                "StFootnote"
            });
            mockMDC.AddClass(4, "Scripture", "CmObject", new List <string>());
            mockMDC.AddClass(5, "ScrBook", "CmObject", new List <string>());
            mockMDC.AddClass(6, "StFootnote", "StText", new List <string> {
                "ScrFootnote"
            });
            mockMDC.AddClass(7, "ScrSection", "CmObject", new List <string>());
            mockMDC.AddClass(8, "StTxtPara", "StPara", new List <string> {
                "ScrTxtPara"
            });
            mockMDC.AddClass(9, "ScrFootnote", "StFootnote", new List <string>());
            mockMDC.AddClass(10, "ScrTxtPara", "StTxtPara", new List <string>());
            mockMDC.AddClass(11, "StPara", "CmObject", new List <string> {
                "StTxtPara"
            });
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000026, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000027, new DummyProgressDlg());
            Assert.AreEqual(7000027, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // Check that the ParaContainingOrc property in footnotes is set
            DomainObjectDTO footnoteDTO       = dtoRepos.GetDTO(footnoteGuids.textGuid.ToString());
            XElement        footnote          = XElement.Parse(footnoteDTO.Xml);
            XElement        paraContainingOrc = footnote.Element("ParaContainingOrc");

            Assert.IsNotNull(paraContainingOrc);
            XElement objRef = paraContainingOrc.Element("objsur");

            Assert.IsNotNull(objRef);
            Assert.AreEqual(contentsTextGuids.paraGuid.ToString(), objRef.Attribute("guid").Value);
            Assert.AreEqual("r", objRef.Attribute("t").Value);
        }
        public void DataMigration7000061Test()
        {
            var mockMdc = new MockMDCForDataMigration();

            mockMdc.AddClass(1, "CmObject", null, new List <string> {
                "LangProject", "StStyle", "CmResource", "LexEntry", "MoStemAllomorph", "MoStemName", "MoStemMsa", "CmIndirectAnnotation", "CmBaseAnnotation", "MoMorphAdhocProhib", "StText", "StTxtPara"
            });
            mockMdc.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMdc.AddClass(3, "StStyle", "CmObject", new List <string>());
            mockMdc.AddClass(4, "CmResource", "CmObject", new List <string>());
            mockMdc.AddClass(5, "LexEntry", "CmObject", new List <string>());
            mockMdc.AddClass(6, "MoStemAllomorph", "CmObject", new List <string>());
            mockMdc.AddClass(7, "MoStemName", "CmObject", new List <string>());
            mockMdc.AddClass(8, "MoStemMsa", "CmObject", new List <string>());
            mockMdc.AddClass(9, "CmIndirectAnnotation", "CmObject", new List <string>());
            mockMdc.AddClass(10, "CmBaseAnnotation", "CmObject", new List <string>());
            mockMdc.AddClass(11, "MoMorphAdhocProhib", "CmObject", new List <string>());
            mockMdc.AddClass(12, "StText", "CmObject", new List <string>());
            mockMdc.AddClass(13, "StTxtPara", "CmObject", new List <string>());

            mockMdc.AddField(1001, "Name", CellarPropertyType.Unicode, 0);
            mockMdc.AddField(5001, "LexemeForm", CellarPropertyType.OwningAtomic, 6);
            mockMdc.AddField(6001, "StemName", CellarPropertyType.ReferenceAtomic, 7);

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000061.xml");
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000060, dtos, mockMdc, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000061, new DummyProgressDlg());

            // Check Step 1.A.
            // <rt class="StStyle" guid ="bb68f6bc-f233-4cd4-8894-c33b4b4c43ba">
            DomainObjectDTO dto;

            dtoRepos.TryGetValue("bb68f6bc-f233-4cd4-8894-c33b4b4c43ba", out dto);
            Assert.IsNull(dto);
            // Step 1.A. Control
            // <rt class="StStyle" guid ="9d28219c-6185-416e-828b-b9e304de141c" ownerguid="88ddebd1-dfad-4033-8b1c-896081469f66">
            dtoRepos.TryGetValue("9d28219c-6185-416e-828b-b9e304de141c", out dto);
            Assert.IsNotNull(dto);

            // Check Step 1.B. (Real + control)
            foreach (var resourceDto in dtoRepos.AllInstancesSansSubclasses("CmResource"))
            {
                var resourceElement = XElement.Parse(resourceDto.Xml);
                var name            = resourceElement.Element("Name").Element("Uni").Value;
                var actualVersion   = resourceElement.Element("Version").Attribute("val").Value;
                var expectedVersion = "";
                switch (name)
                {
                case "TeStyles":
                    expectedVersion = "700176e1-4f42-4abd-8fb5-3c586670085d";
                    break;

                case "FlexStyles":
                    expectedVersion = "13c213b9-e409-41fc-8782-7ca0ee983b2c";
                    break;

                case "ControlResource":
                    expectedVersion = "c1ede2e2-e382-11de-8a39-0800200c9a66";
                    break;
                }
                Assert.AreEqual(expectedVersion, actualVersion);
            }

            // Step 2. (atomic owning and ref props with multiple elements)
            dto = dtoRepos.AllInstancesSansSubclasses("LexEntry").First();
            var element = XElement.Parse(dto.Xml);
            // Atomic owning prop
            var propertyElement = element.Element("LexemeForm");

            Assert.AreEqual(1, propertyElement.Elements().Count());
            Assert.AreEqual("c1ede2e7-e382-11de-8a39-0800200c9a66", propertyElement.Element("objsur").Attribute("guid").Value);
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("5aedaa5f-6f71-4859-953b-a9bb1b78a813"));
            // Atomic reference prop
            dto             = dtoRepos.GetDTO("c1ede2e7-e382-11de-8a39-0800200c9a66");
            element         = XElement.Parse(dto.Xml);
            propertyElement = element.Element("StemName");
            Assert.AreEqual(1, propertyElement.Elements().Count());
            Assert.AreEqual("c1ede2e4-e382-11de-8a39-0800200c9a66", propertyElement.Element("objsur").Attribute("guid").Value);

            // Step 3.
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("003018c0-eba6-43b7-b6e2-5a71ac049f6a"));
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("d06d329f-9dc5-4c1c-aecd-b447cd010bdb"));
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("968caa2b-fae0-479a-9f4a-45d2c6827aa5"));
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("7a62eb69-4738-4514-a94e-b29237d5c188"));

            // Step 4.
            dto             = dtoRepos.AllInstancesSansSubclasses("LexEntry").First();
            element         = XElement.Parse(dto.Xml);
            propertyElement = element.Element("MorphoSyntaxAnalyses");
            Assert.AreEqual(1, propertyElement.Elements().Count());
            Assert.AreEqual("c1ede2e5-e382-11de-8a39-0800200c9a66", propertyElement.Element("objsur").Attribute("guid").Value);
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("c1ede2e6-e382-11de-8a39-0800200c9a66"));
            Assert.Throws <ArgumentException>(() => dtoRepos.GetDTO("304b0aea-dccd-4865-9fad-923e89871b7e"));

            Assert.AreEqual(7000061, dtoRepos.CurrentModelVersion, "Wrong updated version.");
        }
        public void DataMigration7000011Test()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            var sb   = new StringBuilder();

            // 1. Add barebones Notebook.
            sb.Append("<rt class=\"RnResearchNbk\" guid=\"2E237D40-853C-49D5-AAC6-EFF01121AC25\">");
            sb.Append("<RnResearchNbk>");
            sb.Append("<RecTypes><objsur t=\"o\" guid=\"513B370D-8EFC-4C94-8192-7707677A6F98\" /></RecTypes>");
            sb.Append("<Records>");
            sb.Append("<objsur t=\"o\" guid=\"C84B721B-3617-43DE-A436-9E0538837A66\" />");
            sb.Append("</Records>");
            sb.Append("</RnResearchNbk>");
            sb.Append("</rt>");
            var nbkDto = new DomainObjectDTO("2E237D40-853C-49D5-AAC6-EFF01121AC25", "RnResearchNbk", sb.ToString());

            dtos.Add(nbkDto);

            sb = new StringBuilder();
            // 2. Add barebones RecTypes List
            sb.Append("<rt class=\"CmPossibilityList\" guid=\"513B370D-8EFC-4C94-8192-7707677A6F98\" ownerguid=\"2E237D40-853C-49D5-AAC6-EFF01121AC25\">");
            sb.Append("<CmPossibilityList>");
            sb.Append("<Possibilities>");
            sb.Append("<objsur t=\"o\" guid=\"27C32299-3B41-4FAD-A85C-F47657BCF95A\" />");
            sb.Append("<objsur t=\"o\" guid=\"5E3D9C56-404C-44C5-B3CB-99BF390E322E\" />");
            sb.Append("</Possibilities>");
            sb.Append("</CmPossibilityList>");
            sb.Append("</rt>");
            var recTypesDto = new DomainObjectDTO("513B370D-8EFC-4C94-8192-7707677A6F98", "CmPossibilityList", sb.ToString());

            dtos.Add(recTypesDto);

            sb = new StringBuilder();
            // 3. Add barebones Conversation
            sb.Append("<rt class=\"CmPossibility\" guid=\"27C32299-3B41-4FAD-A85C-F47657BCF95A\" ownerguid=\"513B370D-8EFC-4C94-8192-7707677A6F98\">");
            sb.Append("<CmPossibility>");
            sb.Append("<Abbreviation><AUni ws=\"en\">Con</AUni></Abbreviation>");
            sb.Append("</CmPossibility>");
            sb.Append("</rt>");
            var conDto = new DomainObjectDTO("27C32299-3B41-4FAD-A85C-F47657BCF95A", "CmPossibility", sb.ToString());

            dtos.Add(conDto);

            sb = new StringBuilder();
            // 4. Add barebones Observation
            sb.Append("<rt class=\"CmPossibility\" guid=\"5E3D9C56-404C-44C5-B3CB-99BF390E322E\" ownerguid=\"513B370D-8EFC-4C94-8192-7707677A6F98\">");
            sb.Append("<CmPossibility>");
            sb.Append("<Abbreviation><AUni ws=\"en\">Obs</AUni></Abbreviation>");
            sb.Append("<SubPossibilities>");
            sb.Append("<objsur t=\"o\" guid=\"9827CBE0-31F3-434E-80F7-5D5354C110B0\" />");
            sb.Append("</SubPossibilities>");
            sb.Append("</CmPossibility>");
            sb.Append("</rt>");
            var obsDto = new DomainObjectDTO("5E3D9C56-404C-44C5-B3CB-99BF390E322E", "CmPossibility", sb.ToString());

            dtos.Add(obsDto);

            sb = new StringBuilder();
            // 5. Add barebones Performance
            sb.Append("<rt class=\"CmPossibility\" guid=\"9827CBE0-31F3-434E-80F7-5D5354C110B0\" ownerguid=\"5E3D9C56-404C-44C5-B3CB-99BF390E322E\">");
            sb.Append("<CmPossibility>");
            sb.Append("<Abbreviation><AUni ws=\"en\">Per</AUni></Abbreviation>");
            sb.Append("</CmPossibility>");
            sb.Append("</rt>");
            var perDto = new DomainObjectDTO("9827CBE0-31F3-434E-80F7-5D5354C110B0", "CmPossibility", sb.ToString());

            dtos.Add(perDto);

            sb = new StringBuilder();
            // 6. Add barebones RnGenericRec
            sb.Append("<rt class=\"RnGenericRec\" guid=\"c84b721b-3617-43de-a436-9e0538837a66\" ownerguid=\"2E237D40-853C-49D5-AAC6-EFF01121AC25\">");
            sb.Append("<RnGenericRec>");
            sb.Append("<Type><objsur guid=\"27c32299-3b41-4fad-a85c-f47657bcf95a\" t=\"r\" /></Type>");
            sb.Append("</RnGenericRec>");
            sb.Append("</rt>");
            var recDto = new DomainObjectDTO("c84b721b-3617-43de-a436-9e0538837a66", "RnGenericRec", sb.ToString());

            dtos.Add(recDto);

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "RnResearchNbk", "CmPossibilityList", "CmPossibility", "RnGenericRec"
            });
            mockMDC.AddClass(2, "RnResearchNbk", "CmObject", new List <string>());
            mockMDC.AddClass(3, "CmPossibilityList", "CmObject", new List <string>());
            mockMDC.AddClass(4, "CmPossibility", "CmObject", new List <string>());
            mockMDC.AddClass(5, "RnGenericRec", "CmObject", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000010, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000011, new DummyProgressDlg());

            XElement nbkElem = XElement.Parse(nbkDto.Xml);

            Assert.AreEqual("D9D55B12-EA5E-11DE-95EF-0013722F8DEC",
                            (string)nbkElem.XPathSelectElement("RnResearchNbk/RecTypes/objsur").Attribute("guid"));

            DataMigrationTestServices.CheckDtoRemoved(dtoRepos, recTypesDto);
            recTypesDto = dtoRepos.GetDTO("D9D55B12-EA5E-11DE-95EF-0013722F8DEC");
            XElement        recTypesElem = XElement.Parse(recTypesDto.Xml);
            List <XElement> objSurElems  = recTypesElem.XPathSelectElements("CmPossibilityList/Possibilities/objsur").ToList();

            Assert.AreEqual(2, objSurElems.Count);
            Assert.AreEqual("B7B37B86-EA5E-11DE-80E9-0013722F8DEC", (string)objSurElems[0].Attribute("guid"));
            Assert.AreEqual("B7EA5156-EA5E-11DE-9F9C-0013722F8DEC", (string)objSurElems[1].Attribute("guid"));

            DataMigrationTestServices.CheckDtoRemoved(dtoRepos, conDto);
            conDto = dtoRepos.GetDTO("B7B37B86-EA5E-11DE-80E9-0013722F8DEC");
            XElement conElem = XElement.Parse(conDto.Xml);

            Assert.AreEqual("Con", (string)conElem.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']"));
            Assert.AreEqual("D9D55B12-EA5E-11DE-95EF-0013722F8DEC", (string)conElem.Attribute("ownerguid"));

            DataMigrationTestServices.CheckDtoRemoved(dtoRepos, obsDto);
            obsDto = dtoRepos.GetDTO("B7EA5156-EA5E-11DE-9F9C-0013722F8DEC");
            XElement obsElem = XElement.Parse(obsDto.Xml);

            Assert.AreEqual("Obs", (string)obsElem.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']"));
            Assert.AreEqual("B7F63D0E-EA5E-11DE-9F02-0013722F8DEC",
                            (string)obsElem.XPathSelectElement("CmPossibility/SubPossibilities/objsur").Attribute("guid"));
            Assert.AreEqual("D9D55B12-EA5E-11DE-95EF-0013722F8DEC", (string)obsElem.Attribute("ownerguid"));

            DataMigrationTestServices.CheckDtoRemoved(dtoRepos, perDto);
            perDto = dtoRepos.GetDTO("B7F63D0E-EA5E-11DE-9F02-0013722F8DEC");
            XElement perElem = XElement.Parse(perDto.Xml);

            Assert.AreEqual("Per", (string)perElem.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']"));
            Assert.AreEqual("B7EA5156-EA5E-11DE-9F9C-0013722F8DEC", (string)perElem.Attribute("ownerguid"));

            XElement recElem = XElement.Parse(recDto.Xml);

            Assert.AreEqual("B7B37B86-EA5E-11DE-80E9-0013722F8DEC", (string)recElem.XPathSelectElement("RnGenericRec/Type/objsur").Attribute("guid"));
        }
        public void DataMigration7000044Test()
        {
            var projectFolder = Path.GetTempPath();
            var storePath     = Path.Combine(projectFolder, LcmFileHelper.ksWritingSystemsDir);

            PrepareStore(storePath);
            var testEnglishPath = Path.Combine(storePath, "en.ldml");

            File.Copy(Path.Combine(TestDirectoryFinder.TestDataDirectory, "en_7000043.ldml"), testEnglishPath);
            File.SetAttributes(testEnglishPath, FileAttributes.Normal);             // don't want to copy readonly property.
            var xkalPath = Path.Combine(storePath, "x-kal.ldml");

            File.Copy(Path.Combine(TestDirectoryFinder.TestDataDirectory, "x-kal_7000043.ldml"), xkalPath);
            File.SetAttributes(xkalPath, FileAttributes.Normal);             // don't want to copy readonly property.
            var xkalFonipaPath = Path.Combine(storePath, "x-kal-fonipa.ldml");

            File.Copy(Path.Combine(TestDirectoryFinder.TestDataDirectory, "x-kal-fonipa_7000043.ldml"), xkalFonipaPath);
            File.SetAttributes(xkalFonipaPath, FileAttributes.Normal);             // don't want to copy readonly property.

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000044.xml");
            // Create all the Mock classes for the classes in my test data.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "LexEntry", "LangProject", "LexSense", "LexDb",
                "ReversalEntry", "StStyle", "CmPossibilityList", "CmBaseAnnotation"
            });
            mockMDC.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMDC.AddClass(3, "LexEntry", "CmObject", new List <string>());
            mockMDC.AddClass(4, "LexSense", "CmObject", new List <string>());
            mockMDC.AddClass(5, "LexDb", "CmObject", new List <string>());
            mockMDC.AddClass(6, "ReversalEntry", "CmObject", new List <string>());
            mockMDC.AddClass(7, "StStyle", "CmObject", new List <string>());
            mockMDC.AddClass(8, "CmPossibilityList", "CmObject", new List <string>());
            mockMDC.AddClass(9, "CmBaseAnnotation", "CmObject", new List <string>());

            var settingsFolder = Path.Combine(projectFolder, LcmFileHelper.ksConfigurationSettingsDir);

            Directory.CreateDirectory(settingsFolder);
            var sampleLayout = Path.Combine(settingsFolder, "Test_Layouts.xml");

            File.WriteAllText(sampleLayout, sampleLayoutData, Encoding.UTF8);
            var sampleSettings = Path.Combine(settingsFolder, "db$local$Settings.xml");

            File.WriteAllText(sampleSettings, sampleLocalSettingsData, Encoding.UTF8);

            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000043, dtos, mockMDC, projectFolder,
                                                                                TestDirectoryFinder.LcmDirectories);

            // Do the migration.
            m_dataMigrationManager.PerformMigration(dtoRepos, 7000044, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000044, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // Todo:
            // Verify that en.ldml is unchanged.
            Assert.That(File.Exists(testEnglishPath));
            // Verify that x-kal.ldml is renamed to qaa-x-kal and content changed
            Assert.That(File.Exists(Path.Combine(storePath, "qaa-x-kal.ldml")));
            // Verify that x-kal-fonipa.ldml is renamed to qaa-fonipa-x-kal and content changed
            Assert.That(File.Exists(Path.Combine(storePath, "qaa-x-kal-fonipa.ldml")));
            // Verify that AUni data in LexEntry" guid="7ecbb299-bf35-4795-a5cc-8d38ce8b891c tag is changed to qaa-x-kal
            var entry = XElement.Parse(dtoRepos.GetDTO("7ecbb299-bf35-4795-a5cc-8d38ce8b891c").Xml);

            Assert.That(entry.Element("CitationForm").Element("AUni").Attribute("ws").Value, Is.EqualTo("qaa-x-kal"));
            // Verify that AStr data in LexSense" guid="e3c2d179-3ccd-431e-ac2e-100bdb883680" tag is changed to qaa-x-kal
            var sense = XElement.Parse(dtoRepos.GetDTO("e3c2d179-3ccd-431e-ac2e-100bdb883680").Xml);

            Assert.That(sense.Element("Definition").Elements("AStr").Skip(1).First().Attribute("ws").Value, Is.EqualTo("qaa-x-kal"));
            Assert.That(sense.Element("Definition").Elements("AStr").Count(), Is.EqualTo(2), "french should be deleted because empty");
            // Verify that the empty alternatives get removed.
            Assert.That(sense.Element("Bibliography").Elements("AUni").First().Attribute("ws").Value, Is.EqualTo("en"));
            Assert.That(sense.Element("Bibliography").Elements("AUni").Count(), Is.EqualTo(1));
            // Verify that Run data in LexSense" guid="e3c2d179-3ccd-431e-ac2e-100bdb883680" tag is changed to qaa-x-kal
            Assert.That(sense.Element("Definition").Element("AStr").Elements("Run").Skip(1).First().Attribute("ws").Value, Is.EqualTo("qaa-x-kal"));
            // Check LiftResidue lang attributes are fixed; note that a result containing lang=&quot;qaa-x-kal&quot
            // would also be acceptable, perhaps even more to be expected, but converting the &quot; s here to " is acceptable.
            Assert.That(sense.Element("LiftResidue").Element("Uni").Value.Contains("lang=\"qaa-x-kal\""));
            // Verify that WsProp data in StStyle guid="4d312f11-439e-11d4-b5e7-00400543a266" is changed to qaa-x-kal
            var style = XElement.Parse(dtoRepos.GetDTO("4d312f11-439e-11d4-b5e7-00400543a266").Xml);

            Assert.That(style.Element("Rules").Element("Prop").Element("WsStyles9999").Elements("WsProp").Skip(1).First().Attribute("ws").Value, Is.EqualTo("qaa-x-kal"));
            // Verify that x-kal is changed to qaa-x-kal in xWss properties of LangProject b8bdad3d-9006-46f0-83e8-ae1d1726f2ad.
            var langProj = XElement.Parse(dtoRepos.GetDTO("b8bdad3d-9006-46f0-83e8-ae1d1726f2ad").Xml);

            Assert.That(langProj.Element("AnalysisWss").Element("Uni").Value, Is.EqualTo("en qaa-x-kal"));
            Assert.That(langProj.Element("CurVernWss").Element("Uni").Value, Is.EqualTo("seh qaa-x-kal fr"));
            Assert.That(langProj.Element("CurAnalysisWss").Element("Uni").Value, Is.EqualTo("en qaa-x-kal"));
            Assert.That(langProj.Element("CurPronunWss").Element("Uni").Value, Is.EqualTo("qaa-x-kal"));
            Assert.That(langProj.Element("VernWss").Element("Uni").Value, Is.EqualTo("qaa-x-kal"));
            // Verify that WritingSystem/Uni is changed to qaa-x-kal in ReversalIndex" guid="62105696-da6c-405e-b87f-a2a0294bb179
            var ri = XElement.Parse(dtoRepos.GetDTO("62105696-da6c-405e-b87f-a2a0294bb179").Xml);

            Assert.That(ri.Element("WritingSystem").Element("Uni").Value, Is.EqualTo("qaa-x-kal"));
            //	and CmPossibilityList" guid="b30aa28d-7510-49e6-b9ac-bc1902398ce6"
            var pl = XElement.Parse(dtoRepos.GetDTO("b30aa28d-7510-49e6-b9ac-bc1902398ce6").Xml);

            Assert.That(pl.Element("WritingSystem").Element("Uni").Value, Is.EqualTo("qaa-x-kal"));
            //  and CmBaseAnnotation" guid="dc747a85-ceb6-491e-8b54-7fc37d7b2f80"
            var cba = XElement.Parse(dtoRepos.GetDTO("dc747a85-ceb6-491e-8b54-7fc37d7b2f80").Xml);

            Assert.That(cba.Element("WritingSystem").Element("Uni").Value, Is.EqualTo("qaa-x-kal"));
            // Several other classes have WritingSystem, but we're checking ALL objects, so I think three test cases is plenty.

            // Check the layout
            var layoutElt = XElement.Parse(File.ReadAllText(sampleLayout, Encoding.UTF8));

            Assert.That(layoutElt.Element("layout").Element("part").Attribute("ws").Value, Is.EqualTo("qaa-x-kal"));
            Assert.That(layoutElt.Element("layout").Elements("part").Skip(1).First().Attribute("ws").Value, Is.EqualTo("vernacular"));
            Assert.That(layoutElt.Element("layout").Elements("part").Skip(2).First().Attribute("ws").Value, Is.EqualTo("$ws=all analysis"));
            Assert.That(layoutElt.Element("layout").Elements("part").Skip(3).First().Attribute("ws").Value, Is.EqualTo("$ws=qaa-x-kal"));
            Assert.That(layoutElt.Element("layout").Elements("part").Skip(4).First().Attribute("ws").Value, Is.EqualTo("qaa-x-kal-fonipa,qaa-x-kal"));
            Assert.That(layoutElt.Element("layout").Elements("part").Skip(4).First().Attribute("visibleWritingSystems").Value, Is.EqualTo("qaa-x-kal-fonipa,qaa-x-kal"));

            // Check the local settings.
            var propTable = XElement.Parse(File.ReadAllText(sampleSettings, Encoding.UTF8));

            Assert.That(propTable.Element("Property").Element("value").Value.Contains("5062001%qaa-x-kal"));
            Assert.That(propTable.Element("Property").Element("value").Value.Contains("5112002%qaa-x-kal"));
            Assert.That(propTable.Element("Property").Element("value").Value.Contains("103%qaa-x-kal"));
            Assert.That(propTable.Elements("Property").Skip(1).First().Element("value").Value.Contains("ws=\"qaa-x-kal\""));
            Assert.That(propTable.Elements("Property").Skip(2).First().Element("value").Value.Contains("ws=\"$ws=qaa-x-kal\""));
            Assert.That(propTable.Elements("Property").Skip(3).First().Element("value").Value.Contains("ws=\"$wsName\""));
            Assert.That(propTable.Elements("Property").Skip(4).First().Element("value").Value.Contains("ws=\"$ws=reversal\""));
            Assert.That(propTable.Elements("Property").Skip(5).First().Element("value").Value, Is.EqualTo("qaa-x-kal"));
            Assert.That(propTable.Elements("Property").Skip(6).First().Element("value").Value.Contains("ws=\"qaa-x-kal\""));
            Assert.That(propTable.Elements("Property").Skip(7).First().Element("value").Value.Contains("ws=\"$ws=qaa-x-kal\""));
        }
        public void DataMigration7000024Test1()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000024Tests1.xml");

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string>
            {
                "CmProject",
                "CmMajorObject",
                "RnGenericRec"
            });

            mockMDC.AddClass(2, "CmProject", "CmObject", new List <string> {
                "LangProject"
            });
            mockMDC.AddClass(3, "LangProject", "CmProject", new List <string>());
            mockMDC.AddClass(4, "CmMajorObject", "CmObject", new List <string> {
                "RnResearchNbk"
            });
            mockMDC.AddClass(5, "RnResearchNbk", "CmMajorObject", new List <string>());
            mockMDC.AddClass(6, "RnGenericRec", "CmObject", new List <string>());

            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000023, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000024, new DummyProgressDlg());

            //This object should contain a 'Status' property
            var langProjDto     = dtoRepos.AllInstancesSansSubclasses("LangProject").First();
            var langProjElement = XElement.Parse(langProjDto.Xml);
            var langProjStatus  = langProjElement.XPathSelectElement("Status/objsur");

            Assert.That(langProjStatus, Is.Not.Null, "We should now have a 'Status' element on LangProj");

            //This object should not contain an 'AnalysysStatus' property
            var langProjAnalysisStatus = langProjElement.XPathSelectElement("AnalysisStatus");

            Assert.That(langProjAnalysisStatus, Is.Null, "LangProject AnalysisStatus Property should not exist any more");

            var langPossListGuid    = langProjStatus.Attribute("guid").Value;
            var langPossListDto     = dtoRepos.GetDTO(langPossListGuid);
            var langPossListElement = XElement.Parse(langPossListDto.Xml);

            Assert.That(langPossListElement.Attribute("ownerguid").Value.ToLowerInvariant(),
                        Is.EqualTo("b5a90c21-d8b2-4d4a-94f6-1b1fbeac3388"),
                        "Status element should be owned by LangProject");

            //There should be 1 possibility in the status list; 'Confirmed'.
            var possibilities    = langPossListElement.XPathSelectElement("Possibilities");
            var possibilitiesDto = possibilities.Descendants();

            Assert.That(possibilitiesDto.Count(), Is.EqualTo(1), "We should have exactly one status item in the PL");

            // Verify that the RnGenericRec Entries are copied over (they won't have statuses).
            var rnGenericRecDto = dtoRepos.GetDirectlyOwnedDTOs("4e3802af-98cd-48c4-b6ff-3cb0a5fd1310");

            Assert.That(rnGenericRecDto.Count(), Is.EqualTo(7), "There should be exactly seven RnGeneric records");
            foreach (var rnRec in rnGenericRecDto)
            {
                var rnGenericRecElement = XElement.Parse(rnRec.Xml);
                var rnStatusElem        = rnGenericRecElement.XPathSelectElement("Status/objsur");
                Assert.That(rnStatusElem, Is.Null, "None of the RnGeneric records should have statuses");
            }
            Assert.AreEqual(7000024, dtoRepos.CurrentModelVersion, "Wrong updated version.");
        }
        public void DataMigration7000024Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000024Tests.xml");

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string>
            {
                "CmProject",
                "CmMajorObject",
                "RnGenericRec",
                "LexEntry",
                "LexSense",
                "CmPossibility"
            });
            mockMDC.AddClass(2, "CmProject", "CmObject", new List <string> {
                "LangProject"
            });
            mockMDC.AddClass(3, "LangProject", "CmProject", new List <string>());
            mockMDC.AddClass(4, "CmMajorObject", "CmObject", new List <string> {
                "RnResearchNbk", "CmPossibilityList", "LexDb"
            });
            mockMDC.AddClass(5, "RnResearchNbk", "CmMajorObject", new List <string>());
            mockMDC.AddClass(6, "RnGenericRec", "CmObject", new List <string>());
            mockMDC.AddClass(7, "CmPossibilityList", "CmMajorObject", new List <string>());
            mockMDC.AddClass(8, "LexDb", "CmMajorObject", new List <string> {
            });
            mockMDC.AddClass(9, "LexEntry", "CmObject", new List <string>());
            mockMDC.AddClass(10, "LexSense", "CmObject", new List <string>());
            mockMDC.AddClass(11, "CmPossibility", "CmObject", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000023, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000024, new DummyProgressDlg());

            //This object should contain a 'Status' property
            var langProjDto     = dtoRepos.AllInstancesSansSubclasses("LangProject").First();
            var langProjElement = XElement.Parse(langProjDto.Xml);
            var langProjStatus  = langProjElement.XPathSelectElement("Status/objsur");

            Assert.That(langProjStatus, Is.Not.Null, "We should now have a 'Status' element on LangProj");
            //This object should not contain an 'AnalysysStatus' property
            var langProjAnalysisStatus = langProjElement.XPathSelectElement("AnalysisStatus");

            Assert.That(langProjAnalysisStatus, Is.Null, "LangProject AnalysisStatus Property should not exist any more");

            Assert.That(langProjStatus.Attribute("guid").Value.ToLowerInvariant(),
                        Is.EqualTo("0084b4d9-6c1e-4d63-9c66-ff22764ef171"),
                        "Status element should preserve objsur guid of old Analysis Status");
            //This LexDb element should not contain a 'Status' property
            var lexDbDto     = dtoRepos.AllInstancesSansSubclasses("LexDb").First();
            var lexDbElement = XElement.Parse(lexDbDto.Xml);
            var lexDbStatus  = lexDbElement.XPathSelectElement("Status");

            Assert.That(lexDbStatus, Is.Null, "LexDb Status Property exists but should have been deleted");

            //The 5 resulting possibilities should be 'Confirmed', 'Disproved', 'Pending', ''Tentative', and 'Ann'.
            var possListDto = dtoRepos.GetDirectlyOwnedDTOs("0084B4D9-6C1E-4D63-9C66-FF22764EF171");

            Assert.That(possListDto.Count(), Is.EqualTo(6), "We should have exactly six status items in the PL");
            var names = new HashSet <string>();

            foreach (var possibility in possListDto)
            {
                var possElement = XElement.Parse(possibility.Xml);
                var nameElt     = possElement.XPathSelectElement("Name/AUni[@ws='en']");
                if (nameElt == null)
                {
                    nameElt = possElement.XPathSelectElement("Name/AUni[@ws='id']");
                }
                var ttype = nameElt.Value;
                names.Add(ttype);
                switch (ttype)
                {
                case "Confirmed":
                case "Tentative":
                case "Disproved":
                case "Pending":
                case "Ann":
                case "Foreign":
                    break;

                default:
                    Assert.Fail(ttype + " is in the CmPossibility List");
                    break;
                }
            }
            Assert.That(names, Has.Count.EqualTo(6), "One of the expected possibilities is missing!");

            // Verify that the LexSense Entries point to the new status entries.
            var lexSenseDto = dtoRepos.GetDirectlyOwnedDTOs("fd6bb890-bb84-4920-954d-40d1e987b683");

            Assert.That(lexSenseDto.Count(), Is.EqualTo(5), "There should be exactly five senses");
            foreach (var lexSense in lexSenseDto)
            {
                var lexSenseElement = XElement.Parse(lexSense.Xml);
                var ttype           = lexSenseElement.XPathSelectElement("Gloss/AUni[@ws='en']").Value;
                switch (ttype)
                {
                case "Aardvark":
                    //Make sure the Status's Guid this LexSense status is the one owned by LangProject.
                    Assert.That(lexSenseElement.XPathSelectElement("Status/objsur").Attribute("guid").Value,
                                Is.EqualTo("8D87FC8A-593E-4C84-A9ED-193879D08585"),
                                ttype + " doesn''t point to the correct possibility.");
                    break;

                case "Aardvark2":
                    //Make sure the ownerguid of the Possibility for this LexSense status is the cmPossibilityList owned by langProject
                    var aardDto           = dtoRepos.GetDTO(lexSenseElement.XPathSelectElement("Status/objsur").Attribute("guid").Value);
                    var aardStatusElement = XElement.Parse(aardDto.Xml);
                    Assert.That(aardStatusElement.Attribute("ownerguid").Value.ToUpperInvariant(),
                                Is.EqualTo("0084B4D9-6C1E-4D63-9C66-FF22764EF171"),
                                ttype + " ownerguid isn't correct.");
                    Assert.AreEqual(aardStatusElement.XPathSelectElement("Name/AUni[@ws='en']").Value,
                                    "Ann",
                                    ttype + " Possibility pointed to has the wrong name.");
                    break;

                case "Aardvark3":
                    //Make sure the Status's Guid this LexSense status is the one owned by LangProject.
                    Assert.That(lexSenseElement.XPathSelectElement("Status/objsur").Attribute("guid").Value.ToUpperInvariant,
                                Is.EqualTo("8D87FC8A-593E-4C84-A9ED-193879D08585"),
                                ttype + " doesn''t point to the correct possibility.");
                    break;

                case "Aardvark4":
                    //Make sure the Status's Guid this LexSense status is the one owned by LangProject.
                    Assert.That(lexSenseElement.XPathSelectElement("Status"), Is.Null,
                                ttype + " does have a status.");
                    break;

                default:
                    Assert.Pass(ttype + " is in the LexSense List");
                    break;
                }
            }
            // Verify that the RnGenericRec Entries point to the new status entries.
            var rnGenericRecDto = dtoRepos.GetDirectlyOwnedDTOs("4e3802af-98cd-48c4-b6ff-3cb0a5fd1310");

            Assert.That(rnGenericRecDto.Count(), Is.EqualTo(7), "There should be exactly seven RnGeneric records");
            foreach (var rnRec in rnGenericRecDto)
            {
                var rnGenericRecElement = XElement.Parse(rnRec.Xml);
                var rnStatusElem        = rnGenericRecElement.XPathSelectElement("Status/objsur");
                if (rnStatusElem == null)
                {
                    continue;
                }
                var rnStatusGuid = rnStatusElem.Attribute("guid").Value;

                var rnPossibilityDto       = dtoRepos.GetDTO(rnStatusGuid);
                var rnPossibilityElement   = XElement.Parse(rnPossibilityDto.Xml);
                var rnNameElem             = rnPossibilityElement.XPathSelectElement("Name/AUni[@ws='en']").Value;
                var rnPossibilityOwnerGuid = rnPossibilityElement.Attribute("ownerguid").Value;

                switch (rnGenericRecElement.Attribute("guid").Value.ToLowerInvariant())
                {
                case "611739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 1 status record isn't owned by LangProj.",
                                             rnNameElem, "Pending", "RnGenericRec record 1 doesn''t point to a status of ''Pending''.");
                    break;

                case "612739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 2 status record isn't owned by LangProj.",
                                             rnNameElem, "Confirmed",
                                             "RnGenericRec record 2 doesn''t point to a status of ''Confirmed''.");
                    break;

                case "613739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 3 status record isn't owned by LangProj.",
                                             rnNameElem, "Tentative",
                                             "RnGenericRec record 3 doesn''t point to a status of ''Tentative''.");
                    break;

                case "614739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 4 status record isn't owned by LangProj.",
                                             rnNameElem, "Confirmed",
                                             "RnGenericRec record 4 doesn''t point to a status of ''Approved''.");
                    break;

                case "615739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 5 status record isn't owned by LangProj.",
                                             rnNameElem, "Disproved",
                                             "RnGenericRec record 5 doesn''t point to a status of ''Disproved''.");
                    break;

                case "616739fe-8fe2-4d16-8570-b9d46c339e6e":
                    VerifyOwnerguidAndStatus(rnPossibilityOwnerGuid, "RnGenericRec record 6 status record isn't owned by LangProj.",
                                             rnNameElem, "Disproved", "RnGenericRec record 6 doesn''t point to a status of ''Ann''.");
                    break;

                default:
                    Assert.Fail("There is no RnGenericRec with a guid of: " +
                                rnGenericRecElement.Attribute("guid").Value.ToLowerInvariant());
                    break;
                }
            }
            Assert.AreEqual(7000024, dtoRepos.CurrentModelVersion, "Wrong updated version.");
        }
        public void DataMigration7000023Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000023.xml");

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "LangProject", "DsDiscourseData", "LexDb", "RnResearchNbk",
                "CmPossibilityList", "CmFilter", "UserView", "UserAppFeatAct", "CmResource", "ScrCheckRun"
            });
            mockMDC.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMDC.AddClass(3, "DsDiscourseData", "CmObject", new List <string>());
            mockMDC.AddClass(4, "LexDb", "CmObject", new List <string>());
            mockMDC.AddClass(5, "CmPossibilityList", "CmObject", new List <string>());
            mockMDC.AddClass(6, "CmFilter", "CmObject", new List <string>());
            mockMDC.AddClass(7, "UserView", "CmObject", new List <string>());
            mockMDC.AddClass(8, "UserAppFeatAct", "CmObject", new List <string>());
            mockMDC.AddClass(9, "CmResource", "CmObject", new List <string>());
            mockMDC.AddClass(10, "ScrCheckRun", "CmObject", new List <string>());
            mockMDC.AddClass(11, "RnResearchNbk", "CmObject", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000022, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            //SUT
            m_dataMigrationManager.PerformMigration(dtoRepos, 7000023, new DummyProgressDlg());

            // Verification section
            var dto       = dtoRepos.GetDTO("c1ecaa73-e382-11de-8a39-0800200c9a66");
            var rtElement = XElement.Parse(dto.Xml);

            CheckGuid(rtElement.Element("LexDb").Element("objsur").Attribute("guid").Value);
            dto       = dtoRepos.GetDTO("c1ec5c4c-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Attribute("ownerguid").Value);
            dto       = dtoRepos.GetDTO("c1Ecaa74-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Attribute("guid").Value);
            dto       = dtoRepos.GetDTO("AF26D792-EA5E-11DE-8F7E-0013722F8DEC");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Attribute("guid").Value);
            dto       = dtoRepos.GetDTO("1FBDC211-32E4-4203-9B7F-9CAACBF31DBD");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Attribute("guid").Value);
            CheckGuid(rtElement.Element("ListVersion").Attribute("val").Value);
            dto       = dtoRepos.GetDTO("c1ecaa77-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Element("App").Attribute("val").Value);
            dto       = dtoRepos.GetDTO("c1ecaa78-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Element("App").Attribute("val").Value);
            dto       = dtoRepos.GetDTO("c1ecaa79-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Element("ApplicationId").Attribute("val").Value);
            dto       = dtoRepos.GetDTO("c1ecaa7a-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Element("Version").Attribute("val").Value);
            dto       = dtoRepos.GetDTO("c1ecd170-e382-11de-8a39-0800200c9a66");
            rtElement = XElement.Parse(dto.Xml);
            CheckGuid(rtElement.Element("CheckId").Attribute("val").Value);

            Assert.AreEqual(7000023, dtoRepos.CurrentModelVersion, "Wrong updated version.");
        }
        public void DataMigration7000034Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000034.xml");

            //Now create all the Mock classes for the classes in my test data.
            //eg LangProject base class is CmProject which has a base class of CmObject
            //eg LexEntry base class is CmObject
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string>
            {
                "CmProject",
                "CmPicture",
                "CmFolder",
                "CmFile",
            });
            mockMDC.AddClass(2, "CmProject", "CmObject", new List <string> {
                "LangProject"
            });
            mockMDC.AddClass(3, "LangProject", "CmProject", new List <string>());

            //In the List, put each class in this test which derives from this class.
            mockMDC.AddClass(8, "CmPicture", "CmObject", new List <string>());
            mockMDC.AddClass(9, "CmFolder", "CmObject", new List <string>());
            mockMDC.AddClass(10, "CmFile", "CmObject", new List <string>());
            IDomainObjectDTORepository repoDto = new DomainObjectDtoRepository(7000033, dtos, mockMDC,
                                                                               Path.GetTempPath(), TestDirectoryFinder.LcmDirectories);

            // Do the migration.
            m_dataMigrationManager.PerformMigration(repoDto, 7000034, new DummyProgressDlg());

            Assert.AreEqual(7000034, repoDto.CurrentModelVersion, "Wrong updated version.");

            var langProj        = repoDto.AllInstancesSansSubclasses("LangProject").First();
            var langProjElement = XElement.Parse(langProj.Xml);

            // Not directly related to this migration, but fixed problem with DataMigrationServices.RemoveIncludingOwnedObjects
            // and couldn't find a better place to put the test. Need to make sure only empty properties on LangProject
            // get deleted.
            Assert.AreEqual("en", langProjElement.Element("AnalysisWss").Element("Uni").Value,
                            "Analysis Writing systems should be preserved.");
            Assert.IsNull(langProjElement.Element("Styles"));              // empty styles in test data should have been removed.

            // Verify migration worked
            var pictures = langProjElement.Element("Pictures");

            Assert.AreEqual(1, pictures.Elements().Count(), "Should only be one folder in Pictures");
            var folder        = repoDto.GetDTO(pictures.Elements().First().Attribute("guid").Value);
            var folderElement = XElement.Parse(folder.Xml);
            var files         = folderElement.Element("Files");

            Assert.AreEqual(4, files.Elements().Count(), "Should be four files");
            Assert.AreEqual(4, repoDto.AllInstancesSansSubclasses("CmFile").Count(),
                            "Should still be four files");
            // Verify ownership is correct
            foreach (var fileRef in files.Elements())
            {
                var file        = repoDto.GetDTO(fileRef.Attribute("guid").Value);
                var fileElement = XElement.Parse(file.Xml);
                Assert.AreEqual(folder.Guid, fileElement.Attribute("ownerguid").Value, "All files should be owned by folder");
            }

            // the first CmFile is used in all except CmPictures in the test data
            var fileGuid = files.Elements().First().Attribute("guid").Value;

            Assert.AreEqual(4, repoDto.AllInstancesSansSubclasses("CmPicture").Count(),
                            "Should still be four pictures");
            int matchCount = 0;

            foreach (var picture in repoDto.AllInstancesSansSubclasses("CmPicture"))
            {
                var pictureElement = XElement.Parse(picture.Xml);
                if (fileGuid ==
                    pictureElement.Element("PictureFile").Element("objsur").Attribute("guid").Value)
                {
                    matchCount++;
                }
            }
            Assert.AreEqual(3, matchCount, "Should be 3 pictures using first CmFile");
        }