public void Index_Perfect() { // Arrange var fakeCurrencyList = new List <string>() { "HUF", "EUR" }; var fakeRepository = new FakeCurrencyRespository(); fakeRepository.currencyList = fakeCurrencyList; HomeController controller = new HomeController(fakeRepository); // Act var resultTask = controller.Index(); resultTask.Wait(); var viewtContent = (ViewResult)resultTask.Result; var viewCurrencyList = viewtContent.ViewData.Values.First() as ICollection <string>; // Assert Assert.IsNotNull(viewtContent); Assert.AreEqual(fakeCurrencyList.Count, viewCurrencyList.Count); Assert.AreEqual(fakeCurrencyList[0], viewCurrencyList.ToList()[0]); Assert.AreEqual(fakeCurrencyList[1], viewCurrencyList.ToList()[1]); }
public void History_Perfect() { // Arrange var currency = "ANY"; var fakeHistory = new List <CurrencyRate>() { new CurrencyRate() { Rate = 1, Timestamp = DateTime.Now } }; var fakeRepository = new FakeCurrencyRespository(); fakeRepository.history = fakeHistory; var controller = new CurrencyController(fakeRepository); // Act var historyTask = controller.History(currency); historyTask.Wait(); var historyContent = (JsonResult <IEnumerable <CurrencyRate> >)historyTask.Result; var historyList = new List <CurrencyRate>(historyContent.Content); // Assert Assert.IsNotNull(historyContent); Assert.AreEqual(fakeHistory.Count, historyList.Count); Assert.AreEqual(fakeHistory[0].Rate, historyList[0].Rate); Assert.AreEqual(fakeHistory[0].Timestamp, historyList[0].Timestamp); }
public void Convert_Perfect() { // Arrange var fakeLatestRates = new Dictionary <string, decimal>() { { "HUF", 2 }, { "USD", 1 } }; var fakeRepository = new FakeCurrencyRespository(); fakeRepository.latestRates = fakeLatestRates; var controller = new ExchangeController(fakeRepository); // Act var convertTask = controller.Convert("10", "HUF", "USD"); convertTask.Wait(); var convertContent = (JsonResult <Decimal>)convertTask.Result; // Assert Assert.IsNotNull(convertContent); Assert.AreEqual(5, convertContent.Content); }