Exemplo n.º 1
0
        public async Task <IActionResult> Balance()
        {
            int cardId = _sessionManager.GetSessionCardId(HttpContext).Value;
            var result = await _terminalService.GetCreditCardDetailsByIdAsync(cardId);

            return(View(result));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }