Exemplo n.º 1
0
        public void BadListDisplayOptionAndChoiceOptionAreFixed()
        {
            var mockMdc = new MockMDCForDataMigration();

            mockMdc.AddClass(1, "CmObject", null, new List <string> {
                "CmPossibilityList", "LanguageProject", "CmCustomItem", "LexDb", "LexEntryRef"
            });
            mockMdc.AddClass(2, "CmPossibilityList", "CmObject", new List <string>());
            mockMdc.AddClass(3, "CmCustomItem", "CmObject", new List <string>());
            mockMdc.AddClass(4, "LanguageProject", "CmObject", new List <string>());
            mockMdc.AddClass(5, "LexDb", "CmObject", new List <string>());
            mockMdc.AddClass(6, "LexEntryRef", "CmObject", new List <string>());

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000070_DoubledList.xml");
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000069, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            const string badEnumValue = "-1073741824";

            Assert.True(dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").Any(dto => dto.Xml.Contains("PreventChoiceAboveLevel val=\"" + badEnumValue + "\"")),
                        "The CmPossibilityList test data has changed");
            Assert.True(dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").Any(dto => dto.Xml.Contains("DisplayOption val=\"" + badEnumValue + "\"")),
                        "The CmPossibilityList test data has changed");

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

            var resultingLists = dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").ToList();

            Assert.False(dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").Any(dto => dto.Xml.Contains(badEnumValue)), "Bad list data was not removed.");
            Assert.AreEqual(2, resultingLists.Count(dto => dto.Xml.Contains("PreventChoiceAboveLevel val=\"0\"")), "PreventChoiceAbove should have changed to 0");
            Assert.AreEqual(2, resultingLists.Count(dto => dto.Xml.Contains("DisplayOption val=\"0\"")), "DisplayOption should have changed to 0");
        }
Exemplo n.º 2
0
        public void DeleteWeatherListAndField()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000017.xml");

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository repoDTO = new DomainObjectDtoRepository(7000016, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(repoDTO, 7000017, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000017, repoDTO.CurrentModelVersion, "Wrong updated version.");

            DomainObjectDTO dtoLP = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("LangProject"))
            {
                Assert.IsNull(dtoLP, "Only one LangProject object should exist");
                dtoLP = dto;
            }
            Assert.NotNull(dtoLP, "The LangProject object should exist");
            string sXml = dtoLP.Xml;

            Assert.IsFalse(sXml.Contains("<WeatherConditions>"), "The <WeatherConditions> element should have disappeared");
            string sLpOwnerGuid = GetGuidAsOwnerGuid(sXml);

            DomainObjectDTO dtoNbk = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("RnResearchNbk"))
            {
                Assert.IsNull(dtoNbk, "Only one RnResearchNbk should exist");
                Assert.IsTrue(dto.Xml.Contains(sLpOwnerGuid), "The RnResearchNbk should be owned by the LangProject");
                dtoNbk = dto;
            }
            Assert.NotNull(dtoNbk, "The RnResearchNbk should exist");
            string sNbkOwnerGuid = GetGuidAsOwnerGuid(dtoNbk.Xml);
            int    cList         = 0;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("CmPossibilityList"))
            {
                sXml = dto.Xml;
                Assert.IsTrue(sXml.Contains(sNbkOwnerGuid), "Possibility List must be owned by Data Notebook");
                ++cList;
            }
            Assert.AreEqual(1, cList, "Only one CmPossibilityList should exist");

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesWithSubclasses("RnGenericRec"))
            {
                Assert.IsFalse(dto.Xml.Contains("<Weather"), "Any <Weather> element should have disappeared");
                Assert.IsFalse(dto.Xml.Contains("<Custom name="), "No <Custom> element should have been created");
            }

            // This test file has three overlays; the first refers to a weather item and the weather possibility list,
            // and should be delted. The second refers to a non-weather possibility, and the third to a non-weather
            // possibility list; they should survive.
            Assert.That(repoDTO.AllInstancesSansSubclasses("CmOverlay"), Has.Count.EqualTo(2));
        }
Exemplo n.º 3
0
        public void DuplicatedListsAreMarkedAsCustom()
        {
            var mockMdc = new MockMDCForDataMigration();

            mockMdc.AddClass(1, "CmObject", null, new List <string> {
                "CmPossibilityList", "LanguageProject", "CmCustomItem", "LexDb", "LexEntryRef"
            });
            mockMdc.AddClass(2, "CmPossibilityList", "CmObject", new List <string>());
            mockMdc.AddClass(3, "CmCustomItem", "CmObject", new List <string>());
            mockMdc.AddClass(4, "LanguageProject", "CmObject", new List <string>());
            mockMdc.AddClass(5, "LexDb", "CmObject", new List <string>());
            mockMdc.AddClass(6, "LexEntryRef", "CmObject", new List <string>());

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000070_DoubledList.xml");
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000069, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            Assert.AreEqual(3, dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").Count(), "The CmPossibilityList test data has changed");

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

            var resultingLists = dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").ToList();

            Assert.AreEqual(3, resultingLists.Count, "The Custom list and new replacement should be all there is");
            // Make sure that the custom list got a custom name and the 'real' owned list kept the original name
            var custLanguages = XElement.Parse(resultingLists[0].Xml);
            var origLanguages = XElement.Parse(resultingLists[1].Xml);
            var notLanguages  = XElement.Parse(resultingLists[2].Xml);

            Assert.IsTrue(origLanguages.Attribute("ownerguid") != null, "Test data order has changed");
            var firstName = origLanguages.Element("Name").Elements("AUni").First().Value;

            Assert.That(firstName, Is.StringMatching("Languages"), "Built in list should not have changed the name");
            firstName = custLanguages.Element("Name").Elements("AUni").First().Value;
            Assert.That(firstName, Is.StringMatching("Languages-Custom"), "The custom Languages list did not have its name changed");
            firstName = notLanguages.Element("Name").Elements("AUni").First().Value;
            Assert.That(firstName, Is.StringMatching("Not Languages"), "The unrelated list should not have had its name changed");
        }
Exemplo n.º 4
0
        public void DtosByClassWithSubclassesTest()
        {
            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, FwDirectoryFinder.FdoDirectories);
            var result = new List <DomainObjectDTO>(dtoRepos.AllInstancesWithSubclasses("CmObject"));

            Assert.AreEqual(2, result.Count, "Wrong number of DTOs (expected 2).");
        }
Exemplo n.º 5
0
        public void DataMigration7000019Test()
        {
            string storePath = Path.Combine(Path.GetTempPath(), FdoFileHelper.ksWritingSystemsDir);

            PrepareStore(storePath);
            string globalStorePath = DirectoryFinder.GlobalWritingSystemStoreDirectory;

            PrepareStore(globalStorePath);

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000019Tests.xml");

            IFwMetaDataCacheManaged mockMdc = SetupMdc();

            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000018, dtos, mockMdc, Path.GetTempPath(), FwDirectoryFinder.FdoDirectories);

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

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

            Assert.AreEqual(0, dtoRepos.AllInstancesSansSubclasses("LgWritingSystem").Count());
            Assert.AreEqual(0, dtoRepos.AllInstancesSansSubclasses("LgCollation").Count());
            Assert.AreEqual(0, dtoRepos.AllInstancesSansSubclasses("CmSortSpec").Count());

            DomainObjectDTO lpDto  = dtoRepos.AllInstancesSansSubclasses("LangProject").First();
            XElement        lpElem = XElement.Parse(lpDto.Xml);

            var kalabaPath = Path.Combine(storePath, "x-kal.ldml");             // Note this migration does NOT yet convert to qaa-x-kal
            var kalabaNode = XDocument.Parse(Encoding.UTF8.GetString(File.ReadAllBytes(kalabaPath))).Root;

            Assert.That(kalabaNode.Name.LocalName, Is.EqualTo("ldml"));
            var identityNode = kalabaNode.Element("identity");

            Assert.That(identityNode.Element("language").Attribute("type").Value, Is.EqualTo("x-kal"));
            var        specialNode = kalabaNode.Element("special");
            XNamespace xmlns       = "http://www.w3.org/2000/xmlns/";

            Assert.That(specialNode.Attribute(xmlns + "palaso").Value, Is.EqualTo("urn://palaso.org/ldmlExtensions/v1"));
            XNamespace palaso = "urn://palaso.org/ldmlExtensions/v1";

            Assert.That(specialNode.Element(palaso + "languageName").Attribute("value").Value, Is.EqualTo("Kalaba"));
            Assert.That(specialNode.Element(palaso + "abbreviation").Attribute("value").Value, Is.EqualTo("Kal"));
            // Todo: check a lot more things.
            //Assert.AreEqual(1033, kalaba.LCID);

            //IWritingSystem frIpa = wsManager.Get("fr-fonipa-x-etic");
            //Assert.AreEqual("FrnI", frIpa.Abbreviation);
            //Assert.AreEqual("IPA Unicode 1.0", frIpa.Keyboard);

            var analysisWss = (string)lpElem.Element("AnalysisWss");
            //foreach (string id in analysisWss.Split(' '))
            //    Assert.IsTrue(wsManager.Exists(id));
            //var vernWss = (string)lpElem.Element("VernWss");
            //foreach (string id in vernWss.Split(' '))
            //    Assert.IsTrue(wsManager.Exists(id));

            //CheckWsProperty(dtoRepos.AllInstancesWithSubclasses("CmPossibilityList"), wsManager);

            //foreach (DomainObjectDTO dto in dtoRepos.AllInstancesWithValidClasses())
            //    CheckStringWsIds(wsManager, dto);

            DomainObjectDTO importSourceDto  = dtoRepos.AllInstancesWithSubclasses("ScrImportSource").First();
            XElement        importSourceElem = XElement.Parse(importSourceDto.Xml);

            Assert.AreEqual("x-kal", (string)importSourceElem.Element("WritingSystem").Element("Uni"));
            Assert.IsNull(importSourceElem.Element("ICULocale"));

            DomainObjectDTO mappingDto  = dtoRepos.AllInstancesWithSubclasses("ScrMarkerMapping").First();
            XElement        mappingElem = XElement.Parse(mappingDto.Xml);

            Assert.AreEqual("fr-fonipa-x-etic", (string)mappingElem.Element("WritingSystem").Element("Uni"));
            Assert.IsNull(mappingElem.Element("ICULocale"));

            DomainObjectDTO styleDto  = dtoRepos.AllInstancesWithSubclasses("StStyle").First();
            XElement        styleElem = XElement.Parse(styleDto.Xml);

            Assert.AreEqual("<default font>", (string)styleElem.Element("Rules").Element("Prop").Attribute("fontFamily"));
        }
Exemplo n.º 6
0
        public void DataMigration7000012_Unneeded_UserViewField_Removed_Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000012_UserViewField.xml");

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

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "UserViewField"
            });
            mockMDC.AddClass(2, "UserViewField", "CmObject", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000011, dtos, mockMDC, null);

            Assert.AreEqual(40, dtoRepos.AllInstancesWithSubclasses("UserViewField").Count());

            // Collect the UserViewField values.
            var userViewFieldDtos = new Dictionary <string, DomainObjectDTO>();

            foreach (var uvfDto in dtoRepos.AllInstancesWithSubclasses("UserViewField"))
            {
                userViewFieldDtos.Add(uvfDto.Guid.ToUpper(), uvfDto);
            }

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

            // Counts for fields that should not have been removed.
            int countRequired   = 0;
            int countStyle      = 0;
            int countHelpString = 0;
            int countFlid       = 0;
            int countType       = 0;

            foreach (var userViewField in dtoRepos.AllInstancesSansSubclasses("UserViewField"))
            {
                var uvfElement = XElement.Parse(userViewField.Xml);

                // Confirm that needed fields are still present.
                // Increment counter for fields occurring in UserViewField (but some may not always be present).
                if (uvfElement.XPathSelectElement("UserViewField/Required") != null)
                {
                    countRequired++;
                }
                if (uvfElement.XPathSelectElement("UserViewField/Style") != null)
                {
                    countStyle++;
                }
                if (uvfElement.XPathSelectElement("UserViewField/HelpString") != null)
                {
                    countHelpString++;
                }
                if (uvfElement.XPathSelectElement("UserViewField/Flid") != null)
                {
                    countFlid++;
                }
                if (uvfElement.XPathSelectElement("UserViewField/Type") != null)
                {
                    countType++;
                }

                // Try to get the unused elements in UserViewField (should be gone)
                Assert.IsNull(uvfElement.XPathSelectElement("UserViewField/Details"));
                Assert.IsNull(uvfElement.XPathSelectElement("UserViewField/Visibility"));
                Assert.IsNull(uvfElement.XPathSelectElement("UserViewField/SubfieldOf"));
                Assert.IsNull(uvfElement.XPathSelectElement("UserViewField/IsCustomField"));
            }

            // Expectations for occurrences of fields that should not have been removed from XML file
            Assert.AreEqual(1, countStyle, "Unexpected number of Style fields");
            Assert.AreEqual(3, countRequired, "Unexpected number of Required fields");
            Assert.AreEqual(36, countHelpString, "Unexpected number of HelpString fields");
            Assert.AreEqual(40, countFlid, "Unexpected number of Flid fields");
            Assert.AreEqual(40, countType, "Unexpected number of Type fields");
        }
Exemplo n.º 7
0
        public void DataMigration7000036Test()
        {
            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>");
            // This footnote should also have its ParaContainingOrc property set, but this test really doesn't care.
            StTextAndParaInfo footnoteGuids = new StTextAndParaInfo("ScrFootnote", "f213db11-7007-4a2f-9b94-06d6c96014ca", "Note General Paragraph", 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\" link=\"" + footnoteGuids.textGuid + "\"></Run>", true, false,
                                                                        "<Run ws=\"en\" link=\"" + footnoteGuids.textGuid + "\"></Run>");

            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);

            sb.Length = 0;
            sb.Append("<rt class=\"StJournalText\" guid=\"c1ecd177-e382-11de-8a39-0800200c9a66\">");
            sb.Append("<DateCreated val=\"2009-12-31 23:59:59.000\" />");
            sb.Append("<DateModified val=\"2010-01-01 23:59:59.000\" />");
            sb.Append("</rt>");
            var journalTextDto = new DomainObjectDTO("c1ecd177-e382-11de-8a39-0800200c9a66", "StJounalText",
                                                     sb.ToString());

            dtos.Add(journalTextDto);

            // 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);
            // BT of para
            var btDto = new DomainObjectDTO(contentsTextGuids.btGuid.ToString(), "CmTranslation",
                                            contentsTextGuids.btXml);

            dtos.Add(btDto);

            // 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", "StJounalText"
            });
            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"
            });
            mockMDC.AddClass(12, "StJounalText", "StText", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000035, dtos, mockMDC, null);

            DateTime beforeMigration = DateTime.Now.AddSeconds(-1);             // avoid tick problem

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

            int cJournalTexts = 0;

            foreach (DomainObjectDTO stTextDTO in dtoRepos.AllInstancesWithSubclasses("StText"))
            {
                XElement stText = XElement.Parse(stTextDTO.Xml);
                Assert.AreEqual(1, stText.Elements("DateModified").Count());
                XElement dateModified = stText.Element("DateModified");
                Assert.IsNotNull(dateModified);
                if (stTextDTO.Classname == "StJounalText")
                {
                    Assert.AreEqual(new DateTime(2010, 1, 1, 23, 59, 59).ToLocalTime(), ReadWriteServices.LoadDateTime(dateModified));
                    cJournalTexts++;
                }
                else
                {
                    Assert.GreaterOrEqual(ReadWriteServices.LoadDateTime(dateModified), beforeMigration);
                }
            }
            Assert.AreEqual(1, cJournalTexts);
        }
Exemplo n.º 8
0
        private void ConvertWeatherToCustomListAndField(string datafile)
        {
            var dtos = DataMigrationTestServices.ParseProjectFile(datafile);

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository repoDTO = new DomainObjectDtoRepository(7000016, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(repoDTO, 7000017, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000017, repoDTO.CurrentModelVersion, "Wrong updated version.");

            DomainObjectDTO dtoLP = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("LangProject"))
            {
                Assert.IsNull(dtoLP, "Only one LangProject object should exist");
                dtoLP = dto;
            }
            Assert.NotNull(dtoLP, "The LangProject object should exist");
            string sXml = dtoLP.Xml;

            Assert.IsFalse(sXml.Contains("<WeatherConditions>"), "The <WeatherConditions> element should have disappeared");
            string sLpOwnerGuid = GetGuidAsOwnerGuid(sXml);

            DomainObjectDTO dtoNbk = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("RnResearchNbk"))
            {
                Assert.IsNull(dtoNbk, "Only one RnResearchNbk should exist");
                Assert.IsTrue(dto.Xml.Contains(sLpOwnerGuid), "The RnResearchNbk should be owned by the LangProject");
                dtoNbk = dto;
            }
            Assert.NotNull(dtoNbk, "The RnResearchNbk should exist");
            string          sNbkOwnerGuid = GetGuidAsOwnerGuid(dtoNbk.Xml);
            int             cList         = 0;
            DomainObjectDTO dtoTypeList   = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("CmPossibilityList"))
            {
                sXml = dto.Xml;
                if (sXml.Contains(" ownerguid="))
                {
                    Assert.IsTrue(sXml.Contains(sNbkOwnerGuid), "Any remaining owned Possibility List must be owned by Data Notebook");
                    Assert.IsNull(dtoTypeList, "Only one list should be owned by the Data Notebook");
                    dtoTypeList = dto;
                }
                ++cList;
            }
            Assert.AreEqual(2, cList, "Two CmPossibilityList objects should still exist");

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesWithSubclasses("RnGenericRec"))
            {
                sXml = dto.Xml;
                Assert.IsFalse(sXml.Contains("<Weather"), "Any <Weather> element should have disappeared");
                int idxCustom = sXml.IndexOf("<Custom");
                if (idxCustom >= 0)
                {
                    string sCustom = sXml.Substring(idxCustom);
                    Assert.IsTrue(sCustom.StartsWith("<Custom name=\"Weather\">"), "Converted weather element has proper start element");
                    Assert.IsTrue(sCustom.Contains("</Custom>"), "Converted weather element has proper end element");
                }
            }

            Assert.IsTrue(mockMdc.FieldExists("RnGenericRec", "Weather", false), "Weather field exists in RnGenericRec");
            int flid = mockMdc.GetFieldId("RnGenericRec", "Weather", false);

            Assert.IsTrue(mockMdc.IsCustom(flid), "Weather field is a custom field");

            // This test file has three overlays; none should be deleted, since we are keeping the weather list.
            Assert.That(repoDTO.AllInstancesSansSubclasses("CmOverlay"), Has.Count.EqualTo(3));
        }
Exemplo n.º 9
0
        public void VerifyDefaultTypeInLexEntryRefs()
        {
            var mockMdc = new MockMDCForDataMigration();

            mockMdc.AddClass(1, "CmObject", null, new List <string> {
                "LexEntryRef", "CmPossibilityList", "LanguageProject", "LexEntryType"
            });
            mockMdc.AddClass(2, "LexEntryRef", "CmPossibility", new List <string>());
            mockMdc.AddClass(3, "CmPossibilityList", "CmObject", new List <string>());
            mockMdc.AddClass(4, "LanguageProject", "CmObject", new List <string>());
            mockMdc.AddClass(5, "LexEntryType", "CmObject", new List <string>());

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000070.xml");
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000069, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            Assert.AreEqual(4, dtoRepos.AllInstancesWithSubclasses("LexEntryRef").Count(), "The LexEntryRef test data has changed");
            Assert.AreEqual(2, dtoRepos.AllInstancesWithSubclasses("CmPossibilityList").Count(), "The CmPossibilityList test data has changed");

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

            // Make sure new default types are added.
            var lexEntryRefs = dtoRepos.AllInstancesWithSubclasses("LexEntryRef").ToList();
            var data         = XElement.Parse(lexEntryRefs[0].Xml);
            var defTypeElt   = data.Element("VariantEntryTypes");

            Assert.IsNotNull(defTypeElt);
            Assert.That(defTypeElt != null && defTypeElt.HasElements, "Should have components (or variants)");
            var objSurElem = defTypeElt.Element("objsur");

            Assert.IsNotNull(objSurElem);
            Assert.AreEqual("3942addb-99fd-43e9-ab7d-99025ceb0d4e", objSurElem.FirstAttribute.Value);
            var refTypeAttr = objSurElem.Attribute("t");

            Assert.IsNotNull(refTypeAttr, "The type attribute should be set on the 'objsur' element for the default c.f.");
            Assert.AreEqual(refTypeAttr.Value, "r");
            data       = XElement.Parse(lexEntryRefs[1].Xml);
            defTypeElt = data.Element("ComplexEntryTypes");
            Assert.IsNotNull(defTypeElt);
            Assert.That(defTypeElt != null && defTypeElt.HasElements, "Should have components (or variants)");
            objSurElem = defTypeElt.Element("objsur");
            Assert.IsNotNull(objSurElem);
            Assert.AreEqual("fec038ed-6a8c-4fa5-bc96-a4f515a98c50", objSurElem.FirstAttribute.Value);
            refTypeAttr = objSurElem.Attribute("t");
            Assert.IsNotNull(refTypeAttr, "The type attribute should be set on the 'objsur' element for the default variant");
            Assert.AreEqual(refTypeAttr.Value, "r");
            // Make sure that the complex form ref which had bogus VariantTypes was cleaned up
            data       = XElement.Parse(lexEntryRefs[2].Xml);
            defTypeElt = data.Element("VariantEntryTypes");
            Assert.IsNull(defTypeElt);
            defTypeElt = data.Element("ComplexEntryTypes");
            Assert.IsNotNull(defTypeElt);
            Assert.That(defTypeElt != null && defTypeElt.HasElements, "Should have components (or variants)");
            objSurElem = defTypeElt.Element("objsur");
            Assert.IsNotNull(objSurElem);
            Assert.AreEqual("1f6ae209-141a-40db-983c-bee93af0ca3c", objSurElem.FirstAttribute.Value);
            refTypeAttr = objSurElem.Attribute("t");
            Assert.IsNotNull(refTypeAttr, "The type attribute should be set on the 'objsur' element for the default variant");
            Assert.AreEqual(refTypeAttr.Value, "r");
            // Make sure that a variant which had bogus ComplexFormType was cleaned up
            data       = XElement.Parse(lexEntryRefs[3].Xml);
            defTypeElt = data.Element("ComplexEntryTypes");
            Assert.IsNull(defTypeElt, "Complex form types should have been removed.");
            defTypeElt = data.Element("VariantEntryTypes");
            Assert.IsNotNull(defTypeElt, "default variant type should have been added");
            Assert.That(defTypeElt != null && defTypeElt.HasElements, "Should have components (or variants)");
            objSurElem = defTypeElt.Element("objsur");
            Assert.IsNotNull(objSurElem);
            Assert.AreEqual("3942addb-99fd-43e9-ab7d-99025ceb0d4e", objSurElem.FirstAttribute.Value);
            refTypeAttr = objSurElem.Attribute("t");
            Assert.IsNotNull(refTypeAttr, "The type attribute should be set on the 'objsur' element for the default variant");
            Assert.AreEqual(refTypeAttr.Value, "r");
        }