No, sorry for the confusion. I hadn't seen the edit Patrick made on Stack.
Thx for the help.

On Thu, Dec 23, 2010 at 1:18 PM, Tim Barcz <[email protected]> wrote:

> So is the only difference between what Patrick has on StackOverflow and
> what you need is randomness?
>
> If that's the case just assign a random number where Patrick is assigning
> "1".
>
> Failing that - I'm not sure I understand the difference.
>
> On Thu, Dec 23, 2010 at 2:46 AM, Lieven Cardoen 
> <[email protected]>wrote:
>
>> Maybe a small example can clarify what I need:
>>
>> Say there's a class with a method Save:
>>
>> public void Create(Entity entity)
>> {
>>     //entity is saved to database
>>     //entity.id is updated with the created id in database
>> }
>>
>> So, before the create, entity.id is -1, after the create it is > 0.
>>
>> Now, there's a service that uses this Create. Code contracts on this
>> service method say that before it is called, the entity must have an id
>> equal to -1, after it is called it must have an id > 0 (preconditions and
>> postconditions).
>>
>> So, what I need is something like this:
>> var entity = new Entity(); //id == -1
>> Expect.Call(() => _instance.Create(entity);
>> //Now the entity.id should be a random number > 0. This is what I need,
>> to have Rhino Mocks update the id of entity to a given integer. Is this
>> possible?
>>
>> Thx, Lieven Cardoen
>>
>> On Wed, Dec 22, 2010 at 11:04 PM, Lieven Cardoen <
>> [email protected]> wrote:
>>
>>> No, it isn't, but the answer on stackoverflow you gave isn't what I'm
>>> searching for.
>>>
>>>
>>> On Wed, Dec 22, 2010 at 8:43 PM, Patrick Steele <
>>> [email protected]> wrote:
>>>
>>>> Is this different than the StackOverflow question I answered?
>>>>
>>>>
>>>> http://stackoverflow.com/questions/4387299/set-a-property-of-an-object-in-a-expect-call
>>>>
>>>> ---
>>>> Patrick Steele
>>>> http://weblogs.asp.net/psteele
>>>>
>>>>
>>>>
>>>> On Wed, Dec 8, 2010 at 5:25 AM, LievenCardoen <[email protected]>
>>>> wrote:
>>>> > I have next code:
>>>> >
>>>> > var schedule = ScheduleUtil.CreateScheduleDto(user, user);
>>>> > Expect.Call(() => _scheduleRepository.Save(schedule));
>>>> >
>>>> > Now, what I need is that after the Save, the id of the schedule should
>>>> > be changed to a value bigger than 0. If it's created, it is -1.
>>>> >
>>>> > At the end of the test, _scheduleService.Create(schedule, channelId);
>>>> > is called. A precondition of code contracts is that the id of the
>>>> > schedule should be -1 at the beginning of the Save. A postcondition is
>>>> > that the id of the schedule should be bigger than 0 at the end of the
>>>> > Save.
>>>> >
>>>> > Is there a way to do this? To have not an Expect but to make a change
>>>> > in a certain object?
>>>> >
>>>> > Hard to explain.
>>>> >
>>>> > Full code:
>>>> >
>>>> > [Test]
>>>> > public void TestCreate()
>>>> > {
>>>> >    var channelId = RandomizeUtil.Next(10000);
>>>> >    var user = UserUtil.CreateRandomUserDto();
>>>> >    var schedule = ScheduleUtil.CreateScheduleDto(user, user);
>>>> >    Expect.Call(() => _scheduleRepository.Save(schedule));
>>>> >    foreach (var userDto in schedule.users)
>>>> >    {
>>>> >        Expect.Call(() => _scheduleRepository.AddUser(schedule.id,
>>>> > userDto.id));
>>>> >    }
>>>> >    foreach (var groupDto in schedule.groups)
>>>> >    {
>>>> >        Expect.Call(() => _scheduleRepository.AddGroup(schedule.id,
>>>> > groupDto.id));
>>>> >    }
>>>> >
>>>> >
>>>> Expect.Call(_managementConfigurator.RetrieveChannelManager(channelId)).Return(_channelManager);
>>>> >    Expect.Call(() => _channelManager.HandleNewSchedule(schedule.id));
>>>> >    _mocks.ReplayAll();
>>>> >    _scheduleService.Create(schedule, channelId);
>>>> >    schedule.id = 1; //Otherwise Contract Postcondition
>>>> > (scheduleDto.id > 0) fails
>>>> >    _mocks.VerifyAll();
>>>> > }
>>>> >
>>>> > --
>>>> > You received this message because you are subscribed to the Google
>>>> Groups "Rhino.Mocks" group.
>>>> > To post to this group, send email to [email protected].
>>>> > To unsubscribe from this group, send email to
>>>> [email protected]<rhinomocks%[email protected]>
>>>> .
>>>> > For more options, visit this group at
>>>> http://groups.google.com/group/rhinomocks?hl=en.
>>>> >
>>>> >
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Rhino.Mocks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<rhinomocks%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/rhinomocks?hl=en.
>>>>
>>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Rhino.Mocks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<rhinomocks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/rhinomocks?hl=en.
>>
>
>
>
> --
> Tim Barcz
> Microsoft C# MVP
> Microsoft ASPInsider
> http://timbarcz.devlicio.us
> http://www.twitter.com/timbarcz
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rhinomocks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rhinomocks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to