Ejemplo n.º 1
0
    public void MonitorExceptionTest()
    {

      using ( var provider = new MemoryCacheProvider( "Test" ).AsAsyncProvider() )
      {
        var cacheService = new CacheService( provider );
        var monitor = new CacheServiceMonitorWithException();
        cacheService.RegisterMonitor( monitor );


        Task.Run( (Func<Task>) (async () =>
        {

          await cacheService.FetchOrAdd<string>( (string) "Test", (Func<Task<string>>) (() => (Task<string>) Task.Run( (Func<string>) (() => (string) "Test") )), (Caching.CachePolicy) Caching.CachePolicy.Expires( (TimeSpan) TimeSpan.FromHours( (double) 1 ) ) );
          await cacheService.FetchOrAdd<string>( (string) "Test", (Func<Task<string>>) (() => (Task<string>) Task.Run( (Func<string>) (() => (string) "Test") )), (Caching.CachePolicy) Caching.CachePolicy.Expires( (TimeSpan) TimeSpan.FromHours( (double) 1 ) ) );

          await Task.Delay( 100 );

          await cacheService.FetchOrAdd<string>( (string) "Test", (Func<Task<string>>) (() => (Task<string>) Task.Run( (Func<string>) (() => (string) "Test") )), (Caching.CachePolicy) Caching.CachePolicy.Expires( (TimeSpan) TimeSpan.FromHours( (double) 1 ) ) );
          await cacheService.FetchOrAdd<string>( (string) "Test", (Func<Task<string>>) (() => (Task<string>) Task.Run( (Func<string>) (() => (string) "Test") )), (Caching.CachePolicy) Caching.CachePolicy.Expires( (TimeSpan) TimeSpan.FromHours( (double) 1 ) ) );

        })
        ).Wait();


        Assert.AreEqual( monitor.Misses, 1 );
        Assert.AreEqual( monitor.Hits, 3 );

      }

    }
Ejemplo n.º 2
0
        public void MonitorExceptionTest()
        {
            using (var provider = new MemoryCacheProvider("Test").AsAsyncProvider())
            {
                var cacheService = new CacheService(provider);
                var monitor      = new CacheServiceMonitorWithException();
                cacheService.RegisterMonitor(monitor);


                Task.Run((Func <Task>)(async() =>
                {
                    await cacheService.FetchOrAdd <string>((string)"Test", (Func <Task <string> >)(() => (Task <string>)Task.Run((Func <string>)(() => (string)"Test"))), (Caching.CachePolicy)Caching.CachePolicy.Expires((TimeSpan)TimeSpan.FromHours((double)1)));
                    await cacheService.FetchOrAdd <string>((string)"Test", (Func <Task <string> >)(() => (Task <string>)Task.Run((Func <string>)(() => (string)"Test"))), (Caching.CachePolicy)Caching.CachePolicy.Expires((TimeSpan)TimeSpan.FromHours((double)1)));

                    await Task.Delay(100);

                    await cacheService.FetchOrAdd <string>((string)"Test", (Func <Task <string> >)(() => (Task <string>)Task.Run((Func <string>)(() => (string)"Test"))), (Caching.CachePolicy)Caching.CachePolicy.Expires((TimeSpan)TimeSpan.FromHours((double)1)));
                    await cacheService.FetchOrAdd <string>((string)"Test", (Func <Task <string> >)(() => (Task <string>)Task.Run((Func <string>)(() => (string)"Test"))), (Caching.CachePolicy)Caching.CachePolicy.Expires((TimeSpan)TimeSpan.FromHours((double)1)));
                })
                         ).Wait();


                Assert.AreEqual(monitor.Misses, 1);
                Assert.AreEqual(monitor.Hits, 3);
            }
        }