コード例 #1
0
        public IObjectMapper GetOrCreateMapper()
        {
            if (_mapper != null)
            {
                return(_mapper);
            }

            _mapper = MapperContext.ObjectMapperFactory.Create(this);

            MapperKey.MappingData = null;

            if (_mapper == null)
            {
                return(null);
            }

            if (MapperContext.UserConfigurations.ValidateMappingPlans)
            {
                // TODO: Test coverage for validation of standalone child mappers
                MappingValidator.Validate(_mapper.MapperData);
            }

            StaticMapperCache <TSource, TTarget> .AddIfAppropriate(_mapper, this);

            return(_mapper);
        }
コード例 #2
0
        public void Mapping_CanCreate()
        {
            Mapping mapping = NewMapping(NewBinding <Person, PersonDto>());

            var actual = MappingValidator.IsValid(mapping);

            Assert.AreEqual(true, actual);
        }
コード例 #3
0
        public void ValidatingRuleSetReturnsValidationResults()
        {
            var mappingManager           = new MappingManager();
            var mappingValidationManager = new MappingValidator(mappingManager, new[] { new DummyValidationRuleError() });

            var validationResults = mappingValidationManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), new SolrSchema()).ToList();

            Assert.AreEqual(1, validationResults.Count);
        }
コード例 #4
0
        public void ValidateWithEmptyIdAndName1()
        {
            var mapping = new Dictionary <MappingInfo, MappingInfo> {
                { new MappingInfo(string.Empty, string.Empty), new MappingInfo(string.Empty, "Name") },
            };
            var validator = new MappingValidator(mapping, "Tester")
            {
                JiraConnector = ConnectorMock, Logger = LoggerMock
            };;

            Assert.IsFalse(validator.Validate(), "Incorrect validator processing.");
        }
コード例 #5
0
        public void ValidateWithEmptyName()
        {
            var mapping = new Dictionary <MappingInfo, MappingInfo> {
                { new MappingInfo("Scope:0", string.Empty), new MappingInfo("0", string.Empty) },
                { new MappingInfo("Scope:1", string.Empty), new MappingInfo("1", string.Empty) },
            };
            var validator = new MappingValidator(mapping, "Tester")
            {
                JiraConnector = ConnectorMock, Logger = LoggerMock
            };;

            Assert.IsTrue(validator.Validate(), "Incorrect validator processing.");
        }
コード例 #6
0
        public MappingValidatorTests()
        {
            _fhirTemplateFactory       = CollectionFhirTemplateFactory.Default;
            _collectionTemplateFactory = new CollectionContentTemplateFactory(
                new JsonPathContentTemplateFactory(),
                new IotJsonPathContentTemplateFactory(),
                new IotCentralJsonPathContentTemplateFactory());

            _iotConnectorValidator = new MappingValidator(
                _collectionTemplateFactory,
                _fhirTemplateFactory,
                new R4FhirLookupTemplateProcessor());
        }
コード例 #7
0
        public void StringMappedToStringShouldNotReturnError()
        {
            var mappingTypesCompatibleRule = new MappingTypesAreCompatibleWithSolrTypesRule(new[] { new StringSolrFieldTypeChecker() });

            var mgr           = new MappingManager();
            var schemaManager = new MappingValidator(mgr, new[] { mappingTypesCompatibleRule });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaMappingTypes.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.Equal(0, validationResults.Count);
        }
コード例 #8
0
        public void MultivaluedSolrFieldMappedToCollectionShouldNotReturnError()
        {
            var mgr = new MappingManager();

            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("NameCollection"), "name");

            var schemaManager = new MappingValidator(mgr, new[] { new MultivaluedMappedToCollectionRule() });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaMultiValuedName.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.AreEqual(0, validationResults.Count);
        }
コード例 #9
0
        public ISolrOperations <T> GetServer(ISolrConnection connection)
        {
            var basicServer = GetBasicServer(connection);

            MappingValidator = new MappingValidator(MappingManager, new IValidationRule[]
            {
                new MappedPropertiesIsInSolrSchemaRule(),
                new RequiredFieldsAreMappedRule(),
                new UniqueKeyMatchesMappingRule(),
                new MultivaluedMappedToCollectionRule()
            });

            ISolrOperations <T> server = new SolrServer <T>(basicServer, MappingManager, MappingValidator);

            return(server);
        }
コード例 #10
0
        public void NonMatchingUniqueKeyMappingShouldReturnError()
        {
            var mgr = new MappingManager();

            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("Name"), "name");
            mgr.SetUniqueKey(typeof(SchemaMappingTestDocument).GetProperty("Name"));

            var schemaManager = new MappingValidator(mgr, new[] { new UniqueKeyMatchesMappingRule() });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.AreEqual(1, validationResults.Count);
        }
コード例 #11
0
ファイル: SolrNet.cs プロジェクト: vladen/SolrNet
        public static ISolrOperations <T> GetServer <T>(ISolrConnection connection)
        {
            IReadOnlyMappingManager mapper = new MemoizingMappingManager(new AttributesMappingManager());

            IReadOnlyMappingManager mappingManager   = mapper;
            IMappingValidator       mappingValidator = new MappingValidator(mapper, new IValidationRule[] {
                new MappedPropertiesIsInSolrSchemaRule(),
                new RequiredFieldsAreMappedRule(),
                new UniqueKeyMatchesMappingRule(),
                new MultivaluedMappedToCollectionRule()
            });

            var basicServer            = GetBasicServer <T>(connection);
            ISolrOperations <T> server = new SolrServer <T>(basicServer, mappingManager, mappingValidator);

            return(server);
        }
コード例 #12
0
        public void RequiredSolrFieldForWhichNoCopyFieldExistsShouldReturnError()
        {
            var mgr = new MappingManager();

            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof(SchemaMappingTestDocument).GetProperty("ID"));

            var schemaManager = new MappingValidator(mgr, new[] { new RequiredFieldsAreMappedRule() });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.Equal(1, validationResults.Count);
        }
コード例 #13
0
        public void CollectionMappedToNonMultiValuedFolrFieldShouldReturnError()
        {
            var mgr = new MappingManager();

            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("NameCollection"), "author");

            var schemaManager = new MappingValidator(mgr, new[] { new MultivaluedMappedToCollectionRule() });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaMultiValuedName.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.Single(validationResults);
            testOutputHelper.WriteLine(validationResults[0].Message);
        }
        public void MappedPropertyForWhichSolrFieldExistsInSchemaShouldNotReturnError()
        {
            var mgr = new MappingManager();

            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof(SchemaMappingTestDocument).GetProperty("ID"));
            mgr.Add(typeof(SchemaMappingTestDocument).GetProperty("Name"), "name");

            var schemaManager = new MappingValidator(mgr, new[] { new MappedPropertiesIsInSolrSchemaRule() });

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser  = new SolrSchemaParser();
            var schema            = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), schema).ToList();

            Assert.Empty(validationResults);
        }
コード例 #15
0
 public void ThrowNowIfMappingPlanIsIncomplete() => MappingValidator.Validate(ConfigInfo);
コード例 #16
0
 void IMapper.ThrowNowIfAnyMappingPlanIsIncomplete() => MappingValidator.Validate(this);