chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

Instead of writing

            var serialNoRow = Isolate.Fake.Instance<Elite_Lock_Record>();
            Isolate.WhenCalled(()=>serialNoRow.IncarnationID_UID).WillReturn(100);
            Isolate.WhenCalled(()=>serialNoRow.LockType).WillReturn(lockType);
            Isolate.WhenCalled(()=>serialNoRow.CodePractice).WillReturn(codePractice);
            Isolate.WhenCalled(()=>serialNoRow.Software).WillReturn(software);
            Isolate.WhenCalled(()=>serialNoRow.RunningNumber).WillReturn(runningNumber);


I want to be able to write

Isolate.WhenCalled(()=>serialNoRow).SetProperty(
{
   IncarnationID_UID=100,
  LockType= lockType,
  CodePractice= codePractice
..
});


The idea is to reduce the time I type Isolate.WhenCall, WillReturn etc.

Not sure whether this is possible or not
 

asked by nsoonhui (59.1k points)
edited by Bar

4 Answers

0 votes
Hi Soon Hui,

Nice idea, like property initializers in C#.
I don't think this will work, because of the compiler, but we can get to a syntax that will.

Do you find you need this often?

Thanks,
answered by gilz (14.5k points)
0 votes
With the latest version this can be done using True Properties

var fakesRow = Isolate.Fake.Instance<Elite_Lock_Record>();
fakesRow.IncarnationID_UID = 100;
fakesRow.LockType = lockType;
fakesRow.CodePractice = codePractice;
fakesRow.Software = software;
fakesRow.RunningNumber = runningNumber; 
answered by eli (5.7k points)
0 votes
Hi Soon Hui,

Nice idea, like property initializers in C#.
I don't think this will work, because of the compiler, but we can get to a syntax that will.

Do you find you need this often?

Thanks,


Yes, quite often.

In my application I often have to mock the data inside a [url=msdn.microsoft.com/en-us/library/system.data.datatable.aspx]datatable[/url] just to simulate the data access layer. So if I have 5 columns, I need to repeat all those statements 5 times. [/quote]
 

answered by nsoonhui (59.1k points)
edited by Bar
0 votes
With the latest version this can be done using True Properties

var fakesRow = Isolate.Fake.Instance<Elite_Lock_Record>();
fakesRow.IncarnationID_UID = 100;
fakesRow.LockType = lockType;
fakesRow.CodePractice = codePractice;
fakesRow.Software = software;
fakesRow.RunningNumber = runningNumber; 


Good idea, but I afraid fakesRow.IncarnationID_UID = 100; might not work if IncarnatioID_UID is a get only properties... any idea to get around this?
 

answered by nsoonhui (59.1k points)
edited by Bar
...