11using System ;
22using System . Diagnostics ;
33using System . IO ;
4- using System . Reflection ;
54using System . Runtime . InteropServices ;
65using Newtonsoft . Json . Linq ;
76using NUnit . Framework ;
87using UnityEditor ;
9- using UnityEngine ;
10- using MCPForUnity . Editor . Data ;
8+ using MCPForUnity . Editor . Helpers ;
119using MCPForUnity . Editor . Models ;
12- using MCPForUnity . Editor . Windows ;
1310
14- namespace MCPForUnityTests . Editor . Windows
11+ namespace MCPForUnityTests . Editor . Helpers
1512{
1613 public class WriteToConfigTests
1714 {
@@ -68,7 +65,7 @@ public void TearDown()
6865 public void AddsEnvAndDisabledFalse_ForWindsurf ( )
6966 {
7067 var configPath = Path . Combine ( _tempRoot , "windsurf.json" ) ;
71- WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
68+ WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
7269
7370 var client = new McpClient { name = "Windsurf" , mcpType = McpTypes . Windsurf } ;
7471 InvokeWriteToConfig ( configPath , client ) ;
@@ -85,7 +82,7 @@ public void AddsEnvAndDisabledFalse_ForWindsurf()
8582 public void AddsEnvAndDisabledFalse_ForKiro ( )
8683 {
8784 var configPath = Path . Combine ( _tempRoot , "kiro.json" ) ;
88- WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
85+ WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
8986
9087 var client = new McpClient { name = "Kiro" , mcpType = McpTypes . Kiro } ;
9188 InvokeWriteToConfig ( configPath , client ) ;
@@ -102,7 +99,7 @@ public void AddsEnvAndDisabledFalse_ForKiro()
10299 public void DoesNotAddEnvOrDisabled_ForCursor ( )
103100 {
104101 var configPath = Path . Combine ( _tempRoot , "cursor.json" ) ;
105- WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
102+ WriteInitialConfig ( configPath , isVSCode : false , command : _fakeUvPath , directory : "/old/path" ) ;
106103
107104 var client = new McpClient { name = "Cursor" , mcpType = McpTypes . Cursor } ;
108105 InvokeWriteToConfig ( configPath , client ) ;
@@ -118,7 +115,7 @@ public void DoesNotAddEnvOrDisabled_ForCursor()
118115 public void DoesNotAddEnvOrDisabled_ForVSCode ( )
119116 {
120117 var configPath = Path . Combine ( _tempRoot , "vscode.json" ) ;
121- WriteInitialConfig ( configPath , isVSCode : true , command : _fakeUvPath , directory : "/old/path" ) ;
118+ WriteInitialConfig ( configPath , isVSCode : true , command : _fakeUvPath , directory : "/old/path" ) ;
122119
123120 var client = new McpClient { name = "VSCode" , mcpType = McpTypes . VSCode } ;
124121 InvokeWriteToConfig ( configPath , client ) ;
@@ -219,25 +216,15 @@ private static void WriteInitialConfig(string configPath, bool isVSCode, string
219216 File . WriteAllText ( configPath , root . ToString ( ) ) ;
220217 }
221218
222- private static MCPForUnityEditorWindow CreateWindow ( )
223- {
224- return ScriptableObject . CreateInstance < MCPForUnityEditorWindow > ( ) ;
225- }
226-
227219 private static void InvokeWriteToConfig ( string configPath , McpClient client )
228220 {
229- var window = CreateWindow ( ) ;
230- var mi = typeof ( MCPForUnityEditorWindow ) . GetMethod ( "WriteToConfig" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
231- Assert . NotNull ( mi , "Could not find WriteToConfig via reflection" ) ;
232-
233- // pythonDir is unused by WriteToConfig, but pass server src to keep it consistent
234- var result = ( string ) mi ! . Invoke ( window , new object [ ] {
235- /* pythonDir */ string . Empty ,
236- /* configPath */ configPath ,
237- /* mcpClient */ client
238- } ) ;
239-
240- Assert . AreEqual ( "Configured successfully" , result , "WriteToConfig should return success" ) ;
221+ var result = McpConfigurationHelper . WriteMcpConfiguration (
222+ pythonDir : string . Empty ,
223+ configPath : configPath ,
224+ mcpClient : client
225+ ) ;
226+
227+ Assert . AreEqual ( "Configured successfully" , result , "WriteMcpConfiguration should return success" ) ;
241228 }
242229 }
243230}
0 commit comments