public async Task <IActionResult> Balance() { int cardId = _sessionManager.GetSessionCardId(HttpContext).Value; var result = await _terminalService.GetCreditCardDetailsByIdAsync(cardId); return(View(result)); }
public async Task GetCreditCardDetailsByIdAsync_ShouldThrowArgNullEx() { // Arrange int?cardId = new int?(); var terminalService = new TerminalService(GetCardRepoMock().Object, null, null); // Act Func <Task> action = async() => await terminalService.GetCreditCardDetailsByIdAsync(cardId); // Assert Exception ex = await Assert.ThrowsAsync <ArgumentNullException>(action); }
public async Task GetCreditCardDetailsByIdAsync_ShouldThrowInvalOpEx() { // Arrange int cardId = SampleData.CREDITCARDS.First(c => !c.IsValid).Id; var terminalService = new TerminalService(GetCardRepoMock().Object, null, null); // Act Func <Task> action = async() => await terminalService.GetCreditCardDetailsByIdAsync(cardId); // Assert Exception ex = await Assert.ThrowsAsync <InvalidOperationException>(action); Assert.Equal("Card is invalid", ex.Message); }
public async Task GetCreditCardDetailsByIdAsync_ShouldThrowArgEx() { // Arrange int cardId = SampleData.CARD_NOT_ON_THE_LIST.Id; var terminalService = new TerminalService(GetCardRepoMock().Object, null, null); // Act Func <Task> action = async() => await terminalService.GetCreditCardDetailsByIdAsync(cardId); // Assert Exception ex = await Assert.ThrowsAsync <ArgumentException>(action); Assert.Equal("Card with this ID doesn't exist", ex.Message); }
public async Task GetCreditCardDetailsByIdAsync_ShouldReturnView() { // Arrange var card = SampleData.CREDITCARDS.First(); int cardId = card.Id; var expectedView = new CreditCardBalanceViewModel { Number = card.Number, Balance = card.Balance }; int count = 0; var loggerMock = GetActionRepoMock(() => { count++; }); var terminalService = new TerminalService( GetCardRepoMock().Object, loggerMock.Object, null); // Act var result = await terminalService.GetCreditCardDetailsByIdAsync(cardId); // Assert Assert.Equal(expectedView.Number, result.Number); Assert.Equal(expectedView.Balance, result.Balance); Assert.True(count > 0); }