Beispiel #1
0
        public void MarkPersisted_non_flat_one_to_one_and_one_to_many_relations()
        {
            MockEntity entity           = new MockEntity();
            MockEntity relationalEntity = new MockEntity();

            relationalEntity.RelationalEntities.Add(new MockEntity());
            entity.RelationalEntities.Add(new MockEntity()
            {
                RelationalEntity1 = relationalEntity
            });
            Assert.AreEqual(EntityState.New, entity.State);
            Assert.AreEqual(EntityState.New, entity.RelationalEntities.Single().State);
            Assert.AreEqual(EntityState.New, entity.RelationalEntities.Single().RelationalEntity1.State);
            Assert.AreEqual(EntityState.New, entity.RelationalEntities.Single().RelationalEntity1.RelationalEntities.Single().State);

            Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { new Tuple <string, object>("Key", "Value") };
            Mock <IDataAccessLayer>  mockDal     = new Mock <IDataAccessLayer>();

            mockDal.Setup(m => m.GetEntity <MockEntity, IDbEntityProjection>(primaryKeys)).Returns(Task.FromResult(entity));
            DbEntityRepository.MarkPersisted(entity, entity.GetType());

            Assert.AreEqual(EntityState.Persisted, entity.State);
            Assert.AreEqual(EntityState.Persisted, entity.RelationalEntities.Single().State);
            Assert.AreEqual(EntityState.Persisted, entity.RelationalEntities.Single().RelationalEntity1.State);
            Assert.AreEqual(EntityState.Persisted, entity.RelationalEntities.Single().RelationalEntity1.RelationalEntities.Single().State);
        }
Beispiel #2
0
        public void MarkPersisted_flat_entity()
        {
            MockEntity entity = new MockEntity();

            Assert.AreEqual(EntityState.New, entity.State);

            Tuple <string, object>[] primaryKeys = new Tuple <string, object>[] { new Tuple <string, object>("Key", "Value") };
            Mock <IDataAccessLayer>  mockDal     = new Mock <IDataAccessLayer>();

            mockDal.Setup(m => m.GetEntity <MockEntity, IDbEntityProjection>(primaryKeys)).Returns(Task.FromResult(entity));
            DbEntityRepository.MarkPersisted(entity, entity.GetType());

            Assert.AreEqual(EntityState.Persisted, entity.State);
        }
Beispiel #3
0
        public void CanCreateSolrDictionary()
        {
            const string     entityTypeName    = "Entity type name";
            const double     numericValue      = 42.0;
            MockEntity       MockEntityChanges = new MockEntity();
            List <FormField> formFields        = new List <FormField>();

            TextValue stringTextValue = new TextValue();

            stringTextValue.LanguageCode = "en";
            stringTextValue.Value        = "Forty two";
            TextField textField = new TextField();

            textField.Name = "Text";
            textField.SetTextValues(new List <TextValue>()
            {
                stringTextValue
            });
            formFields.Add(textField);

            TextValue numericTextValue = new TextValue();

            numericTextValue.LanguageCode = "en";
            numericTextValue.Value        = numericValue.ToString();

            TextField numericField = new TextField();

            numericField.Name = "Numeric";
            numericField.SetTextValues(new List <TextValue>()
            {
                numericTextValue
            });
            formFields.Add(numericField);


            // Add two options and select second

            OptionsField optionsField = new OptionsField();

            optionsField.Name = "Options field";

            TextValue nonSelectedValue = new TextValue();

            nonSelectedValue.LanguageCode = "en";
            nonSelectedValue.Value        = "Not selected";

            TextValue selectedValue = new TextValue();

            selectedValue.LanguageCode = "en";
            selectedValue.Value        = "Selected";

            Option notSelectedOption = new Option();

            notSelectedOption.Selected = false;
            notSelectedOption.Value.Add(nonSelectedValue);

            Option selectedOption = new Option();

            selectedOption.Selected = true;
            selectedOption.Value.Add(selectedValue);

            List <Option> optList = new List <Option>();

            optList.Add(notSelectedOption);
            optList.Add(selectedOption);

            optionsField.Options = optList;

            formFields.Add(optionsField);

            CFMetadataSet metadataSet = CreateMetadataSet(
                mDh,
                "name metadataset",
                "description metadataset",
                formFields);

            CFEntityType entityType = CreateEntityType(mDh,
                                                       entityTypeName,
                                                       "description entity type",
                                                       "Items",
                                                       metadataSet
                                                       );

            MockEntity.EntityType        = entityType;
            MockEntityChanges.EntityType = entityType;
            //MockEntityChanges.MetadataSets
            MockEntity.MetadataSets = new List <CFMetadataSet>()
            {
                metadataSet
            };
            MockEntityChanges.MetadataSets = new List <CFMetadataSet>()
            {
                metadataSet
            };
            MockEntityChanges.MetadataSets[0].UpdateValueFields(formFields);

            MockEntity.UpdateValues(MockEntityChanges);

            // set vales

            //MockEntity.MetadataSets[0].UpdateValueFields(test);


            Dictionary <string, object> solrDictionary =
                MockEntity.ToSolrDictionary();

            string metadataSetGuid  = metadataSet.MappedGuid.ToString().Replace("-", "_");
            string textFieldGuid    = textField.MappedGuid.ToString().Replace("-", "_");
            string numericFieldGuid = numericField.MappedGuid.ToString().Replace("-", "_");
            string optionFieldGuid  = optionsField.MappedGuid.ToString().Replace("-", "_");

            Dictionary <string, object> expectedResult = new Dictionary <string, object>()
            {
                { "id", solrDictionary["id"] },
                { "modeltype_s", MockEntity.GetType().Name },
                { "entitytype_s", entityTypeName },
                { $@"name_{metadataSetGuid}_{textFieldGuid}_txt_en",
                  textField.Name },
                { $@"name_{metadataSetGuid}_{numericFieldGuid}_txt_en",
                  numericField.Name },
                { $@"name_{metadataSetGuid}_{optionFieldGuid}_txt_en",
                  optionsField.Name },
                { $@"value_{metadataSetGuid}_{textFieldGuid}_txts_en",
                  new List <string>()
                  {
                      textField.Values[0].Value
                  } },
                { $@"value_{metadataSetGuid}_{numericFieldGuid}_txts_en",
                  new List <string>()
                  {
                      numericValue.ToString()
                  } },
                { $@"value_{metadataSetGuid}_{numericFieldGuid}_ds",
                  new List <decimal>()
                  {
                      (decimal)numericValue
                  } },
                { $@"value_{metadataSetGuid}_{numericFieldGuid}_is",
                  new List <int>()
                  {
                      (int)numericValue
                  } },
                { $@"value_{metadataSetGuid}_{optionFieldGuid}_txts_en",
                  new List <string>()
                  {
                      selectedValue.Value
                  } }
            };

            foreach (KeyValuePair <string, object> entry in expectedResult)
            {
                Assert.AreEqual(entry.Value, solrDictionary[entry.Key]);
            }
        }