Example #1
0
        public async Task BuyLotteryTicket_Should_Return_Ok()
        {
            // Arrange
            var ticketViewModel = new BuyLotteryTicketViewModel
            {
                LotteryId = 1,
                Tickets   = 5
            };

            var ticketDto = new BuyLotteryTicketDto
            {
                LotteryId = 1,
                Tickets   = 5
            };

            _mapper.Map <BuyLotteryTicketViewModel, BuyLotteryTicketDto>(ticketViewModel).Returns(ticketDto);

            // Act
            var response = await _lotteryController.BuyLotteryTicket(ticketViewModel);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <OkResult>(response);
            await _lotteryService.Received(1).BuyLotteryTicketAsync(ticketDto, UserAndOrganizationArg);
        }
Example #2
0
        public async Task BuyLotteryTicket_Should_Return_Bad_Request()
        {
            // Arrange
            var ticketViewModel = new BuyLotteryTicketViewModel
            {
                LotteryId = 1,
                Tickets   = 5
            };

            var ticketDto = new BuyLotteryTicketDto
            {
                LotteryId = 1,
                Tickets   = 5
            };

            _mapper.Map <BuyLotteryTicketViewModel, BuyLotteryTicketDto>(ticketViewModel).Returns(ticketDto);

            _lotteryService.BuyLotteryTicketAsync(ticketDto, UserAndOrganizationArg).Throws(new LotteryException("Exception"));

            // Act
            var response = await _lotteryController.BuyLotteryTicket(ticketViewModel);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(response);
            await _lotteryService.Received(1).BuyLotteryTicketAsync(ticketDto, UserAndOrganizationArg);
        }
Example #3
0
        public async Task <IHttpActionResult> BuyLotteryTicket(BuyLotteryTicketViewModel lotteryTickets)
        {
            try
            {
                var buyLotteryTicket = _mapper.Map <BuyLotteryTicketViewModel, BuyLotteryTicketDto>(lotteryTickets);
                await _lotteryService.BuyLotteryTicketAsync(buyLotteryTicket, GetUserAndOrganization());

                return(Ok());
            }
            catch (LotteryException ex)
            {
                return(BadRequest(ex.Message));
            }
        }