public async Task AddCurrenyUpdateRecord(CurrencyUpdateList currencyUpdate) { CurrencyUpdate newUpdate = new CurrencyUpdate() { AppuserId = currencyUpdate.userId, UpdateDate = DateTimeOffset.UtcNow }; foreach (var item in currencyUpdate.CurrencyList) { var currency = await GetCurrencyById(item.CurrenceyId); if (currency.Code == "USD") { newUpdate.USD = item.value; } else if (currency.Code == "EURO") { newUpdate.EURO = item.value; } else if (currency.Code == "STG") { newUpdate.STG = item.value; } } await _CurrencyUpdate.InsertOneAsync(newUpdate); }
public void ReturnTrue_AfterWaitingFullInterval() { const int intervalInMinutes = 1; Shim shim = Shim.Replace(() => DateTime.Now).With(() => DateTime.Now.AddMinutes(intervalInMinutes)); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, null); PoseContext.Isolate(() => Assert.True(currencyUpdate.IsTimeToRun()), shim); }
public void ReturnFalse_UponInitialCreation() { var currencyUpdate = new CurrencyUpdate(1, null); bool result = currencyUpdate.IsTimeToRun(); Assert.False(result); }
public static AbstractEntities.CurrencyUpdate ToAbstract(this CurrencyUpdate web) { if (web == null) { return(null); } return(new AbstractEntities.CurrencyUpdate(web.Id, web.Code)); }
public void ReturnTrue_AfterWaitingFullInterval() { const int intervalInMinutes = 1; var fakeClock = new FakeClock(); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, null, fakeClock); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); Assert.True(currencyUpdate.IsTimeToRun()); }
public static BotMain NewBot(TwitchClientSettings twitchSettings, string connectionString) { var twitchApi = new TwitchAPI(twitchSettings.TwitchClientId); var twitchChatClient = new TwitchChatClient(twitchSettings, twitchApi); var chatClients = new List <IChatClient> { new ConsoleChatClient(), twitchChatClient, }; var twitchFollowerService = new TwitchFollowerService(twitchApi, twitchSettings); IRepository repository = SetUpDatabase.SetUpRepository(connectionString); var chatUserCollection = new ChatUserCollection(repository); var currencyGenerator = new CurrencyGenerator(chatClients, chatUserCollection); var currencyUpdate = new CurrencyUpdate(1, currencyGenerator); var automatedActionSystem = new AutomatedActionSystem(new List <IIntervalAction> { currencyUpdate }); var rockPaperScissorsGame = new RockPaperScissorsGame(currencyGenerator, automatedActionSystem); var wordList = new List <string> { "apple", "banana", "orange", "mango", "watermellon", "grapes", "pizza", "pasta", "pepperoni", "cheese", "mushroom", "csharp", "javascript", "cplusplus", "nullreferenceexception", "parameter", "argument" }; var hangmanGame = new HangmanGame(currencyGenerator, automatedActionSystem, wordList); var simpleCommands = repository.List <SimpleCommand>(); List <IBotCommand> allCommands = new List <IBotCommand>(); allCommands.AddRange(simpleCommands); allCommands.Add(new GiveCommand(chatUserCollection)); allCommands.Add(new HelpCommand(allCommands)); allCommands.Add(new CommandsCommand(allCommands)); allCommands.Add(new CoinsCommand(repository)); allCommands.Add(new BonusCommand(currencyGenerator)); allCommands.Add(new StreamsCommand(repository)); allCommands.Add(new ShoutOutCommand(twitchFollowerService)); allCommands.Add(new QuoteCommand(repository)); allCommands.Add(new AddQuoteCommand(repository)); allCommands.Add(new AddCommandCommand(repository, allCommands)); allCommands.Add(new RemoveCommandCommand(repository, allCommands)); allCommands.Add(new HangmanCommand(hangmanGame)); allCommands.Add(new RockPaperScissorsCommand(rockPaperScissorsGame)); var commandHandler = new CommandHandler(chatClients, allCommands); var subscriberHandler = new SubscriberHandler(chatClients); var twitchSystem = new FollowableSystem(new[] { twitchChatClient }, twitchFollowerService); var botMain = new BotMain(chatClients, repository, commandHandler, subscriberHandler, twitchSystem, automatedActionSystem); return(botMain); }
public void Update_WhenRecordDoesNotExist_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { var currencyUpdate = new CurrencyUpdate { Id = 1, Code = "USD" }; controller.Update(currencyUpdate); } }
public void ReturnFalse_UponInitialCreation() { var settingsFactory = new Mock <ISettingsFactory>(); settingsFactory.Setup(x => x.GetSettings <CurrencySettings>()).Returns(new CurrencySettings()); var currencyUpdate = new CurrencyUpdate(null, settingsFactory.Object, new FakeClock()); bool result = currencyUpdate.IsTimeToRun(); Assert.False(result); }
public void ReturnFalse_AfterInvokingAction() { // TODO: Add the shim in here, because the test would pass regardless const int intervalInMinutes = 1; IRepository repository = new FakeRepo(); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, new CurrencyGenerator(new List <IChatClient>(), new ChatUserCollection(repository))); bool result = false; currencyUpdate.Invoke(); result = currencyUpdate.IsTimeToRun(); Assert.False(result); }
public void ReturnTrue_AfterWaitingFullInterval() { const int intervalInMinutes = 1; var fakeClock = new FakeClock(); var settingsFactory = new Mock <ISettingsFactory>(); settingsFactory.Setup(x => x.GetSettings <CurrencySettings>()).Returns(new CurrencySettings()); var currencyUpdate = new CurrencyUpdate(null, settingsFactory.Object, fakeClock); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); Assert.True(currencyUpdate.IsTimeToRun()); }
public IActionResult Update([FromBody] CurrencyUpdate currencyUpdate) { if (currencyUpdate == null) { throw new InvalidRequestArgumentException("The currency cannot be null or empty."); } if (string.IsNullOrWhiteSpace(currencyUpdate.Code)) { throw new InvalidRequestArgumentException("Currency code cannot be null or empty."); } dataLayer.UpdateCurrency(currencyUpdate.ToAbstract()); return(NoContent()); }
public void ReturnFalse_AfterInvokingAction() { const int intervalInMinutes = 1; IRepository repository = new Mock <IRepository>().Object; var currencyGenerator = new CurrencyGenerator(new List <IChatClient>(), new ChatUserCollection(repository)); var fakeClock = new FakeClock(); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, currencyGenerator, fakeClock); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); Assert.True(currencyUpdate.IsTimeToRun()); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); currencyUpdate.Invoke(); Assert.False(currencyUpdate.IsTimeToRun()); }
public BotMain(IList <IChatClient> chatClients, IRepository repository, IFollowableSystem followableSystem, IAutomatedActionSystem automatedActionSystem, ICommandHandler commandHandler, SubscriberHandler subscriberHandler, CurrencyUpdate currencyUpdate) { _chatClients = chatClients; _repository = repository; _followableSystem = followableSystem; _automatedActionSystem = automatedActionSystem; _commandHandler = commandHandler; _subscriberHandler = subscriberHandler; _currencyUpdate = currencyUpdate; }
public void ReturnFalse_AfterInvokingAction() { const int intervalInMinutes = 1; var repository = new Mock <IRepository>(); repository.Setup(x => x.List(It.IsAny <ISpecification <ChatUser> >())).Returns(new List <ChatUser>()); var currencyGenerator = new CurrencyGenerator(new List <IChatClient>(), new ChatUserCollection(repository.Object)); var fakeClock = new FakeClock(); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, currencyGenerator, fakeClock); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); Assert.True(currencyUpdate.IsTimeToRun()); fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes); currencyUpdate.Invoke(); Assert.False(currencyUpdate.IsTimeToRun()); }