For unit tests I would like to mimic different commandline arguments. How do I modify the commandLine args to my program at runtime (looked around but can't find the trick)? Basically I am trying to find a way to modify the contents of the READONLY property Environment.CommandLine.
You can't, this is 'hard' read-only. It comes out of Windows, GetCommandLine API function, it doesn't allow modifying it either. You'll have to mock it.
It sounds to me as if you're trying to test things the hard way. Presumably somewhere you have a function that is reading directly from Environment.CommandLine. Refactor that method to take a string parameter (which in the real application will be populated from Environment.CommandLine), and test that method independently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With