0
votes

I want to write a test to check some settings in my app config files are present.

How would i go about getting all of the app/web config files in the solution?

2
do u mean "how to access files of a specific directory?" - SHEKHAR SHETE
I want to write a test that ensures none of the app config files in my solution contain a particular setting. This should fail if i add another project to the solution and it does not contain that config - TJF

2 Answers

1
votes

By using directory searching you can get the files

  string[] configFiles = Directory.GetFiles( @"YourSolutonDirectoryLocation", "*.config", SearchOption.AllDirectories)
                               .Where(x => x.EndsWith("App.config") || x.EndsWith("Web.config")).ToArray();
1
votes

As far as i understand your post, Please use following to get all files in a directory

public string[] GetAllFilesInDirectory(string path, string startsWith, string fileExt)
    {
        string[] filenames = Directory.GetFiles(path, startsWith + "*" + fileExt);
        return filenames;

    }

Usage:

 string[] arr= GetAllFilesInDirectory(somepath,startswith,".config");

Hope this helps!