public void ServerProgramStopTest(string serverIp, int serverPort, int mlsOfDelay) { ServerProgram server = new ServerProgram(serverIp, serverPort, mlsOfDelay); server.Run(); Client client = new Client(new SocketSettings.SocketSettings(serverIp, serverPort, mlsOfDelay)); string result1 = ""; Task client1 = Task.Factory.StartNew(() => { result1 = client.Send("cc"); }); client1.Wait(1000); int mlsToStop = server.Stop(); Thread.Sleep(mlsOfDelay); string result2 = ""; Task client2 = Task.Factory.StartNew(() => { result2 = client.Send("cc"); }); client2.Wait(1000); Assert.AreEqual(mlsOfDelay, mlsToStop); Assert.AreEqual("cs", result1); Assert.AreEqual("", result2); }
public void TestInitialize() { server = new ServerProgram(settings); server.Run(); server.ExecuteCommand("rnu", new string[] { "Login", "Password", "Name" }); helper = new DBHelper(settings); DBHelper.Login = "******"; DBHelper.Password = "******"; }
public void TestInitialize() { settings = new SocketSettings.SocketSettings("192.168.0.107", 11223, 10000); server = new ServerProgram(settings); server.Run(); DBHelper helper = new DBHelper(settings); helper.Registration("Login", "Password", "Name"); DBHelper.Login = "******"; DBHelper.Password = "******"; }
public void ExecuteCommandTest(string ip, int port, int clientPort, string command, string[] args, string expectedResult) { ServerProgram server = new ServerProgram(ip, port, 100); server.Run(); try { string result = server.ExecuteCommand(command, args); Assert.AreEqual(expectedResult, result); } finally { Thread.Sleep(server.Stop()); } }
public void AutoTimingTest(string name, string text, string newName, string newText) { SocketSettings.SocketSettings settings = new SocketSettings.SocketSettings("192.168.0.107", 11221, 300); ServerProgram server = new ServerProgram(settings); server.Run(); server.ExecuteCommand("rnu", new string[] { "Login", "Password", "Name" }); DBHelper helper = new DBHelper(settings); DBHelper.Login = "******"; DBHelper.Password = "******"; Note note = new Note(name, text, true); Thread.Sleep(500); Assert.AreEqual(name, note.Name); Assert.AreEqual(text, note.Text); Assert.IsTrue(DBContext.Notes.Where(x => x.Id == note.Id).Count() == 1); ServerRealization.Database.Context.Note dbNote = DBContext.Notes.Where(x => x.Id == note.Id).First(); Assert.AreEqual(name, dbNote.Name); Assert.AreEqual(text, dbNote.Text); Assert.IsTrue(new TimeSpan(0, 0, 1) > (note.Created > dbNote.Created ? note.Created - dbNote.Created : dbNote.Created - note.Created)); Assert.IsTrue(new TimeSpan(0, 0, 1) > (note.LastChanged > dbNote.LastChanged ? note.LastChanged - dbNote.LastChanged : dbNote.LastChanged - note.LastChanged)); note.Name = newName; note.Text = newText; Thread.Sleep(7000); if (name != newName) { Assert.AreNotEqual(newName, dbNote.Name); } if (text != newText) { Assert.AreNotEqual(newText, dbNote.Text); } Thread.Sleep(3500); Assert.AreEqual(newName, dbNote.Name); Assert.AreEqual(newText, dbNote.Text); server.Stop(); Thread.Sleep(1000); }
public void ServerProgramRunTest(string serverIp, int serverPort) { ServerProgram server = new ServerProgram(serverIp, serverPort, 300); bool isAsync = false; Thread serverThread = new Thread(() => { server.Run(); isAsync = true; }); serverThread.Start(); Client client = new Client(new SocketSettings.SocketSettings(serverIp, serverPort, 300)); string result = ""; Thread clientThread = new Thread(() => { result = client.Send("cc"); }); clientThread.Start(); Thread.Sleep(1000); Assert.IsTrue(isAsync); Assert.AreEqual("cs", result); Thread.Sleep(server.Stop()); }