Skip to content

create map for all members

Bert Loedeman edited this page Aug 27, 2015 · 1 revision

#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);
Clone this wiki locally