-
Notifications
You must be signed in to change notification settings - Fork 36
create map for all members
#forAllMembers
The createMap.forAllMembers function specifies which action should be performed for any mapped property. The function call provides you with destinationObject
, destinationProperty
and value
. When specifying this function, notice that you yourself are responsible for setting the value on the destination object. The AutoMapper library assumes you are handling it.
The unit test sample below shows a basic sample to set all property values in the destination object.
// arrange
var objA = { prop1: 'From A', prop2: 'From A too' };
var fromKey = '{C4056539-FA86-4398-A10B-C41D3A791F26}';
var toKey = '{01C64E8D-CDB5-4307-9011-0C7F1E70D115}';
var forAllMembersSpy = jasmine.createSpy('forAllMembersSpy').and.callFake((destinationObject: any, destinationProperty: string, value: any) => {
destinationObject[destinationProperty] = value;
});
automapper
.createMap(fromKey, toKey)
.forAllMembers(forAllMembersSpy);
// act
var objB = automapper.map(fromKey, toKey, objA);
// assert
expect(forAllMembersSpy).toHaveBeenCalled();
expect(forAllMembersSpy.calls.count()).toBe(Object.keys(objB).length);
AutoMapperTS is Copyright © 2015 Bert Loedeman and other contributors under the MIT license.
Getting started
Mapping performance
Initialization (initialize)
Mapping configuration (createMap)
- forMember
- forSourceMember
- condition
- forAllMembers
- ignoreAllNonExisting
- convertToType
- convertUsing
- withProfile
Validation (assertConfigurationIsValid)
Mapping (map)
Currying
Custom type converters
Profiles
Chaining
Naming conventions
Asynchronous mapping
Flattening and nesting