public async Task ForbidUseAndSaveOfDefaultConfigFile() { await Task.Delay(500); ServerSettings serverSettingsOne = ServerSettings.LoadFromFile <ServerSettings>(SDaysToDiePath + SEP + "serverconfig.xml"); try { serverSettingsOne.SaveToFile(SDaysToDiePath + SEP + serverSettingsOne.ServerConfigFilepath); Assert.Fail("Expected 'File is not allowed to be saved as 'serverconfig.xml'' Exception!"); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("File is not allowed to be saved as 'serverconfig.xml'")); } try { SDaysTDieServer sDaysTDieServerOne = new SDaysTDieServer(SDaysToDiePath, serverSettingsOne); Assert.Fail("serverSettings.ServerConfigFilePath.EndsWith('serverconfig.xml')! Use of Default File is not allowed!"); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("serverSettings.ServerConfigFilePath.EndsWith('serverconfig.xml')! Use of Default File is not allowed!")); } }
public async Task StartAndShutdownServer() { bool serverStopped = false; Console.WriteLine("*** Starting ***"); ServerSettings serverSettings = ServerSettings.LoadFromFile <ServerSettings>(SDaysToDiePath + SEP + "serverconfig.xml"); serverSettings.ServerConfigFilepath = "StartAndShutdownServer.xml"; serverSettings.SaveToFile(SDaysToDiePath + SEP + serverSettings.ServerConfigFilepath); SDaysTDieServer sDaysTDieServer = new SDaysTDieServer(SDaysToDiePath, serverSettings); void SDaysTDieServer_OnSDaysTDieServerStoppedHandler(SDaysTDieServer sender, SDaysTDieServer.OnSDaysTDieServerStoppedEventArgs e) { serverStopped = true; } sDaysTDieServer.OnSDaysTDieServerStoppedHandler += SDaysTDieServer_OnSDaysTDieServerStoppedHandler; sDaysTDieServer.Start(); await Task.Delay(10000); sDaysTDieServer.Stop(); await Task.Delay(10000); Assert.AreEqual(true, serverStopped); }
public async Task InvalidConfigFile() { await Task.Delay(500); ServerSettings serverSettingsOne = ServerSettings.LoadFromFile <ServerSettings>(SDaysToDiePath + SEP + "serverconfig.xml"); serverSettingsOne.ServerConfigFilepath = "serverconfigFileNotFound.xml"; SDaysTDieServer sDaysTDieServerOne = new SDaysTDieServer(SDaysToDiePath, serverSettingsOne); try { sDaysTDieServerOne.Start(); Assert.Fail("Expected 'Config file not found' Exception!"); } catch (FileNotFoundException ex) { Assert.IsTrue(ex.Message.Contains("Config file not found at")); } }
public async Task FastStartAndShutdownServerModdedConfig() { bool serverStoppedNormally = false; Console.WriteLine("*** Starting ***"); ServerSettings serverSettings = ServerSettings.LoadFromFile <ServerSettings>(SDaysToDiePath + SEP + "serverconfig.xml"); serverSettings.ServerPort = 26901; serverSettings.TelnetPort = 8082; serverSettings.TelnetPassword = "******"; serverSettings.ServerConfigFilepath = "serverconfigModded.xml"; serverSettings.SaveToFile(SDaysToDiePath + SEP + serverSettings.ServerConfigFilepath); SDaysTDieServer sDaysTDieServer = new SDaysTDieServer(SDaysToDiePath, serverSettings); void SDaysTDieServer_OnSDaysTDieServerStoppedHandler(SDaysTDieServer sender, SDaysTDieServer.OnSDaysTDieServerStoppedEventArgs e) { if (e.Message == "*** Shutdown successful ***") { serverStoppedNormally = true; } } sDaysTDieServer.OnSDaysTDieServerStoppedHandler += SDaysTDieServer_OnSDaysTDieServerStoppedHandler; sDaysTDieServer.Start(); sDaysTDieServer.Stop(); async Task CheckServerStopped() { while (true) { if (serverStoppedNormally) { return; } await Task.Delay(1000); } } await CheckServerStopped(); }