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.
- there method openmappedexeconfiguration allow open non-default configuration file.
- you can add second configuration file project , use deploymentitem attribute automatically copy test directory.
Comments
Post a Comment