public void RedisNotificationBus_WhenInvalidation_ShouldDisposeMonitor()
        {
            var lcache = new MemoryCache(Guid.NewGuid().ToString());
            var bus = new RedisNotificationBus("localhost:6379", new InvalidationSettings() { TargetCache = lcache, InvalidationStrategy = InvalidationStrategyType.ChangeMonitor });
            bus.Connection = this.MockOfConnection.Object;
            var monitor = new RedisChangeMonitor(bus.Notifier, "mykey");
            lcache.Add("mykey", DateTime.UtcNow, new CacheItemPolicy() { AbsoluteExpiration = DateTime.UtcNow.AddDays(1), ChangeMonitors = { monitor } });

            bus.Start();

            //act
            this.NotificationEmitter(Constants.DEFAULT_INVALIDATION_CHANNEL, "mykey");

            //assert
            Assert.False(lcache.Contains("mykey"));
            Assert.True(monitor.IsDisposed);
        }
        public void RedisNotificationBus_WhenStart_ShouldConnectAndSubscribe()
        {
            var bus = new RedisNotificationBus("localhost:6379", new InvalidationSettings());
            bus.Connection = this.MockOfConnection.Object;

               bus.Start();

            this.MockOfConnection.Verify(c => c.Connect(), Times.Once);
            this.MockOfConnection.Verify(c => c.Subscribe(Constants.DEFAULT_INVALIDATION_CHANNEL, It.IsAny<Action<RedisChannel, RedisValue>>()), Times.Once);
        }
        public void RedisNotificationBus_WhenStop_ShouldDisconnect()
        {
            var bus = new RedisNotificationBus("localhost:6379", new InvalidationSettings());
            bus.Connection = this.MockOfConnection.Object;

            var notifyTask = bus.NotifyAsync("mykey");

            Assert.NotNull(notifyTask);
            Assert.Equal(5, notifyTask.Result);
            this.MockOfConnection.Verify(c => c.PublishAsync(Constants.DEFAULT_INVALIDATION_CHANNEL, "mykey"), Times.Once);
        }
 public void RedisNotificationBus_WhenInvalidCtorArgs_ShouldNotThrowExceptions()
 {
     var bus = new RedisNotificationBus("fghfgh", new InvalidationSettings());
     Assert.NotNull(bus.Connection);
     Assert.NotNull(bus.Notifier);
     Assert.Equal(MemoryCache.Default, bus.LocalCache);
 }