public void SaveAndLoadTest() { List <string> list = new List <string>(); list.Add("qwerty"); list.Add("asdfgh"); list.Add("zxcvbn"); string path = "trueXmlSerializerTest.xml"; TrueXmlSerializer.Save(list, path); List <string> list2 = TrueXmlSerializer.Load <List <string> >(path); CollectionAssert.AreEqual(list, list2); }
private void AddTest(TcpClient tcpClient, TrueMessage trueMessage) { Console.WriteLine($"AddTest"); SqlConnection sqlConnection = new SqlConnection(connectionString); try { if (sqlConnection.State == ConnectionState.Closed) { sqlConnection.Open(); } TestDLL.Test test = (TestDLL.Test)trueMessage.Message; string path = test.Name; string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { path = path.Replace(c.ToString(), ""); } path = "..\\..\\..\\Tests\\" + path + ".xml"; TrueMessage trueMessageToClient = new TrueMessage(); Random random = new Random(); while (File.Exists(path)) { path += random.Next(1, 100); } TrueXmlSerializer.Save(test, path); SqlCommand sqlCommand = new SqlCommand("Proc_AddTest", sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@Name", test.Name); sqlCommand.Parameters.AddWithValue("@Description", test.Description); sqlCommand.Parameters.AddWithValue("@Path", path); sqlCommand.ExecuteNonQuery(); trueMessageToClient.Command = Command.Approve; trueMessageToClient.Message = test.Name; byte[] dataAddTestAnswer; IFormatter formatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, trueMessageToClient); dataAddTestAnswer = stream.ToArray(); } NetworkStream networkStream = tcpClient.GetStream(); networkStream.BeginWrite(dataAddTestAnswer, 0, dataAddTestAnswer.Length, new AsyncCallback(AddTestAnswer), tcpClient); Console.WriteLine($"AddTest ended"); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (sqlConnection.State != ConnectionState.Closed) { sqlConnection.Close(); } } }