public void GetCustomFieldsForThisCmObject_ShouldGetCustomFieldSettings()
        {
            // Setup
            var  lfProject = _lfProj;
            var  cache     = _cache;
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var  entry     = _servLoc.GetInstance <ILexEntryRepository>().GetObject(entryGuid);

            Assert.That(entry, Is.Not.Null);
            ConvertFdoToMongoCustomField converter = new ConvertFdoToMongoCustomField(cache, _servLoc,
                                                                                      new TestLogger(TestContext.CurrentContext.Test.Name));

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

            // 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);
        }
예제 #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, _servLoc, new LfMerge.Core.Logging.NullLogger());

            return(convertCustomField.GetCustomFieldsForThisCmObject(obj, objectType, _listConverters));
        }
예제 #3
0
        public void Setup()
        {
            _env    = new TestEnvironment(resetLfProjectsDuringCleanup: false);
            _conn   = MainClass.Container.Resolve <IMongoConnection>() as MongoConnectionDouble;
            _counts = MainClass.Container.Resolve <EntryCounts>();
            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;
            _servLoc             = new FwServiceLocatorCache(_cache.ServiceLocator);
            _wsEn                = _cache.WritingSystemFactory.GetWsFromStr("en");
            _undoHelper          = new UndoableUnitOfWorkHelper(_cache.ActionHandlerAccessor, "undo", "redo");
            _undoHelper.RollBack = true;

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

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

            var convertCustomField = new ConvertFdoToMongoCustomField(_cache, _servLoc, _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);
            }
        }
        public void GetCustomFieldForThisCmObject_ShouldGetSingleLineAll()
        {
            // Setup
            var lfProject = _lfProj;
            var converter = new ConvertFdoToMongoCustomField(_cache, _servLoc,
                                                             new TestLogger(TestContext.CurrentContext.Test.Name));
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var  entry     = _servLoc.GetInstance <ILexEntryRepository>().GetObject(entryGuid) as ILexEntry;

            Assert.That(entry, Is.Not.Null);

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

            // 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 = _lfProj;
            var cache     = _cache;
            var converter = new ConvertFdoToMongoCustomField(cache, _servLoc,
                                                             new TestLogger(TestContext.CurrentContext.Test.Name));
            Guid entryGuid = Guid.Parse(TestEntryGuidStr);
            var  entry     = _servLoc.GetInstance <ILexEntryRepository>().GetObject(entryGuid);

            Assert.That(entry, Is.Not.Null);

            // Exercise
            ILexSense[]  senses             = entry.SensesOS.ToArray();
            BsonDocument customDataDocument = converter.GetCustomFieldsForThisCmObject(senses[0], "senses", _listConverters);

            // 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"));
        }