public void PopHandler_should_pop_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);
            service.PopHandler(a);
            Assert.Null(service.GetHandler(typeof(A)));
        }
예제 #2
0
        public void GetHandler_should_return_null_if_handler_not_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().HandlerHead     = CreateStack();

            Assert.Null(service.GetHandler(typeof(ComboBox)));
        }
예제 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            EventHandlerService.Start();
        }
예제 #4
0
        public void PushHandler_should_set_lastHandler_to_new_handler()
        {
            var service = new EventHandlerService(null);
            var handler = new Label();

            service.PushHandler(handler);

            Assert.Same(handler, service.GetTestAccessor().LastHandler);
        }
        public void ctor_should_set_FocusWindow()
        {
            var service = new EventHandlerService(null);

            Assert.Null(service.FocusWindow);

            using var focusWnd = new Control();
            service            = new EventHandlerService(focusWnd);
            Assert.Same(focusWnd, service.FocusWindow);
        }
예제 #6
0
        public void GetHandler_should_return_lastHandlerType_if_matches()
        {
            var service = new EventHandlerService(null);
            var handler = new Button();

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().LastHandler     = handler;

            Assert.Same(handler, service.GetHandler(typeof(Button)));
        }
예제 #7
0
 private void SetupHandlerService()
 {
     _handlerService = new EventHandlerService(
         _statusServiceMock.Object,
         _httpServiceMock.Object,
         _tilgangerServiceMock.Object,
         _appSettingsMock.Object,
         _loggerMock.Object
         );
 }
예제 #8
0
        public void GetHandler_should_set_lastHandlerType_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().HandlerHead     = CreateStack();

            var foundHandler = service.GetHandler(typeof(TextBox));

            Assert.Same(typeof(TextBox), service.GetTestAccessor().LastHandlerType);
        }
        public void GetHandler_should_return_null_if_handler_type_not_found()
        {
            var service = new EventHandlerService(null);

            service.PushHandler("Handler");

            // PopHandler asserts when an item isn't found
            using (new NoAssertContext())
            {
                Assert.Null(service.GetHandler(typeof(int)));
            }
        }
        public void GetHandler_should_return_last_inserted_handler_of_type()
        {
            var service = new EventHandlerService(null);

            service.PushHandler(new A());

            object second = new A();

            service.PushHandler(second);

            Assert.Same(second, service.GetHandler(typeof(A)));
        }
예제 #11
0
        public void PushHandler_should_raise_changedEvent_for_new_handler()
        {
            var service   = new EventHandlerService(null);
            var handler   = new Label();
            int callCount = 0;

            service.EventHandlerChanged += (s, e) => { callCount++; };

            service.PushHandler(handler);

            Assert.Equal(1, callCount);
        }
        public void GetHandler_should_not_remove_from_handlers()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);

            var foundHandler = service.GetHandler(typeof(A));

            Assert.Same(a, foundHandler);
            foundHandler = service.GetHandler(typeof(A));
            Assert.Same(a, foundHandler);
        }
        public void PushHandler_should_set_handlerHead_to_new_handler()
        {
            var service = new EventHandlerService(null);

            A a1 = new A();

            service.PushHandler(a1);
            A a2 = new A();

            service.PushHandler(a2);

            Assert.Same(a2, service.GetHandler(typeof(A)));
        }
        public void GetHandler_should_return_derived_handler_if_found()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);
            B b = new B();

            service.PushHandler(b);

            var foundHandler = service.GetHandler(typeof(A));

            Assert.Same(b, foundHandler);
        }
예제 #15
0
        public void GetHandler_should_set_lastHandler_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            var foundHandler = service.GetHandler(handler.GetType());

            Assert.Same(handler, service.GetTestAccessor().LastHandler);
        }
예제 #16
0
        public void PopHandler_should_set_lastHandlerType_null_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            service.PopHandler(handler);

            Assert.Null(service.GetTestAccessor().LastHandlerType);
        }
        public void PopHandler_should_not_pop_if_handler_not_found_on_stack()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);

            // PopHandler asserts when an item isn't found
            using (new NoAssertContext())
            {
                service.PopHandler(new B());
            }

            Assert.Same(a, service.GetHandler(typeof(A)));
        }
예제 #18
0
        // Get the service from the site
        internal Object GetServiceFromSite(Type type)
        {
            Object service = _serviceContainer.GetService(type);

            if (service != null)
            {
                return(service);
            }

            // These are the site local services
            if (type.Equals(typeof(IInheritanceService)))
            {
                AddService(typeof(IInheritanceService), new InheritanceService());
                return(GetService(type));
            }
            if (type.Equals(typeof(AmbientProperties)))
            {
                AddService(typeof(AmbientProperties), new AmbientProperties());
                return(GetService(type));
            }
            if (type.Equals(typeof(IDictionaryService)))
            {
                AddService(typeof(IDictionaryService), this);
                return(GetService(type));
            }
            if (type.Equals(typeof(IComponentChangeService)))
            {
                AddService(typeof(IComponentChangeService), this);
                return(GetService(type));
            }
            if (type.Equals(typeof(ITypeDescriptorFilterService)))
            {
                AddService(typeof(ITypeDescriptorFilterService), this);
                return(GetService(type));
            }
            if (type.Equals(typeof(IInheritanceService)))
            {
                AddService(typeof(IInheritanceService), this);
                return(GetService(type));
            }
            if (type.FullName.Equals(_ehServiceTypeName))
            {
                Object ehService = new EventHandlerService((Control)_component);
                AddService(type, ehService);
                return(GetService(type));
            }
            return(service);
        }
        public void PopHandler_should_raise_changedEvent_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            A a = new A();

            service.PushHandler(a);

            int callCount = 0;

            service.EventHandlerChanged += (s, e) => { callCount++; };

            service.PopHandler(a);

            Assert.Equal(1, callCount);
        }
예제 #20
0
        public void PopHandler_should_raise_changedEvent_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;
            int callCount = 0;

            service.EventHandlerChanged += (s, e) => { callCount++; };

            service.PopHandler(handler);

            Assert.Equal(1, callCount);
        }
예제 #21
0
        public async Task MainAsync(string token)
        {
            _client = new DiscordSocketClient(
                new DiscordSocketConfig()
            {
                LogLevel         = LogSeverity.Info,
                MessageCacheSize = 1000
            });

            try
            {
                var _EventLoggerService = new EventHandlerService(_client);
                await _client.LoginAsync(TokenType.Bot, token);

                await _client.StartAsync();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Environment.Exit(1);
            };

            _client.Log += (LogMessage msg) =>
            {
                Log.Information("{Source}: {Message}", msg.Source, msg.Message);
                return(Task.CompletedTask);
            };
            _handler = new CommandHandler(_client);

            if (BotConfigFactory.Config.Activity != null)
            {
                await _client.SetActivityAsync(BotConfigFactory.Config.Activity);
            }

            BackupService backupService = new BackupService();

            backupService.Start();
            await Task.Delay(-1);
        }
예제 #22
0
        public void PopHandler_should_pop_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            service.PopHandler(handler);

            var depth = 0;

            for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next)
            {
                depth++;
            }

            Assert.Equal(1, depth);
        }
예제 #23
0
        public void PopHandler_should_not_pop_if_handler_not_found_on_stack()
        {
            // we expect to hit Debug.Assert and unless we clear listeners we will crash to xUnit runner:
            //  "The active test run was aborted. Reason: Test host process crashed : Assertion Failed"
            using (new TraceListenerlessContext())
            {
                var service = new EventHandlerService(null);
                service.GetTestAccessor().LastHandlerType = typeof(Button);
                var stackHead = CreateStack();
                service.GetTestAccessor().HandlerHead = stackHead;

                service.PopHandler(typeof(ComboBox));

                var depth = 0;
                for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next)
                {
                    depth++;
                }

                Assert.Equal(3, depth);
            }
        }
예제 #24
0
 public void setEventHandler(EventHandlerService eventHandler)
 {
     this.eventHandler = eventHandler;
 }
 public bool Trigger([FromBody] string message)
 {
     EventHandlerService.BroadcastMessage(message);
     return(true);
 }
예제 #26
0
        public void GetHandler_should_return_null_if_lastHandlerType_null()
        {
            var service = new EventHandlerService(null);

            Assert.Null(service.GetHandler(typeof(object)));
        }
예제 #27
0
        public void GetHandler_should_throw_if_handlerType_null()
        {
            var service = new EventHandlerService(null);

            Assert.Throws <ArgumentNullException>(() => service.GetHandler(null));
        }
예제 #28
0
        public void ctor_should_create_object()
        {
            var service = new EventHandlerService(null);

            Assert.NotNull(service);
        }
예제 #29
0
        public void PopHandler_should_not_throw_if_stack_empty()
        {
            var service = new EventHandlerService(null);

            service.PopHandler(typeof(ComboBox));
        }