c# - ProtectSection force save -


how force following code hit test below?

if (!section.sectioninformation.isprotected) {      section.sectioninformation.protectsection(encryptionprovider); } 

the problem other tests call encrypt before test below, code never gets inside statement above.

so far force saving in test not seem anything.

[testcategory("integration"), testmethod] public void testprotectsectiononlyhappensonce() // integration test {     // arrange     iappconfigencryptor encryptor = new appconfigencryptor();     bool expected = false;     bool actual;      // act     try     {         configuration config = configurationmanager.openexeconfiguration(configurationuserlevel.none);         var section = config.getsection("appsettings");         section.sectioninformation.setrawxml("");         config.save(configurationsavemode.full, true);          encryptor.encrypt("appsettings", "dataprotectionconfigurationprovider");         encryptor.encrypt("appsettings", "dataprotectionconfigurationprovider");         actual = false;     }     catch (nullreferenceexception)     {         actual = true;     }      // assert     assert.areequal(expected, actual); } 

i use separate configuration file tests not interfere. tests independent.

  1. there method openmappedexeconfiguration allow open non-default configuration file.
  2. you can add second configuration file project , use deploymentitem attribute automatically copy test directory.

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -