The most of applications, especially big and complex ones, need for a kind of variables which must be visible and available all over the application. Sometimes you have to pass data from one module to another, between assemblies, classes, methods, etc. There are different approaches in C# for resolving the problem, and one of them is the use of static variables and methods. In accordance with OOP principles, there are mustn’t be any possibility to create a global variable using object-oriented programming language. And there is no such possibility in C#. Instead, static variables are used.
In the given framework I use the same variables both in the Mapping and the Tests modules. I’m going to initialize variables in my tests but to use them in the Mapping project passing values of variables there.
For the implementation, I added a new static class to my Extensions.cs file and named it Globals. The class is used for storing those static variables which must be used simultaneously in the Mapping and the Tests modules. Sure, you can keep your static members wherever you wish and it’s not mandatory to have a separate class for your “global” statics. But I think it’s better to have all the mess being collected in one place with user-friendly names.
I added class Globals and put these members into it:
Initial values of these variables are kept in App.config file in the Tests project. The method which sets the values will be placed in Extensions class in the Mapping project. It is invoked in BaseTest class in the Tests project. Then the initialized variables are used in the Mapping project and may be used in the tests as well. This is the way how data may be passed from one module to another and between classes and instances inside a module.
The method for static global variables initialization (to avoid errors you have to add reference to System.Configuration library in the Mapping project):
Usage of the method (don’t forget to rebuild Mapping project before):