public void TestWithExceptions() { var test = new SpeedWatchTest("Simple Test", () => SampleActions.ThrowOnEven(2), 2, ""); var result = test.GetSummary(); Assert.IsNotNull(result); Assert.IsTrue(result.TestResults.Count == 2); Assert.IsTrue(result.PassedTests == 0); Assert.IsTrue(result.FailedTests == 2); Trace.WriteLine(test.GetSummary().ToString()); }
public void TestWithNoExceptionsSummary() { var test = new SpeedWatchTest("Simple Test", SampleActions.WaitTwoSeconds, 2, ""); var result = test.GetSummary(); Assert.IsNotNull(result); Assert.IsTrue(result.TestResults.Count == 2); Assert.IsTrue(result.PassedTests == 2); Assert.IsTrue(Math.Round(result.PassedTestsAverageTime, MidpointRounding.ToEven) == 2001); Assert.IsTrue(result.FailedTests == 0); Assert.IsTrue(result.FailedTestsAverageTime == 0); Trace.WriteLine(result.ToString()); Assert.IsFalse(string.IsNullOrEmpty(result.ToString())); }
private static void RunDeSerializerTests() { var dataContractDeSerializerTest = new SpeedWatchTest("DataContractDeSerializer", () => JsonActions.DeSerializeWithDataContractJsonSerializer(), 10, "DataContractJsonDeSerializer test"); var javaScriptDeSerializerTest = new SpeedWatchTest("JavaScriptDeSerializer", () => JsonActions.DeSerializeWithJavaScriptJsonSerializer(), 10, "JavaScriptJsonDeSerializer test"); var newtonSoftDeSerializerTest = new SpeedWatchTest("NewtonsoftDeSerializer", () => JsonActions.DeSerializeWithNewtonSoft(), 10, "NewtonsoftDeSerializer test"); Console.WriteLine($@"{dataContractDeSerializerTest.GetSummary()} {javaScriptDeSerializerTest.GetSummary()} {newtonSoftDeSerializerTest.GetSummary()}"); }
private static void RunCollectionRemoveTests <T>(List <T> inputList) { var targetList = inputList.Take(inputList.Count / 2).ToList(); var listTest = new SpeedWatchTest("ListTest - Remove", () => RunCollectionAction(targetList, 10, () => new List <T>(inputList), (list, i) => list.Remove(i)), 10, $"Remove half {typeof(T).Name} types from a list"); var dictionaryTest = new SpeedWatchTest("DictionaryTest - Remove", () => RunCollectionAction(targetList, 10, () => new Dictionary <T, T>(inputList.ToDictionary(i => i, i => i)), (dic, i) => dic.Remove(i)), 10, $"Remove half {typeof(T).Name} types from a dictionary"); var hashSetTest = new SpeedWatchTest("HashSetTest - Remove", () => RunCollectionAction(targetList, 10, () => new HashSet <T>(inputList), (hash, i) => hash.Remove(i)), 10, $"Remove half {typeof(T).Name} types from a hashset"); Console.WriteLine($@"Collections Remove Tests: {listTest.GetSummary()} {dictionaryTest.GetSummary()} {hashSetTest.GetSummary()}"); }
private static void RunCollectionAddTests <T>(List <T> inputList) { var listTest = new SpeedWatchTest("ListTest - Add", () => RunCollectionAction(inputList, 10, () => new List <T>(), (list, i) => list.Add(i)), 10, $"Add {inputList.Count} {typeof(T).Name} types to a list"); var dictionaryTest = new SpeedWatchTest("DictionaryTest - Add", () => RunCollectionAction(inputList, 10, () => new Dictionary <T, T>(), (dic, i) => dic.Add(i, i)), 10, $"Add {inputList.Count} {typeof(T).Name} types to a dictionary"); var hashSetTest = new SpeedWatchTest("HashSetTest - Add", () => RunCollectionAction(inputList, 10, () => new HashSet <T>(), (hash, i) => hash.Add(i)), 10, $"Add {inputList.Count} {typeof(T).Name} types to a hashset"); Console.WriteLine($@"Collections Add Tests: {listTest.GetSummary()} {dictionaryTest.GetSummary()} {hashSetTest.GetSummary()}"); }