public async Task TimeWatchInterceptorTestV1()
        {
            //Configuration
            var count = 0;

            TraceData[] traceReceived = { };

            _container.RegisterInterceptor(PredefinedInterceptors.TimeWatchInterceptor, LifeTime.Singleton);
            _container.Intercept <IClassVoidTest>().With(PredefinedInterceptors.TimeWatchInterceptor);

            var instance = _container.Resolve <IClassVoidTest>();

            using (var tracer = new TraceSourceSync(_traceConfig))
            {
                tracer.OnTracesSent += trace =>
                {
                    traceReceived = trace;
                    Interlocked.Increment(ref count);
                };

                //Test
                instance.MethodCall();

                //Verify
                await tracer.FlushAndCompleteAddingAsync().ConfigureAwait(false);
            }

            // un seul retour
            Assert.AreEqual(1, count);
            Assert.AreEqual(1, traceReceived.Length);
            Assert.IsTrue(traceReceived[0].Message.StartsWith("TIME_IClassVoidTest.MethodCall = "));
        }
        public void PerformanceNewClassTest_TransientV3()
        {
            //Configuration
            var config = new TraceConfig {
                TraceBehavior = TraceStaticBehavior.AddListenerToStaticAccessAndRemoveDefaultTracer
            };

            _container.RegisterInstance(new TraceSourceSync(config));

            _container.RegisterInterceptor <InterceptorDoNothing>(LifeTime.Transient);
            _container.Register <IClassVoidTest, ClassVoidTest>(LifeTime.Transient);
            _container.Intercept <IClassVoidTest>().With <InterceptorDoNothing>();

            //Test
            const int upper = 10_000;
            var       watch = Stopwatch.StartNew();

            for (var i = 0; i < upper; i++)
            {
                var _ = _container.Resolve <IClassVoidTest>();
            }
            watch.Stop();

            //Verify
            Assert.IsTrue(watch.Elapsed < TimeSpan.FromSeconds(1),
                          $"Trop lent pour créer {upper} objet transient: time = {watch.ElapsedMilliseconds} ms");
        }
        public async Task InterceptionTestV1()
        {
            //Configuration
            var count = 0;

            TraceData[] traceReceived = { };

            using (var tracer = new TraceSourceSync(new TraceConfig {
                TraceBehavior = TraceStaticBehavior.AddListenerToStaticAccessAndRemoveDefaultTracer, PageSize = 2
            }))
            {
                _container.RegisterInstance(tracer);

                _container.RegisterInterceptor <InterceptorTraceInjectTracer>(LifeTime.Singleton);
                _container.RegisterInterceptor <InterceptorTraceStatic>(LifeTime.Singleton);
                _container.Register <IClassVoidTest, ClassVoidTest>(LifeTime.Singleton);

                _container.Intercept <IClassVoidTest>().With <InterceptorTraceInjectTracer>();
                _container.Intercept <IClassVoidTest>().With <InterceptorTraceStatic>();

                tracer.OnTracesSent += trace =>
                {
                    traceReceived = trace;
                    Interlocked.Increment(ref count);
                };

                //Test
                var instance = _container.Resolve <IClassVoidTest>();
                instance.MethodCall();

                //Verify
                await tracer.FlushAndCompleteAddingAsync().ConfigureAwait(false);
            }

            // un seul retour (avec les deux traces des intercepteurs)
            Assert.AreEqual(1, count);
            Assert.IsNotNull(traceReceived.Single(o => o.Message == "IClassVoidTest_InterceptorTraceInjectTracer"));
            Assert.IsNotNull(traceReceived.Single(o => o.Message == "IClassVoidTest_InterceptorTraceStatic"));
        }
Example #4
0
        public async Task MethodInterceptorTestV1()
        {
            //Configuration
            var count = 0;

            TraceData[] traceReceived = { };

            _container.RegisterInterceptor(PredefinedInterceptors.MethodTraceInterceptor, LifeTime.Singleton);
            _container.Intercept <IClassVoidTest>().With(PredefinedInterceptors.MethodTraceInterceptor);

            var instance = _container.Resolve <IClassVoidTest>();

            using (var tracer = new TraceSourceSync(_traceConfig))
            {
                tracer.OnTracesSent += trace =>
                {
                    traceReceived = trace;
                    Interlocked.Increment(ref count);
                };

                //Test
                instance.MethodCall();

                //Verify
                await tracer.FlushAndCompleteAddingAsync().ConfigureAwait(false);
            }

            // un seul retour (avec les deux traces des intercepteurs)
            Assert.AreEqual(1, count);
            Assert.AreEqual(2, traceReceived.Length);
            Assert.AreEqual("START_IClassVoidTest.MethodCall()", traceReceived[0].Message);
            Assert.AreEqual("STOP_IClassVoidTest.MethodCall", traceReceived[1].Message);
        }