In my MVC application i am using different .resx files for different languages. I would like to write a unit test to check if all the resource files has got the same keys. I am using NUnit to test this. Thanks Ela
It is quite easy in yur unit test...you don't need to create any class since everything is done with static methods.
You just set manually your Thread UI culture to the neutral one (en-us) and read the list of all static property names.
Then you do a loop on all supported culture, where first set the thread UI culture to the current loop culture, and then you read all property values. In case some value is wrong in a culture you will get either an exception or a empty/null value. This is
your error condition.
I have no sample code for this because I have never written a test for resource files. The reason is simple when you translate a resource file into another language, the error that is more likey to occurr is not that a key is forgotten but that the translator
put the message in the wrong key, that is that the messages are misplaced. The only way to dicover this error is through a manual test performed by someone that undertsnd the translated language.
Thus you have just to prepare a doicument with all steps an user must perform to show all messages and then to verify if each message appear in the right place.
evanmaran
Member
28 Points
38 Posts
MVC NUnit test to check all the resource file has got same keys
Jun 24, 2011 01:13 PM|LINK
francesco ab...
All-Star
20910 Points
3278 Posts
Re: MVC NUnit test to check all the resource file has got same keys
Jun 24, 2011 03:24 PM|LINK
It is quite easy in yur unit test...you don't need to create any class since everything is done with static methods.
You just set manually your Thread UI culture to the neutral one (en-us) and read the list of all static property names.
Then you do a loop on all supported culture, where first set the thread UI culture to the current loop culture, and then you read all property values. In case some value is wrong in a culture you will get either an exception or a empty/null value. This is your error condition.
Mvc Controls Toolkit | Data Moving Plug-in Videos
evanmaran
Member
28 Points
38 Posts
Re: MVC NUnit test to check all the resource file has got same keys
Jun 27, 2011 08:48 AM|LINK
francesco ab...
All-Star
20910 Points
3278 Posts
Re: MVC NUnit test to check all the resource file has got same keys
Jun 28, 2011 01:57 PM|LINK
I have no sample code for this because I have never written a test for resource files. The reason is simple when you translate a resource file into another language, the error that is more likey to occurr is not that a key is forgotten but that the translator put the message in the wrong key, that is that the messages are misplaced. The only way to dicover this error is through a manual test performed by someone that undertsnd the translated language.
Thus you have just to prepare a doicument with all steps an user must perform to show all messages and then to verify if each message appear in the right place.
Mvc Controls Toolkit | Data Moving Plug-in Videos