Question

I am creating a test project using IBM's Rational Functional Tester(RFT) tool(we are using the VB version of it and it only supports till .net 3.5).In this project I am making all database queries using the entity framework.The problem is entity framework retrieves "Metadata", "Connection String" etc from the App.Config file,and RFT won't let me add a App.Config to the project(I guess it is designed that way -- I googled adding an App.Config file to an rft project and came up with nothing), and the Entity Framework requires you to have the app.config file at the entry point.I was building the string to pass to entity framework in code, but my boss really does not like that. So looking at my options I think any of the below 2 solutions should suffice(or if you have a better solution please advise).

  1. Is their any way to load an App.Config during run-time.
  2. Is their any way to add an App.Config to an RFT project(should really be my first question).

If you guys could help me with this it will be great. Thanks in advance.

Était-ce utile?

La solution

After a lot of research i found you can load the config file at runtime by using,

      ExeConfigurationFileMap map = new ExeConfigurationFileMap();
      map.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Assembly.GetExecutingAssembly().ManifestModule.Name + ".config");
      Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
      var configValue = config.ConnectionStrings.ConnectionStrings["refrenceNameinConfigfile"].ConnectionString;

just make sure your App.config is within the folder where your exe file is running

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top