Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public void TestWithNoExceptionsResult()
        {
            var test   = new SpeedWatchTest("Simple Test", SampleActions.WaitTwoSeconds, 5, "");
            var result = test.GetResults();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 5);
            foreach (var r in result)
            {
                Assert.IsTrue(r.Exception == null);
                Assert.IsTrue(r.Elapsed.Seconds == 2);
            }
        }
Esempio n. 3
0
        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()));
        }
Esempio n. 4
0
        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()}");
        }
Esempio n. 5
0
        public void TestWithNoExceptionsAsyncResult()
        {
            var task1 = SampleActions.WaitTwoSecondsAsync();
            var task2 = SampleActions.WaitTwoSecondsAsync();

            var test = new SpeedWatchTest("Simple Test", () => Task.WaitAll(task1, task2),
                                          5, "");
            var result = test.GetResults();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 5);
            foreach (var r in result)
            {
                Assert.IsTrue(r.Exception == null);
            }
        }
Esempio n. 6
0
        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()}");
        }
Esempio n. 7
0
        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()}");
        }