コード例 #1
0
        public async Task RaiseAndListenToEvents_MultipleListners_ValidCase()
        {
            var bus = new RXEventChannel();
            var mockEventObserver = new MOQObserver();
            var applicationEvent  = new ApplicationEvent()
            {
                Context   = "Hi",
                Name      = "Invalidate-Cache",
                Id        = Guid.NewGuid().ToString(),
                Publisher = "Tushar",
                TimeStamp = DateTime.UtcNow
            };

            var eventObserver1 = bus.GetChannel("Invalidate-Cache");

            eventObserver1.Subscribe(mockEventObserver);

            var eventObserver2 = bus.GetChannel("Invalidate-Cache");

            eventObserver2.Subscribe(mockEventObserver);

            var provider = new SignalREventChannel(bus, new Tavisca.Common.Plugins.Configuration.JsonSerializer());

            Thread.Sleep(2000);

            provider.Notify(applicationEvent);

            Thread.Sleep(5000);

            Assert.AreEqual(mockEventObserver.CallCount, 2);
        }
コード例 #2
0
        public async Task ConfigUpdateEvent_VerifyEventInvokation_OnSuccessfulCompletion()
        {
            var bus                       = new RXEventChannel();
            var configStoreMock           = new Mock <IConfigurationStore>();
            var sensitiveDataProviderMock = new Mock <ISensitiveDataProvider>();
            var mock                      = new Mock <IApplicationEventBus>();

            mock.Setup(x => x.Notify(It.Is <ApplicationEvent>(e => e.Name.Equals("in-memory-consul-cache-refresh", StringComparison.OrdinalIgnoreCase))));
            var dataSet = new Dictionary <string, string>();

            dataSet.Add("key", "value");
            configStoreMock.Setup(cs => cs.GetAllAsync()).ReturnsAsync(dataSet);

            var eventHandler         = new ConfigurationUpdateEventHandler(configStoreMock.Object, mock.Object, sensitiveDataProviderMock.Object);
            var confifUpdateObserver = new ConfigurationObserver(eventHandler);

            var applicationEvent = new ApplicationEvent()
            {
                Context   = "config-update",
                Name      = "config-update",
                Id        = Guid.NewGuid().ToString(),
                Publisher = "Tushar",
                TimeStamp = DateTime.UtcNow
            };

            var eventObserver = bus.GetChannel("config-update");

            eventObserver.Subscribe(confifUpdateObserver);

            var provider = new SignalREventChannel(bus, new Tavisca.Common.Plugins.Configuration.JsonSerializer());

            Thread.Sleep(2000);

            provider.Notify(applicationEvent);

            Thread.Sleep(6000);

            Assert.IsTrue(LocalConfigurationRepository.IsKeyPresent("key"));
            //verify if the event has been raised on completion of config update

            mock.Verify(x => x.Notify(It.Is <ApplicationEvent>(e => e.Name.Equals("in-memory-consul-cache-refresh", StringComparison.OrdinalIgnoreCase))));
        }
コード例 #3
0
        public async Task ConfigUpdateEvent_ObserverCall_ValidCase()
        {
            var bus                       = new RXEventChannel();
            var configStoreMock           = new Mock <IConfigurationStore>();
            var sensitiveDataProviderMock = new Mock <ISensitiveDataProvider>();
            var mock                      = new Mock <IApplicationEventBus>();

            mock.Setup(x => x.Notify(It.IsAny <ApplicationEvent>()));
            var dataSet = new Dictionary <string, string>();

            dataSet.Add("key", "value");
            configStoreMock.Setup(cs => cs.GetAllAsync()).ReturnsAsync(dataSet);

            var eventHandler         = new ConfigurationUpdateEventHandler(configStoreMock.Object, mock.Object, sensitiveDataProviderMock.Object);
            var confifUpdateObserver = new ConfigurationObserver(eventHandler);

            var applicationEvent = new ApplicationEvent()
            {
                Context   = "config-update",
                Name      = "config-update",
                Id        = Guid.NewGuid().ToString(),
                Publisher = "Tushar",
                TimeStamp = DateTime.UtcNow
            };

            var eventObserver = bus.GetChannel("config-update");

            eventObserver.Subscribe(confifUpdateObserver);

            var provider = new SignalREventChannel(bus, new Tavisca.Common.Plugins.Configuration.JsonSerializer());

            Thread.Sleep(2000);

            provider.Notify(applicationEvent);

            Thread.Sleep(5000);

            Assert.IsTrue(LocalConfigurationRepository.IsKeyPresent("key"));
        }