public void GetXMLTest() { //Arrange CurrencyClient currencyClient = new CurrencyClient(); //Act string result = currencyClient.GetXML("31.03.2021"); //Assert Assert.Contains("USD", result); }
public void GetXMLNullTest() { //Arrange CurrencyClient currencyClient = new CurrencyClient(); //Act Action act = () => currencyClient.GetXML(null); //Assert Exception exception = Assert.Throws <ArgumentNullException>(act); Assert.Equal("Value cannot be null. (Parameter 'date')", exception.Message); }
public async Task Execute(Message message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } DateTime dateTime; CurrencyClient currencyClient = new CurrencyClient(); var chatId = message.Chat.Id; var messageId = message.MessageId; var match = new Regex(@"\d{2}.\d{2}.\d{4}").Matches(message.Text).FirstOrDefault(); if (match != null && DateTime.TryParse(match.Value, out dateTime)) { var xml = currencyClient.GetXML(dateTime.Date.ToString()); var valuteName = new Regex(@"\b[a-zA-Z]{3}\b").Matches(message.Text).FirstOrDefault(); if (valuteName == null) { valuteName = new Regex(@"\b[a-zA-Z]{1}\d{5}\b").Matches(message.Text).FirstOrDefault(); if (valuteName == null) { await _client.SendTextMessageAsync(chatId, "Can't parse valute name", replyToMessageId : messageId); return; } } currencyClient.ValCurs = currencyClient.ParseValute(xml); var rate = ""; foreach (var item in currencyClient.ValCurs.Valutes) { if (item.ID == valuteName.Value.ToUpper() || item.CharCode == valuteName.Value.ToUpper()) { rate = item.Value.ToString(); break; } } if (rate == "") { await _client.SendTextMessageAsync(chatId, "Valute name or code isn't correct", replyToMessageId : messageId); } else { await _client.SendTextMessageAsync(chatId, rate, replyToMessageId : messageId); } } else { await _client.SendTextMessageAsync(chatId, "Can't parse date", replyToMessageId : messageId); } }
public void ParseValuteTest() { //Arrange CurrencyClient currencyClient = new CurrencyClient(); string expectedName = "Foreign Currency Market"; string expectedDate = "31.03.2021"; var expectedValutesType = typeof(List <Valute>); //Act var result = currencyClient.ParseValute(currencyClient.GetXML("31.03.2021")); //Assert Assert.Equal(expectedDate, result.Date); Assert.Equal(expectedName, result.Name); Assert.IsType(expectedValutesType, result.Valutes); }