public void SendMessage() { string url = "https://api.groupme.com/v3/bots/post"; string expectedJson = @"{""text"":""Message here"",""bot_id"":""BOT_ID""}"; var httpClientMock = new Mock <IHttpClient>(); var loggerMock = new Mock <ILoggingService>(); var messenger = new GroupMeMessenger("BOT_ID", "BOT_NAME", new string[] {}, url, httpClientMock.Object, loggerMock.Object); messenger.SendMessage("Message here"); httpClientMock.Verify(c => c.Post(url, expectedJson)); }
public void SendMessage_Failure() { string url = "https://api.groupme.com/v3/bots/post"; string expectedJson = @"{""text"":""Message here"",""bot_id"":""BOT_ID""}"; var httpClientMock = new Mock <IHttpClient>(); var loggerMock = new Mock <ILoggingService>(); // Mock failure httpClientMock.Setup(c => c.Post(url, expectedJson)) .Throws(new System.Net.WebException("ERROR")); // Mock error logging loggerMock.Setup(c => c.Error(It.IsAny <Exception>(), "Error sending groupme message: ERROR", true)); var messenger = new GroupMeMessenger("BOT_ID", "BOT_NAME", new string[] { }, url, httpClientMock.Object, loggerMock.Object); bool actualResult = messenger.SendMessage("Message here"); Assert.False(actualResult); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); // Get configuration data string configFile = Path.Combine(Environment.CurrentDirectory, "NerdBot.ini"); if (!File.Exists(configFile)) { throw new Exception("Configuration file 'NerdBot.ini' does not exist."); } string dbConnectionString; string dbName; string priceDbName; string msgrBotId; string msgrBotName; string msgrEndPointUrl; string[] msgrIgnoreNames; string botRouteToken; string urlUser; string urlKey; string reporterBotId; string reporterBotName; string hostUrl; string adminUser; string adminPassword; string imgUrl = null; string imgHiResUrl = null; this.LoadConfiguration( configFile, out dbConnectionString, out dbName, out priceDbName, out msgrBotId, out msgrBotName, out msgrEndPointUrl, out msgrIgnoreNames, out botRouteToken, out urlUser, out urlKey, out reporterBotId, out reporterBotName, out hostUrl, out adminUser, out adminPassword, out imgUrl, out imgHiResUrl ); // Register the instance of ILoggingService container.Register <ILoggingService>((c, p) => new NLogLoggingService()); // Register the instance of IUrlShortener var bitlyUrl = new BitlyUrlShortener( urlUser, urlKey); container.Register <IUrlShortener>(bitlyUrl); // Register the instance of IMtgStore var mtgStore = new MtgStore( dbConnectionString, dbName, container.Resolve <ILoggingService>(), container.Resolve <SearchUtility>()); container.Register <IMtgStore>(mtgStore); // Register the instance of IQueryStatisticsStore var queryStatStore = new QueryStatisticsStore( dbConnectionString, dbName, container.Resolve <ILoggingService>() ); container.Register <IQueryStatisticsStore>(queryStatStore); // Register the instance of IHttpClient container.Register <IHttpClient, SimpleHttpClient>(); // Register the instance of ICommandParser container.Register <ICommandParser, CommandParser>(); // Register the main instance of IMessenger var groupMeMessenger = new GroupMeMessenger( msgrBotId, msgrBotName, msgrIgnoreNames, msgrEndPointUrl, container.Resolve <IHttpClient>(), container.Resolve <ILoggingService>()); container.Register <IMessenger>(groupMeMessenger); // Register IReporter var reporterMessenger = new GroupMeMessenger( reporterBotId, reporterBotName, msgrIgnoreNames, msgrEndPointUrl, container.Resolve <IHttpClient>(), container.Resolve <ILoggingService>()); var groupmeReporter = new GroupMeReporter(reporterMessenger); container.Register <IReporter>(groupmeReporter); // Register the instance of ICardPriceStore var priceStore = new EchoMtgPriceStore( dbConnectionString, priceDbName, container.Resolve <ILoggingService>(), container.Resolve <SearchUtility>()); container.Register <ICardPriceStore>(priceStore); // Register BotConfig string secretToken = botRouteToken; var botConfig = new BotConfig() { SecretToken = secretToken, HostUrl = hostUrl, AdminUser = adminUser, AdminPassword = adminPassword }; container.Register(botConfig); // Register the instance of IPluginManager //string pluginDirectory = Environment.CurrentDirectory; string pluginDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins"); var pluginManager = new PluginManager( msgrBotName, pluginDirectory, container.Resolve <ILoggingService>(), container.Resolve <IMtgStore>(), container.Resolve <ICommandParser>(), container.Resolve <IReporter>(), container); container.Register <IPluginManager>(pluginManager); container.Register <IUserMapper, UserMapper>(); // Register the instance of MtgJsonMapper var mtgJsonMapper = new MtgJsonMapper( container.Resolve <SearchUtility>()); mtgJsonMapper.ImageUrl = imgUrl; mtgJsonMapper.ImageHiResUrl = imgHiResUrl; container.Register <IMtgDataMapper <MtgJsonCard, MtgJsonSet> >(mtgJsonMapper); container.Register <IImporter, MtgImporter>(); }