Exemple #1
0
        public void TraceResultShouldContainThreeThreads()
        {
            ITracer             tracer = new MethodTracer();
            MultiThreadingClass multiThreadingClass = new MultiThreadingClass(tracer);

            multiThreadingClass.RunThreeThreads();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.Equal(3, traceResult.Threads.Count());
        }
Exemple #2
0
        public void FirstMethodResultShouldContainOneInnerMethod()
        {
            ITracer tracer = new MethodTracer();
            ClassWithSeveralMethods classWithSeveralMethods = new ClassWithSeveralMethods(tracer);

            classWithSeveralMethods.MethodWithInnerMethods();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.Single(traceResult.Threads[0].Methods[0].Methods);
        }
Exemple #3
0
        public void MethodTimeShouldBeMoreOrEqualThanSleepTime()
        {
            ITracer tracer = new MethodTracer();
            ClassWithSleepMethod classWithSleepMethod = new ClassWithSleepMethod(tracer);

            classWithSleepMethod.MethodWithSleep();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.True(traceResult.Threads[0].Methods[0].Time >= 100);
        }
Exemple #4
0
        public void ThreadTimeShouldEqualSumOfHighestLevelMethodsTimes()
        {
            ITracer tracer = new MethodTracer();
            ClassWithSeveralMethods classWithSeveralMethods = new ClassWithSeveralMethods(tracer);

            classWithSeveralMethods.MethodWithInnerMethods();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.Equal(traceResult.Threads[0].Time, traceResult.Threads[0].Methods.Select(method => method.Time).Sum());
        }
Exemple #5
0
        public void TracerShouldTraceTwoMethodsOnHighestLevel()
        {
            ITracer tracer = new MethodTracer();
            ClassWithSeveralMethods classWithSeveralMethods = new ClassWithSeveralMethods(tracer);

            classWithSeveralMethods.MethodWithInnerMethods();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.Equal(2, traceResult.Threads[0].Methods.Count);
        }
Exemple #6
0
        public void ShouldReturnCorrectThreadId()
        {
            ITracer tracer = new MethodTracer();
            ClassWithSleepMethod classWithSleepMethod = new ClassWithSleepMethod(tracer);
            int threadId = Thread.CurrentThread.ManagedThreadId;

            classWithSleepMethod.MethodWithSleep();
            TraceResult traceResult = tracer.GetTraceResult();

            Assert.Equal(threadId, traceResult.Threads[0].Id);
        }
Exemple #7
0
        public void TestMethodTraceResult()
        {
            SetUp();
            _methodTracer.StartTrace(ClassName, MethodName);
            _methodTracer.StartTrace(InnerClassName, InnerMethodName);
            _methodTracer.StopTrace();
            _methodTracer.StopTrace();
            var methodTraceResult = _methodTracer.GetTraceResult();

            Assert.Equal(ClassName, methodTraceResult.ClassName);
            Assert.Equal(MethodName, methodTraceResult.MethodName);
            var innerMethodTraceResult = methodTraceResult.InnerMethodTraceResults[0];

            Assert.Equal(InnerClassName, innerMethodTraceResult.ClassName);
            Assert.Equal(InnerMethodName, innerMethodTraceResult.MethodName);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            ITracer methodTracer = new MethodTracer();
            BackgroundTestStarter testStarter = new BackgroundTestStarter(methodTracer);

            testStarter.StartTest();

            TraceResult traceResult = methodTracer.GetTraceResult();

            IWriter consoleWriter = new ConsoleWriter();
            IWriter fileWriter    = new FileWriter("out.txt");

            ISerializer serializer       = new JSONSerializer();
            string      serializedResult = serializer.Serizlize(traceResult);

            consoleWriter.Write(serializedResult);
            fileWriter.Write(serializedResult);
        }