public void TestMethod_TestUdpTarget() { index = 0; byte bufferLimit = 5; int logsCount = 100; TestUdpServer udpServer = new TestUdpServer("127.0.0.1", 9000); LoggerTargetUdp targetUdp = new LoggerTargetUdp("127.0.0.1", 9000, "127.0.0.1", 10000); StringBuilder stringBuilder = new StringBuilder(); ILoggerTarget[] logTarget = new ILoggerTarget[] { targetUdp }; udpServer.StartReceive(); Logger logger = new Logger(bufferLimit, logTarget); Task.Run(() => { logger.ProcessingQueue(); }); for (int i = 0; i < logsCount; i++) { string a = "task " + i; Task.Run(() => { logger.Log(LogLevel.Info, a); index++; }); } while (index != logsCount) { if (index == logsCount) { logger.FlushReamainLogs(); for (int i = 0; i < logsCount; i++) { stringBuilder.Append(i); } udpServer.Synchronize(); udpServer.Close(); CollectionAssert.AreEqual(Encoding.Default.GetBytes(stringBuilder.ToString()), udpServer.GetMessage()); } } }
public void TestMethod_TestUdpTarget() { int bufferLimit = 5, logsCount = 100; TestUdpServer udpServer = new TestUdpServer("127.0.0.1", 9000); LoggerTargetUdp targetUdp = new LoggerTargetUdp("127.0.0.1", 9000, "127.0.0.1", 10000); StringBuilder stringBuilder = new StringBuilder(); ILoggerTarget[] logTarget = new ILoggerTarget[] { targetUdp }; udpServer.StartReceive(); var logsCreator = new LogsCreator(new Logger(bufferLimit, logTarget)); logsCreator.CreateLogs(logsCount, LogLevel.Debug); for (int i = 0; i < logsCount; i++) { stringBuilder.Append(i); } udpServer.Synchronize(); udpServer.Close(); CollectionAssert.AreEqual(Encoding.Default.GetBytes(stringBuilder.ToString()), udpServer.GetMessage()); }