public void SomeSeparatorsThreadingTest() { var someSeparators = new SomeSeparators("{{templKey:user}:'{templValue:user}',{templKey:pass}:'{templValue:pass}'}"); var threaadList = new List <Thread>(); bool someThreadHasError = false; for (int j = 0; j < 50; j++) { var thread = new Thread(() => { for (int i = 1; i < 10000 && !someThreadHasError; i++) { var rndStringUsr = Path.GetRandomFileName(); var rndStringPass = Path.GetRandomFileName(); var cleanRes = someSeparators.CleanString("{user:'******',pass:'******'}"); someThreadHasError = cleanRes.CleanString != "{user:'******',pass:'******'}" && !someThreadHasError; someThreadHasError = cleanRes.SecureData[0].Value != rndStringUsr && !someThreadHasError; someThreadHasError = cleanRes.SecureData[1].Value != rndStringPass && !someThreadHasError; } lock (threaadList) { threaadList.Remove(Thread.CurrentThread); } }); lock (threaadList) { threaadList.Add(thread); } thread.Start(); } int threadCount = threaadList.Count; while (threadCount != 0) { Thread.Sleep(100); lock (threaadList) { threadCount = threaadList.Count; } } Assert.AreEqual(threadCount, 0); Assert.AreEqual(someThreadHasError, false); }
public void SomeSeparatorsTest() { var someSeparate = new SomeSeparators("{{templKey:user}:'{templValue:user}',{templKey:pass}:'{templValue:pass}'}"); for (int i = 1; i < 100000; i++) { var rndStringUsr = Path.GetRandomFileName(); var rndStringPass = Path.GetRandomFileName(); var cleanRes = someSeparate.CleanString("{user :'******', pass:'******'}"); Assert.AreEqual(cleanRes.CleanString, "{user :'******', pass:'******'}"); Assert.AreEqual(cleanRes.SecureData[0].Value, rndStringUsr); Assert.AreEqual(cleanRes.SecureData[1].Value, rndStringPass); } someSeparate = new SomeSeparators("http://test.com/users/{templValue:user}/info"); for (int i = 1; i < 100; i++) { var rndStringUsr = Path.GetRandomFileName(); var cleanRes = someSeparate.CleanString("http://test.com/users/" + rndStringUsr + "/info"); Assert.AreEqual(cleanRes.CleanString, "http://test.com/users/" + new String(someSeparate.Replacement, rndStringUsr.Length) + "/info"); Assert.AreEqual(cleanRes.SecureData[0].Value, rndStringUsr); } someSeparate = new SomeSeparators("<auth><user>{templValue:user}</user><pass>{templValue:pass}</pass></auth>"); for (int i = 1; i < 100; i++) { var rndStringUsr = Path.GetRandomFileName(); var rndStringPass = Path.GetRandomFileName(); var cleanRes = someSeparate.CleanString("<auth><user>" + rndStringUsr + "</user><pass>" + rndStringPass + "</pass></auth>"); Assert.AreEqual(cleanRes.CleanString, "<auth><user>" + new String(someSeparate.Replacement, rndStringUsr.Length) + "</user><pass>" + new String(someSeparate.Replacement, rndStringUsr.Length) + "</pass></auth>"); Assert.AreEqual(cleanRes.SecureData[0].Value, rndStringUsr); } }