Set the property of an object to Expect.Call

It's hard to explain what I'm looking for, but my example should clarify it.

I have the following code:

var schedule = ScheduleUtil.CreateScheduleDto(user, user);
Expect.Call(() => _scheduleRepository.Save(schedule));

Now, what I want to do is when this Save call is made, the schedule.id property must be set to a different value (for example, 1).

I do not want to scoff at the schedule. It can be done? The Save method does not return a value, so this is not an option, but I need to change the schedule of the object.

UPDATE: Maybe a small example will explain what I definitely want.

Say the class using the Save method:

public void Create (Entity entity) {// the object is stored in the database //entity.id is updated with the created identifier in the database}

So, before creating, entity.id is -1, after creating it is> 0.

, Create. , , -1, p > 0 ( ).

, - : var entity = new Entity();//id == -1 Expect.Call(() = > _instance.Create(entity);
// entity.id > 0. , , Rhino Mocks . ?

+3
1

. _scheduleRepository, Rhino Mocks . _scheduleRepository?

EDIT: , , . "WhenCalled" , , Rhino.Mocks . - :

_scheduleRepository.Expect(s => s.Save(schedule)).WhenCalled(a => ((Schedule) a.Arguments[0]).Id = 1);
+3

Source: https://habr.com/ru/post/1779168/


All Articles