public void MapToDto_ValidMetadata_Succeeds() { const string propertyWithMetadata = "PatientAddressType"; Mapper.CreateMap<PatientAddress, PatientAddressDtoTest> (); Mapper.CreateMap<IMetadataItem, IMetadataItemDto>() .Include<ReadonlyMetadataItem, ReadonlyMetadataItemDto>() .Include<RequiredMetadataItem, RequiredMetadataItemDto>() .Include<HiddenMetadataItem, HiddenMetadataItemDto>() .Include<DisplayNameMetadataItem, DisplayNameMetadataItemDto>(); var metaDataRepository = new Mock<IMetadataRepository> (); var metaDataRoot = new MetadataRoot ( typeof( PatientAddress ).FullName, 1 ); metaDataRoot.AddChild ( propertyWithMetadata ); metaDataRoot.Children[0].MetadataItems.Add ( new DisplayNameMetadataItem () ); metaDataRepository.Setup ( m => m.GetMetadata ( typeof( PatientAddress ).FullName ) ).Returns ( metaDataRoot ); var metadataMapper = new MetadataMapper ( metaDataRepository.Object ); var metaDataDto = new MetadataDto ( typeof( PatientAddressDtoTest ).FullName ); metadataMapper.MapToDto ( typeof(PatientAddress), typeof(PatientAddressDtoTest), metaDataDto ); Assert.AreEqual ( 1, metaDataDto.Children.Count); Assert.AreEqual(1, metaDataDto.Children[0].MetadataItemDtos.Count); Assert.AreEqual ( typeof(DisplayNameMetadataItemDto), metaDataDto.Children[0].MetadataItemDtos[0].GetType () ); }
public void MapToDto_NullEntityType_ThrowsArgumentException() { var metaDataRepository = new Mock<IMetadataRepository>(); var metadataMapper = new MetadataMapper(metaDataRepository.Object); var metaDataDto = new MetadataDto(typeof(PatientAddressDtoTest).FullName); metadataMapper.MapToDto(null, typeof(PatientAddressDtoTest), metaDataDto); }
/// <summary> /// Maps Metadata to dto metadata. /// </summary> /// <param name="entityType"> /// Type of the entity. /// </param> /// <param name="dtoType"> /// Type of the dto. /// </param> /// <param name="dtoMetadata"> /// The dto metadata to map to. /// </param> public void MapToDto( Type entityType, Type dtoType, MetadataDto dtoMetadata ) { Check.IsNotNull ( entityType, "entityType is required." ); Check.IsNotNull ( dtoType, "dtoType is required." ); Check.IsNotNull ( dtoMetadata, "dtoMetadata is required." ); var metaData = _metadataRepository.GetMetadata ( entityType.FullName ); if ( metaData != null ) { MapRecursive ( metaData, entityType, dtoType, dtoMetadata ); } }
/// <summary> /// Adds the child metadata. /// </summary> /// <param name="resourceName">Name of the resource.</param> /// <returns>A <see cref="Pillar.Common.Metadata.Dtos.MetadataDto"/></returns> public MetadataDto AddChildMetadata(string resourceName) { if (string.IsNullOrWhiteSpace(resourceName)) { throw new ArgumentNullException("resourceName"); } if (ChildMetadataExists(resourceName)) { throw new ArgumentException(string.Format("Child {0} already exists.", resourceName)); } var child = new MetadataDto(resourceName); _children.Add(child); return(child); }
private void InitializeDefaultMetadata() { _defaultMetadata = GetMetadataForSelectedResource ( _metadataService.GetMetadata ( _metadataProvider.GetType () ) ); if ( _defaultMetadata == null ) { _defaultMetadata = new MetadataDto ( string.Empty ); } }
private void InitializeCustomizedMetadata() { // Case 1: _metadataProvider.MetadataDto is null // Case 2: Child is not found // Case 3: _metadataProvider.MetadataDto is changed // Case 4: Child is replaced or removed if ( _customizedMetadata != null ) { var customizedMetadataItemsCollection = _customizedMetadata.MetadataItemDtos as INotifyCollectionChanged; customizedMetadataItemsCollection.CollectionChanged -= MetadataItemDtosCollectionChanged; } if ( _metadataProvider.MetadataDto != null ) { var metadataChildrenCollection = _metadataProvider.MetadataDto.Children as INotifyCollectionChanged; metadataChildrenCollection.CollectionChanged -= MetadataChildrenCollectionChanged; } _customizedMetadata = null; _customizedMetadata = GetMetadataForSelectedResource ( _metadataProvider.MetadataDto ); if ( _customizedMetadata != null ) { var customizedMetadataItemsCollection = _customizedMetadata.MetadataItemDtos as INotifyCollectionChanged; customizedMetadataItemsCollection.CollectionChanged += MetadataItemDtosCollectionChanged; } if ( _metadataProvider.MetadataDto != null ) { var metadataChildrenCollection = _metadataProvider.MetadataDto.Children as INotifyCollectionChanged; metadataChildrenCollection.CollectionChanged += MetadataChildrenCollectionChanged; } }
private MetadataDto GetMetadataForSelectedResource( MetadataDto metadataDto ) { // Initially, assume that we are selecting the base metadata object var metadataForSelectedResource = metadataDto; // however, if the ChildMetaDataName property is set then it means we want // a metadata child. if ( metadataDto != null && !string.IsNullOrWhiteSpace ( _childMetadataName ) ) { metadataForSelectedResource = metadataDto.Children.FirstOrDefault ( m => m.ResourceName == _childMetadataName ); } return metadataForSelectedResource; }
public void MetadataDto_SetWithSameMetadataDto_NotFirePropertyChangedEvent() { bool isPropertyChangedEventFired = false; var metadataDto = new MetadataDto("Default"); var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; personDto.MetadataDto = metadataDto; personDto.PropertyChanged += (sender, e) => { isPropertyChangedEventFired = true; }; personDto.MetadataDto = metadataDto; Assert.IsFalse(isPropertyChangedEventFired); }
private static void MapRecursive( IMetadata metadata, Type entityType, Type dtoType, MetadataDto dtoMetadata ) { dtoMetadata.AddMetadataItemRange ( MapMetadataItems ( metadata.MetadataItems ) ); foreach ( var propertyInfo in entityType.GetProperties () ) { if ( ( typeof( IAggregateRoot ).IsAssignableFrom ( propertyInfo.PropertyType ) || typeof( IAggregateRoot ).IsAssignableFrom ( propertyInfo.PropertyType ) ) && metadata.HasChild ( propertyInfo.PropertyType.FullName ) ) { var dtoPropertyName = TryFindDestinationPropertyName ( entityType, dtoType, propertyInfo ); if ( dtoPropertyName == null ) { continue; } var dtoPropertyInfo = dtoType.GetProperty ( dtoPropertyName ); if ( typeof( IDataTransferObject ).IsAssignableFrom ( dtoPropertyInfo.PropertyType ) ) { MapRecursive ( metadata.FindChildMetadata ( propertyInfo.PropertyType.FullName ), propertyInfo.PropertyType, dtoPropertyInfo.PropertyType, dtoMetadata.GetChildMetadata ( dtoPropertyInfo.PropertyType.FullName ) ); } else { var subDtoPropertyMetadata = dtoMetadata.GetChildMetadata ( dtoPropertyInfo.Name ); var subPropertyMetadata = metadata.FindChildMetadata ( propertyInfo.PropertyType.FullName ); subDtoPropertyMetadata.AddMetadataItemRange ( MapMetadataItems ( subPropertyMetadata.MetadataItems ) ); } } else if ( metadata.HasChild ( propertyInfo.Name ) ) { var dtoPropertyName = PropertyNameMapper.GetDistinctDestinationPropertyName ( entityType, dtoType, propertyInfo.Name ); if ( dtoPropertyName == null ) { continue; } var subDtoPropertyMetadata = dtoMetadata.GetChildMetadata ( dtoPropertyName ); var subPropertyMetadata = metadata.FindChildMetadata ( propertyInfo.Name ); subDtoPropertyMetadata.AddMetadataItemRange ( MapMetadataItems ( subPropertyMetadata.MetadataItems ) ); } } }
private MetadataDto CreateNewCustomizedMetadataDto() { var metadataDto = new MetadataDto("Rem.Ria.PatientModule.Web.Common.PatientProfileDto"); var lastNameNode = metadataDto.AddChildMetadata("LastName"); lastNameNode.AddMetadataItem(new RequiredMetadataItemDto { IsRequired = true }); lastNameNode.AddMetadataItem ( new HiddenMetadataItemDto { IsHidden = false } ); return metadataDto; }
private MetadataDto CreateDefaultMetadataDto() { var metadataDto = new MetadataDto("Rem.Ria.PatientModule.Web.Common.PatientProfileDto"); var firstNameNode = metadataDto.AddChildMetadata("FirstName"); firstNameNode.AddMetadataItem ( new DisplayNameMetadataItemDto { Name = "The Patient's First Name" } ); firstNameNode.AddMetadataItem ( new ReadonlyMetadataItemDto { IsReadonly = true } ); var middleNameNode = metadataDto.AddChildMetadata("MiddleName"); middleNameNode.AddMetadataItem ( new RequiredMetadataItemDto { IsRequired = true } ); var lastNameNode = metadataDto.AddChildMetadata("LastName"); lastNameNode.AddMetadataItem ( new DisplayNameMetadataItemDto { Name = "Default LastName" } ); lastNameNode.AddMetadataItem ( new HiddenMetadataItemDto { IsHidden = true } ); return metadataDto; }