Skip to content

Commit

Permalink
ModelMapper: Added Customize_TypeMapping test #542
Browse files Browse the repository at this point in the history
  • Loading branch information
apobekiaris committed Oct 7, 2019
1 parent 4f35c40 commit 686c162
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Modules/ModelMapper/Readme.md
Expand Up @@ -164,7 +164,7 @@ DashboardView | ListView | DetailView
---------|----------|---------
![image](https://user-images.githubusercontent.com/159464/61752712-73808880-adb5-11e9-897e-081e8864882f.png)|![image](https://user-images.githubusercontent.com/159464/61752825-ec7fe000-adb5-11e9-8217-2e125f992319.png)|![image](https://user-images.githubusercontent.com/159464/61752720-7f6c4a80-adb5-11e9-832e-931a23b8a159.png)

##### How to customize a map
##### <u>How to customize a map</u>
You can customize the map the following ways:
1. On declaration using the ModelMapperConfiguration properties.
```cs
Expand Down Expand Up @@ -192,7 +192,7 @@ You can customize the map the following ways:
}));
```
Several real world examples are available at [Predefined](https://github.com/eXpandFramework/DevExpress.XAF/tree/master/src/Modules/ModelMapper/Services/Predefined) namespace.
##### How to bind a map
##### <u>How to bind a map</u>

All predefined maps are bound to the runtime instance automatically. The module when any view controls are created will search its model for IModelModelMap properties and use them to configure the related instances. It is possible to customize the process as in next snippet:

Expand Down
20 changes: 20 additions & 0 deletions src/Tests/ModelMapper/TypeMappingServiceTests/MapTests.cs
Expand Up @@ -404,6 +404,26 @@ public class MapTests:ModelMapperBaseTest{
modelNames.ShouldContain(types.Last().Name);

}

[Test]
public void Customize_TypeMapping(){
InitializeMapperService($"{nameof(Customize_TypeMapping)}",Platform.Win);
TypeMappingService.PropertyMappingRules.Add(("RemoveTreeListMap", _ => {
if (_.declaringType == PredefinedMap.TreeList.TypeToMap()){
_.propertyInfos.Clear();
}
}));

var modelInterfaces = new[]{PredefinedMap.GridView,PredefinedMap.TreeList}.MapToModel().ModelInterfaces().Replay();
modelInterfaces.Connect();

var types = modelInterfaces.ToEnumerable().ToArray();
types.Length.ShouldBe(2);
types.Last().GetProperties()
.FirstOrDefault(info => !TypeMappingService.ReservedPropertyNames.Contains(info.Name)&&info.Name!=TypeMappingService.ModelMappersNodeName)
.ShouldBeNull();

}
}


Expand Down

0 comments on commit 686c162

Please sign in to comment.