Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET UnitTesting , +
Hi,
In order to remove external dependency for testing purpose i was trying to implement the mole framework
 
everything was working fine until i have moled the class with static readonly property.
 
Creating mole of that class is not the root cause of issue but that readonly property is creating the issue
 
in my actual method that readonly property is used and value of that property is coming null after creating mole instance
since there is not setter, getter for this property so mole class is not giving override for this property
 
However without mole testcase is not giving error and fetching the data from external sources
 
Please suggest how to proceed in this case
 
Thanks in advance
Posted 1-Jan-13 21:21pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could try using the MolesEraseStaticConstructor.
More about it here - http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf[^].
  Permalink  
Comments
Vijay_Gurunanee at 30-Mar-13 8:35am
   
Sorry Friend for delay in reply!!!
but it is not helping me!!!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Sorry for late reply...
 
but not working for me....
I just re factored the code and changed my code such that it can be moled.
 
But still i didn't find proper solution for this problem...
 
Thanks...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I have gone for many articles and discussions but did not found any perfect solutions.
So for now considering that it is not possible to override the private read only static properties of a sealed class. (Yes in my case, class sealed...)
 
So i have decided to change the design of class and then pain was gone.
 
Thanks for your help.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 115
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100