public async Task SendAllExceptAsync_PublishesAllCommandToBusAndHandlerSkipsExcludedConnection() { using var client = new TestClient(); var connection = HubConnectionContextUtils.Create(connection: client.Connection); var fakeBus = new FakeBus(); var hubLifetimeManager = ArrangeRebusLifetimeManager(fakeBus); await hubLifetimeManager.OnConnectedAsync(connection).OrTimeout(); await hubLifetimeManager.SendAllExceptAsync("Hello", new object[] { "World" }, new List <string>(new[] { connection.ConnectionId }).AsReadOnly()); var publishedEvent = fakeBus.Events.OfType <MessagePublished>().Select(m => m.EventMessage).OfType <All <TestHub> >().FirstOrDefault(); Assert.NotNull(publishedEvent); Assert.True(publishedEvent.ExcludedConnectionIds?.Length == 1 && publishedEvent.ExcludedConnectionIds[0] == connection.ConnectionId); var allHandler = new AllHandler <TestHub>(hubLifetimeManager, NullLogger <AllHandler <TestHub> > .Instance); await allHandler.Handle(publishedEvent); var message = client.TryRead() as InvocationMessage; Assert.Null(message); }
public void TestSetup() { this.ircConfig = TestHelpers.GetTestIrcConfig(); ircConnection = new MockIrcConnection(this.ircConfig); responseReceived = null; this.uut = new AllHandler(AllFunction); }
public async Task SendAllAsync_PublishesAllCommandToBusAndHandlerWritesInvocationToClient() { using var client = new TestClient(); var connection = HubConnectionContextUtils.Create(connection: client.Connection); var fakeBus = new FakeBus(); var hubLifetimeManager = ArrangeRebusLifetimeManager(fakeBus); await hubLifetimeManager.OnConnectedAsync(connection).OrTimeout(); await hubLifetimeManager.SendAllAsync("Hello", new object[] { "World" }); var publishedEvent = fakeBus.Events.OfType <MessagePublished>().Select(m => m.EventMessage).OfType <All <TestHub> >().FirstOrDefault(); Assert.NotNull(publishedEvent); Assert.Null(publishedEvent.ExcludedConnectionIds); var allHandler = new AllHandler <TestHub>(hubLifetimeManager, NullLogger <AllHandler <TestHub> > .Instance); await allHandler.Handle(publishedEvent); var message = client.TryRead() as InvocationMessage; Assert.NotNull(message); Assert.AreEqual("Hello", message.Target); Assert.AreEqual(1, message.Arguments.Length); Assert.AreEqual("World", (string)message.Arguments[0]); }
// -------- Functions -------- /// <summary> /// Initializes the plugin. /// </summary> /// <param name="pluginPath">The absolute path to the plugin dll.</param> /// <param name="ircConfig">The IRC config we are using.</param> public void Init(string pluginPath, IIrcConfig ircConfig) { string pluginDir = Path.GetDirectoryName(pluginPath); IrcLoggerConfig config = XmlLoader.LoadIrcLoggerConfig( Path.Combine(pluginDir, "IrcLoggerConfig.xml") ); if (string.IsNullOrEmpty(config.LogFileLocation)) { config.LogFileLocation = Path.Combine(pluginDir, "Logs"); } if (string.IsNullOrEmpty(config.LogName)) { config.LogName = "irclog"; } this.logManager = new LogManager(config); AllHandler handler = new AllHandler( this.HandleLogEvent ); this.handlers.Add(handler); }
public object GetService(Type type) { if (ReturnNull) { return(null); } if (type == typeof(IHandlerRegistrar)) { return(_registrar); } if (type == typeof(TestAggregateDidSomethingHandler)) { var handler = new TestAggregateDidSomethingHandler(); Handlers.Add(handler); return(handler); } if (type == typeof(TestAggregateDidSomethingInternalHandler)) { var handler = new TestAggregateDidSomethingInternalHandler(); Handlers.Add(handler); return(handler); } if (type == typeof(TestAggregateDoSomethingElseHandler)) { var handler = new TestAggregateDoSomethingElseHandler(); Handlers.Add(handler); return(handler); } if (type == typeof(TestAggregateDoSomethingHandler)) { var handler = new TestAggregateDoSomethingHandler(); Handlers.Add(handler); return(handler); } if (type == typeof(TestAggregateDoSomethingHandlerExplicit)) { var handler = new TestAggregateDoSomethingHandlerExplicit(); Handlers.Add(handler); return(handler); } if (type == typeof(TestAggregateDoSomethingHandlerExplicit2)) { var handler = new TestAggregateDoSomethingHandlerExplicit2(); Handlers.Add(handler); return(handler); } if (type == typeof(AllHandler)) { var handler = new AllHandler(); Handlers.Add(handler); return(handler); } throw new ArgumentException($"Type {type.Name} not registered"); }
// -------- Functions -------- /// <summary> /// Initializes the plugin. /// </summary> /// <param name="pluginPath">The absolute path to the plugin dll.</param> /// <param name="ircConfig">The IRC config we are using.</param> public void Init(string pluginPath, IIrcConfig ircConfig) { AllHandler handler = new AllHandler( delegate(IIrcWriter writer, IrcResponse response) { Console.WriteLine(response.Message); Console.Out.Flush(); } ); this.handlers.Add(handler); }
public void TestSetup() { this.ircConfig = TestHelpers.GetTestIrcConfig(); this.ircWriter = new Mock <IIrcWriter>(MockBehavior.Strict); this.responseReceived = null; AllHandlerConfig allHandlerConfig = new AllHandlerConfig { AllAction = this.AllFunction }; this.uut = new AllHandler(allHandlerConfig); }
// -------- Functions -------- /// <summary> /// Initializes the plugin. This includes loading any configuration files, /// starting services, etc. Allowed to throw Exceptions. /// /// This function should be used to validates that the environment is good for the plugin. /// For example, it has all dependencies installed, config files are in the correct spot, etc. /// It should also load GetHandlers() with the handlers. /// </summary> /// <param name="pluginInit">The class that has information required for initing the plugin.</param> public void Init(PluginInitor initor) { string configPath = Path.Combine( initor.ChaskisConfigPluginRoot, "UserListBot", "UserListBotConfig.xml" ); if (File.Exists(configPath) == false) { throw new FileNotFoundException( "Can not open " + configPath ); } this.userListConfig = XmlLoader.LoadConfig(configPath); // User query command: { MessageHandlerConfig msgConfig = new MessageHandlerConfig { LineRegex = this.userListConfig.Command, LineAction = this.HandleGetUsersCommand, CoolDown = this.userListConfig.Cooldown }; MessageHandler userQueryHandler = new MessageHandler( msgConfig ); this.handlers.Add(userQueryHandler); } { AllHandlerConfig allHandlerConfig = new AllHandlerConfig { AllAction = this.HandleNamesResponse }; AllHandler nameResponseHandler = new AllHandler(allHandlerConfig); this.handlers.Add(nameResponseHandler); } { AllHandlerConfig allHandlerConfig = new AllHandlerConfig { AllAction = this.HandleEndOfNamesResponse }; AllHandler endOfNamesHandler = new AllHandler(allHandlerConfig); this.handlers.Add(endOfNamesHandler); } }
// -------- Functions -------- /// <summary> /// Initializes the plugin. /// </summary> /// <param name="pluginInit">The class that has information required for initing the plugin.</param> public void Init(PluginInitor initor) { AllHandlerConfig allHandlerConfig = new AllHandlerConfig { AllAction = delegate(AllHandlerArgs args) { Console.WriteLine(args.Line); } }; AllHandler handler = new AllHandler( allHandlerConfig ); this.handlers.Add(handler); }
// -------- Functions -------- /// <summary> /// Initializes the plugin. /// </summary> /// <param name="pluginInit">The class that has information required for initing the plugin.</param> public void Init(PluginInitor initor) { string pluginDir = Path.Combine( initor.ChaskisConfigPluginRoot, "IrcLogger" ); string configPath = Path.Combine( pluginDir, "IrcLoggerConfig.xml" ); this.config = XmlLoader.LoadIrcLoggerConfig( configPath ); if (string.IsNullOrEmpty(config.LogFileLocation)) { config.LogFileLocation = Path.Combine(pluginDir, "Logs"); } if (string.IsNullOrEmpty(config.LogName)) { config.LogName = "irclog"; } this.logManager = new LogManager(config, initor.Log); AllHandlerConfig allHandlerConfig = new AllHandlerConfig { AllAction = this.HandleLogEvent }; AllHandler handler = new AllHandler( allHandlerConfig ); this.handlers.Add(handler); }
// -------- Functions -------- /// <summary> /// Initializes the plugin. This includes loading any configuration files, /// starting services, etc. Allowed to throw Exceptions. /// /// This function should be used to validates that the environment is good for the plugin. /// For example, it has all dependencies installed, config files are in the correct spot, etc. /// It should also load GetHandlers() with the handlers. /// </summary> /// <param name="pluginPath"> /// The absolute path to the plugin, including the file name. To just get /// the path to the plugin, call Path.GetDirectoryName on this argument. /// </param> /// <param name="ircConfig">The IRC config we are using.</param> public void Init(string pluginPath, IIrcConfig ircConfig) { string configPath = Path.Combine( Path.GetDirectoryName(pluginPath), "UserListBotConfig.xml" ); if (File.Exists(configPath) == false) { throw new FileNotFoundException( "Can not open " + configPath ); } this.ircConfig = ircConfig; this.userListConfig = XmlLoader.LoadConfig(configPath); // User query command: { MessageHandler userQueryHandler = new MessageHandler( this.userListConfig.Command.Replace("{%nick%}", this.ircConfig.Nick), this.HandleGetUsersCommand, this.userListConfig.Cooldown ); this.handlers.Add(userQueryHandler); } { AllHandler nameResponseHandler = new AllHandler(HandleNamesResponse); this.handlers.Add(nameResponseHandler); } { AllHandler endOfNamesHandler = new AllHandler(HandleEndOfNamesResponse); this.handlers.Add(endOfNamesHandler); } }