public void GetCustomFieldsForThisCmObject_ShouldGetCustomFieldSettings()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);
            Dictionary<string, LfConfigFieldBase> lfCustomFieldList = new Dictionary<string, LfConfigFieldBase>();
            ConvertFdoToMongoCustomField converter = new ConvertFdoToMongoCustomField(cache,
                new TestLogger(TestContext.CurrentContext.Test.Name));

            // Exercise
            var customDataDocument = converter.GetCustomFieldsForThisCmObject(entry, "entry",
                _listConverters, lfCustomFieldList);

            // Verify
            var expectedCustomFieldNames = new List<string>
            {
                "customField_entry_Cust_Date",
                "customField_entry_Cust_MultiPara",
                "customField_entry_Cust_Number",
                "customField_entry_Cust_Single_Line",
                "customField_entry_Cust_Single_Line_All",
                "customField_entry_Cust_Single_ListRef"
            };
            CollectionAssert.AreEquivalent(expectedCustomFieldNames, customDataDocument[0].AsBsonDocument.Names);
        }
Esempio n. 2
0
 protected BsonDocument GetCustomFieldValues(FdoCache cache, ICmObject obj, string objectType = "entry")
 {
     // The objectType parameter is used in the names of the custom fields (and nowhere else).
     var convertCustomField = new ConvertFdoToMongoCustomField(cache, new LfMerge.Logging.NullLogger());
     Dictionary<string, LfConfigFieldBase> lfCustomFieldList = new Dictionary<string, LfConfigFieldBase>();
     return convertCustomField.GetCustomFieldsForThisCmObject(obj, objectType, _listConverters, lfCustomFieldList);
 }
        public void GetCustomFieldForThisCmObject_ShouldGetSingleLineAll()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            var converter = new ConvertFdoToMongoCustomField(cache,
                new TestLogger(TestContext.CurrentContext.Test.Name));
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);

            // Exercise
            Dictionary<string, LfConfigFieldBase>_lfCustomFieldList = new Dictionary<string, LfConfigFieldBase>();
            BsonDocument customDataDocument = converter.GetCustomFieldsForThisCmObject(entry, "entry", _listConverters, _lfCustomFieldList);

            // Verify English and french values
            Assert.That(customDataDocument[0]["customField_entry_Cust_Single_Line_All"].AsBsonDocument.GetElement(0).Value["value"].ToString(),
                Is.EqualTo("Some custom text"));
            Assert.That(customDataDocument[0]["customField_entry_Cust_Single_Line_All"].AsBsonDocument.GetElement(1).Value["value"].ToString(),
                Is.EqualTo("French custom text"));
        }
        public void GetCustomFieldForThisCmObject_ShouldGetMultiListRef()
        {
            // Setup
            var lfProject = LanguageForgeProject.Create(_env.Settings, TestProjectCode);
            var cache = lfProject.FieldWorksProject.Cache;
            var converter = new ConvertFdoToMongoCustomField(cache,
                new TestLogger(TestContext.CurrentContext.Test.Name));
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;
            Assert.That(entry, Is.Not.Null);

            // Exercise
            Dictionary<string, LfConfigFieldBase>_lfCustomFieldList = new Dictionary<string, LfConfigFieldBase>();
            ILexSense[] senses = entry.SensesOS.ToArray();
            BsonDocument customDataDocument = converter.GetCustomFieldsForThisCmObject(senses[0], "senses", _listConverters, _lfCustomFieldList);

            // Verify.  (Note, in the fwdata file, the custom item labels are in reverse order)
            Assert.That(customDataDocument[0].AsBsonDocument["customField_senses_Cust_Multi_ListRef"]["values"][1].ToString(),
                Is.EqualTo("fci"));
            Assert.That(customDataDocument[0].AsBsonDocument["customField_senses_Cust_Multi_ListRef"]["values"][0].ToString(),
                Is.EqualTo("sci"));
        }
Esempio n. 5
0
        public void Setup()
        {
            _env = new TestEnvironment(resetLfProjectsDuringCleanup: false);
            _conn = MainClass.Container.Resolve<IMongoConnection>() as MongoConnectionDouble;
            if (_conn == null)
                throw new AssertionException("FDO tests need a mock MongoConnection that stores data in order to work.");
            _recordFactory = MainClass.Container.Resolve<MongoProjectRecordFactory>() as MongoProjectRecordFactoryDouble;
            if (_recordFactory == null)
                throw new AssertionException("Mongo->Fdo roundtrip tests need a mock MongoProjectRecordFactory in order to work.");

            _lfProj = FdoTestFixture.lfProj;
            _cache = _lfProj.FieldWorksProject.Cache;
            _wsEn = _cache.WritingSystemFactory.GetWsFromStr("en");
            _undoHelper = new UndoableUnitOfWorkHelper(_cache.ActionHandlerAccessor, "undo", "redo");
            _undoHelper.RollBack = true;

            sutMongoToFdo = new TransferMongoToFdoAction(
                _env.Settings,
                _env.Logger,
                _conn,
                _recordFactory
            );

            sutFdoToMongo = new TransferFdoToMongoAction(
                _env.Settings,
                _env.Logger,
                _conn
            );

            var convertCustomField = new ConvertFdoToMongoCustomField(_cache, _env.Logger);
            _listConverters = new Dictionary<string, ConvertFdoToMongoOptionList>();
            foreach (KeyValuePair<string, ICmPossibilityList> pair in convertCustomField.GetCustomFieldParentLists())
            {
                string listCode = pair.Key;
                ICmPossibilityList parentList = pair.Value;
                _listConverters[listCode] = ConvertOptionListFromFdo(_lfProj, listCode, parentList);
            }
        }