public INodeMappingExpression <TDestination> CustomProperty( Expression <Func <TDestination, object> > destinationProperty, CustomPropertyMapping mapping, bool requiresInclude, bool allowCaching ) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } else if (mapping == null) { throw new ArgumentNullException("mapping"); } var mapper = new CustomPropertyMapper( mapping, requiresInclude, allowCaching, _nodeMapper, destinationProperty.GetPropertyInfo() ); _nodeMapper.InsertPropertyMapper(mapper); return(this); }
public void FormatValueFromDirectory_ByteArray_ReturnsGuid() { //prepare var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, Guid>(_mappingArguments, _convertFrom, _convertTo, _convertToFilter, _compareTo); //act var value = propertyMapping.FormatValueFromDirectory(new DirectoryAttribute("name", _guid.ToByteArray()), "dn"); //assert value.CastTo <Guid>().ToByteArray().Should().Have.SameSequenceAs(_guid.ToByteArray()); }
public void FormatValueToFilter_Guid_ReturnsStringOctet() { //prepare var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, Guid>(_mappingArguments, _convertFrom, _convertTo, _convertToFilter, _compareTo); //act var value = propertyMapping.FormatValueToFilter(_guid); //assert value.Should().Be.EqualTo(_guid.ToStringOctet()); }
public void GetDirectoryAttributeModification_ByteArray_ReturnsByteArray() { //prepare _mappingArguments.Getter = d => _guid; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, Guid>(_mappingArguments, _convertFrom, _convertTo, _convertToFilter, _compareTo); //act var value = propertyMapping.GetDirectoryAttributeModification(this); //assert value.Operation.Should().Be.EqualTo(DirectoryAttributeOperation.Replace); value.Name.Should().Be.EqualTo(_mappingArguments.AttributeName); value[0].As <byte[]>().Should().Have.SameSequenceAs(_guid.ToByteArray()); }
public void IsEqual_BothNull_ReturnsTrue() { //prepare _mappingArguments.Getter = t => null; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, Guid>(_mappingArguments, null, _convertTo, null, null); DirectoryAttributeModification modification; //act var value = propertyMapping.IsEqual(this, null, out modification); //assert value.Should().Be.True(); modification.Should().Be.Null(); }
public void GetDirectoryAttributeModification_StringArray_ReturnsStringArray() { //prepare _mappingArguments.Getter = d => new [] { "x" }; Func <string[], object> convertTo = s => new[] { "1", "2" }; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, string[]>(_mappingArguments, null, convertTo, null, null); //act var value = propertyMapping.GetDirectoryAttributeModification(this); //assert value.Operation.Should().Be.EqualTo(DirectoryAttributeOperation.Replace); value.Name.Should().Be.EqualTo(_mappingArguments.AttributeName); value.GetValues(typeof(string)).As <string[]>().Should().Have.SameSequenceAs(new[] { "1", "2" }); }
public void GetDirectoryAttributeModification_String_ReturnsString() { //prepare _mappingArguments.Getter = d => "str"; Func <string, object> convertTo = s => "convert"; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, string>(_mappingArguments, null, convertTo, null, null); //act var value = propertyMapping.GetDirectoryAttributeModification(this); //assert value.Operation.Should().Be.EqualTo(DirectoryAttributeOperation.Replace); value.Name.Should().Be.EqualTo(_mappingArguments.AttributeName); value[0].As <string>().Should().Be.EqualTo("convert"); }
public void IsEqual_EqualFuncReturnsFalseButEqualGuids_ReturnsFalse() { //prepare Func <Guid, Guid, bool> isEqual = (g1, g2) => false; _mappingArguments.Getter = t => _guid; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, Guid>(_mappingArguments, null, _convertTo, null, isEqual); DirectoryAttributeModification modification; //act var value = propertyMapping.IsEqual(this, _guid, out modification); //assert value.Should().Be.False(); modification.Should().Not.Be.Null(); }
public void GetDirectoryAttributeModification_ByteArrayArray_ReturnsByteArrayArray() { //prepare _mappingArguments.Getter = d => new[] { _guid.ToByteArray() }; Func <byte[][], object> convertTo = s => new[] { _guid.ToByteArray(), _guid.ToByteArray() }; var propertyMapping = new CustomPropertyMapping <CustomPropertyMappingTest, byte[][]>(_mappingArguments, null, convertTo, null, null); //act var value = propertyMapping.GetDirectoryAttributeModification(this); //assert value.Operation.Should().Be.EqualTo(DirectoryAttributeOperation.Replace); value.Name.Should().Be.EqualTo(_mappingArguments.AttributeName); value.GetValues(typeof(byte[])).As <byte[][]>()[0].Should().Have.SameSequenceAs(_guid.ToByteArray()); value.GetValues(typeof(byte[])).As <byte[][]>()[1].Should().Have.SameSequenceAs(_guid.ToByteArray()); }
/// <summary> /// Maps a custom property not covered by the other derivations /// of <see cref="PropertyMapperBase"/>. /// </summary> /// <param name="mapping"> /// The custom mapping. /// </param> /// <param name="allowCaching"> /// Whether the property should allow its mapped value to be cached /// and reused. /// </param> /// <param name="requiresInclude"></param> /// <param name="destinationProperty"></param> /// <param name="nodeMapper"></param> public CustomPropertyMapper( CustomPropertyMapping mapping, bool requiresInclude, bool allowCaching, NodeMapper nodeMapper, PropertyInfo destinationProperty ) : base(nodeMapper, destinationProperty) { if (mapping == null) { throw new ArgumentNullException("mapping"); } RequiresInclude = requiresInclude; AllowCaching = allowCaching; _mapping = mapping; }
public INodeMappingExpression <TDestination> ForProperty <TProperty>( Expression <Func <TDestination, TProperty> > destinationProperty, Func <Node, string[], object> propertyMapping, bool requiresInclude ) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } else if (propertyMapping == null) { throw new ArgumentNullException("propertyMapping"); } CustomPropertyMapping mapping = (id, paths, cache) => { var node = new Node(id); if (string.IsNullOrEmpty(node.Name)) { return(null); } return(propertyMapping(node, paths)); }; var mapper = new CustomPropertyMapper( mapping, requiresInclude, false, _nodeMapper, destinationProperty.GetPropertyInfo() ); _nodeMapper.InsertPropertyMapper(mapper); return(this); }