Beispiel #1
0
        protected BsonDocument GetCustomFieldValues(LcmCache cache, ICmObject obj, string objectType = "entry")
        {
            // The objectType parameter is used in the names of the custom fields (and nowhere else).
            var convertCustomField = new ConvertLcmToMongoCustomField(cache, _servLoc, new LfMerge.Core.Logging.NullLogger());

            return(convertCustomField.GetCustomFieldsForThisCmObject(obj, objectType, _listConverters));
        }
        public void GetCustomFieldsForThisCmObject_ShouldGetCustomFieldSettings()
        {
            // Setup
            var lfProject = _lfProj;
            var cache     = _cache;
            var entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry     = _servLoc.GetInstance <ILexEntryRepository>().GetObject(entryGuid);

            Assert.That(entry, Is.Not.Null);
            var converter = new ConvertLcmToMongoCustomField(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);
        }
Beispiel #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("LCM 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->Lcm roundtrip tests need a mock MongoProjectRecordFactory in order to work.");
            }

            _lfProj = LcmTestFixture.lfProj;
            _cache  = _lfProj.FieldWorksProject.Cache;
            Assert.That(_cache, Is.Not.Null);
            _servLoc             = new FwServiceLocatorCache(_cache.ServiceLocator);
            _wsEn                = _cache.WritingSystemFactory.GetWsFromStr("en");
            _undoHelper          = new UndoableUnitOfWorkHelper(_cache.ActionHandlerAccessor, "undo", "redo");
            _undoHelper.RollBack = true;

            SutMongoToLcm = new TransferMongoToLcmAction(
                _env.Settings,
                _env.Logger,
                _conn,
                _recordFactory,
                _counts
                );

            SutLcmToMongo = new TransferLcmToMongoAction(
                _env.Settings,
                _env.Logger,
                _conn,
                _recordFactory
                );

            var convertCustomField = new ConvertLcmToMongoCustomField(_cache, _servLoc, _env.Logger);

            _listConverters = new Dictionary <string, ConvertLcmToMongoOptionList>();
            foreach (KeyValuePair <string, ICmPossibilityList> pair in convertCustomField.GetCustomFieldParentLists())
            {
                string             listCode   = pair.Key;
                ICmPossibilityList parentList = pair.Value;
                _listConverters[listCode] = ConvertOptionListFromLcm(_lfProj, listCode, parentList);
            }
        }
        public void GetCustomFieldForThisCmObject_ShouldGetSingleLineAll()
        {
            // Setup
            var lfProject = _lfProj;
            var converter = new ConvertLcmToMongoCustomField(_cache, _servLoc,
                                                             new TestLogger(TestContext.CurrentContext.Test.Name));
            var entryGuid = Guid.Parse(TestEntryGuidStr);
            var entry     = _servLoc.GetInstance <ILexEntryRepository>().GetObject(entryGuid) as ILexEntry;

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

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

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

            // Exercise
            var senses             = entry.SensesOS.ToArray();
            var 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"));
        }