diff --git a/Test/BootstrapTest.cs b/Test/BootstrapTest.cs index 515de4eb6..51480e3dd 100644 --- a/Test/BootstrapTest.cs +++ b/Test/BootstrapTest.cs @@ -33,8 +33,9 @@ public void ClearBootstrap() private IConfigurationSource CreateBootstrap(string configFile) { var fileMap = new ExeConfigurationFileMap(); - fileMap.ExeConfigFilename = Path.Combine(@"Config", configFile); - + var filePath = Path.Combine(@"Config", configFile); + fileMap.ExeConfigFilename = filePath; + Setup.LoadConfigFileFromResource(filePath); var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var configSource = config.GetSection("superSocket") as IConfigurationSource; diff --git a/Test/Setup.cs b/Test/Setup.cs index f295538c0..33ee203b1 100644 --- a/Test/Setup.cs +++ b/Test/Setup.cs @@ -11,39 +11,23 @@ namespace SuperSocket.Test { - [SetUpFixture] - public class Setup + public static class Setup { - [SetUp] - public void RunBeforeAllTest() + public static void LoadConfigFileFromResource(string filePath) { - Console.WriteLine("RunBeforeAllTest"); - - //Extract all resource var currentAssembly = typeof(Setup).Assembly; - var assemblyName = currentAssembly.GetName().Name; - var names = currentAssembly.GetManifestResourceNames(); - - foreach (var name in names) + var resourceName = currentAssembly.GetName().Name + "." + filePath.Replace(Path.DirectorySeparatorChar, '.'); + using (var stream = currentAssembly.GetManifestResourceStream(resourceName)) { - var fileName = name.Substring(assemblyName.Length + 1); - var fileNameSegments = fileName.Split('.'); - var filePath = string.Join(Path.DirectorySeparatorChar.ToString(), fileNameSegments, 0, fileNameSegments.Length -1) + "." + fileNameSegments[fileNameSegments.Length - 1]; - - if(File.Exists(filePath)) - continue; - + var buffer = new byte[stream.Length]; + stream.Read(buffer, 0, buffer.Length); + var dir = Path.GetDirectoryName(filePath); if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) Directory.CreateDirectory(dir); - using(var stream = currentAssembly.GetManifestResourceStream(name)) - { - var buffer = new byte[stream.Length]; - stream.Read(buffer, 0, buffer.Length); - File.WriteAllBytes(filePath, buffer); - } + File.WriteAllBytes(filePath, buffer); } }