Это может быть решение.
[Test]
public void TestForOutParameterInMoq()
{
//Arrange
_mockParameterManager= new Mock<IParameterManager>();
Mock<IParameter > mockParameter= new Mock<IParameter >();
//Parameter affectation should be useless but is not. It's really used by Moq
IParameter parameter= mockParameter.Object;
//Mock method used in UpperParameterManager
_mockParameterManager.Setup(x => x.OutMethod(out parameter));
//Act with the real instance
_UpperParameterManager.UpperOutMethod(out parameter);
//Assert that method used on the out parameter of inner out method are really called
mockParameter.Verify(x => x.FunctionCalledInOutMethodAfterInnerOutMethod(),Times.Once());
}
Вы можете выбрать более динамичный подход, сначала выбрав декартово произведение, а затем сопоставить объекты с требуемыми свойствами.
const
cartesian = (a, b) => a.reduce((r, v) => r.concat(b.map(w => [].concat(v, w))), []),
takeKeys = keys => a => Object.assign(...a.map((v, i) => ({ [keys[i]]: v })))
array1 = [1, 2, 3],
array2 = ['a', 'b', 'c'],
result = [array1, array2]
.reduce(cartesian)
.map(takeKeys(['el1', 'el2']));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Вы можете использовать Array.flatMap()
с Array.map()
:
const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const getCombinations = (a, b) =>
a.flatMap(el1 => b.map(el2 => ({ el1, el2 })));
const result = getCombinations(arr1, arr2);
console.log(result);