<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>NUnit</title>
        <link>http://www.codeofrob.com/category/6.aspx</link>
        <description>Everybody knows what NUnit is</description>
        <language>en-GB</language>
        <copyright>Rob Ashton</copyright>
        <generator>Subtext Version 2.1.2.2</generator>
        <item>
            <title>NUnit 2.5.3 and [SetUICulture]</title>
            <link>http://codeofrob.com/archive/2009/12/18/nunit-2.5.3-and-setuiculture.aspx</link>
            <description>&lt;p&gt;I can't for the life of me get this to work, and [SetCulture] appears to be working fine - so I can only assume it's a bug.&lt;/p&gt;
&lt;p&gt;I've posted to the mailing list and started off the process of working out whether it is a bug or not, but for now - I need to have my tests running  in the right culture, without any side effects on the other tests once a test has been complete.&lt;/p&gt;
&lt;p&gt;Here is my hack to do that:&lt;/p&gt;
&lt;pre class="brush: csharp;" title="code"&gt;   public class CultureContext : IDisposable
    {
        private CultureInfo mOldCulture;

        public CultureContext(String cultureName)
        {
            mOldCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);
        }

        public void Dispose()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = mOldCulture;
        }
    }&lt;/pre&gt;
&lt;p&gt;The usage is as follows, within a test do:&lt;/p&gt;
&lt;pre class="brush: csharp;" title="code"&gt;using (new CultureContext("fr-FR"))
{
	// Test code here
}&lt;/pre&gt;
&lt;p&gt;This will ensure that your test runs with the ui culture of "fr-FR", before resetting it to whatever it was before the test began. Not pretty, but it'll do until I work out if it's user error or a bug preventing NUnit from doing what I want it to do!&lt;/p&gt;&lt;img src="http://codeofrob.com/aggbug/6.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rob Ashton</dc:creator>
            <guid>http://codeofrob.com/archive/2009/12/18/nunit-2.5.3-and-setuiculture.aspx</guid>
            <pubDate>Fri, 18 Dec 2009 14:28:11 GMT</pubDate>
            <wfw:comment>http://codeofrob.com/comments/6.aspx</wfw:comment>
            <comments>http://codeofrob.com/archive/2009/12/18/nunit-2.5.3-and-setuiculture.aspx#feedback</comments>
            <wfw:commentRss>http://codeofrob.com/comments/commentRss/6.aspx</wfw:commentRss>
            <trackback:ping>http://codeofrob.com/services/trackbacks/6.aspx</trackback:ping>
        </item>
    </channel>
</rss>