public async Task RetrieveStockPriceRequest([FromBody] StockConsumerRequest stock) { var stockName = stock.StockName; string queueMessage = string.Empty; try { List <string> fileHeaders = null; List <string> fileContent = null; (fileHeaders, fileContent) = await _stockInfoIntegration.GetStockInfoFile(stockName); var stockValueIndex = GetStockCloseValueIndex(fileHeaders); ValidateHeadersAndColumnsQuantity(fileHeaders, fileContent); queueMessage = GenerateQueueMessage(stockName, stockValueIndex, fileContent); } catch (Exception ex) { _logger.LogError(ex.Message); queueMessage = $"Unable to get {stockName} stock information."; } finally { _queueIntegration.PostMessage(queueMessage); } }
public StockConsumerControllerTests() { _stockFileInfoIntegration = Mock.Create <IStockFileInfoIntegration>(); _queueIntegration = Mock.Create <IQueueIntegration>(); _logger = Mock.Create <ILogger <StockConsumerController> >(); _controller = new StockConsumerController(_queueIntegration, _stockFileInfoIntegration, _logger); // Prevent any posts in RabbitMq Mock.Arrange(() => _queueIntegration.PostMessage(Arg.AnyString)).DoInstead(() => { }); }
public async Task WhenCallingGetMethod_PassingAValidStockName_ShouldReturnTheExpectedSucessMessage() { //Arrange var stockName = "T.US"; var stockValue = 29.30f; var expectedMessage = $"{stockName} quote is ${stockValue} per share."; var expectedTimesCalledWithExpectedMessage = 1; var header = new List <string> { "header0", "header1", "header2", "header3", "header4", "header5", "Close", }; var stockInfo = new List <string> { "name", "non-used", "non-used", "non-used", "non-used", "non-used", stockValue.ToString(), }; Mock.Arrange(() => _stockFileInfoIntegration.GetStockInfoFile(Arg.AnyString)).TaskResult((header, stockInfo)); // Call await _controller.Get(new StockConsumerRequest { StockName = stockName }); var timesCalled = Mock.GetTimesCalled(() => _queueIntegration.PostMessage(expectedMessage)); // Assert Assert.AreEqual(expectedTimesCalledWithExpectedMessage, timesCalled); }