public async Task <ActionResult <QueryResponse <QueryTicketModel> > > GetTicketsByCustomer(int customerId, int page, int pageSize)
        {
            var query = new GetCustomerTicketsQuery(customerId, page, pageSize)
            {
                CustomerId = customerId
            };
            var tickets = _ticketQueryHandler.HandleAsync(query);

            return(tickets);
        }
        public async Task BuyTicket_ShouldBuyTicket()
        {
            //Arrange
            var handler            = new TicketQueryHandler();
            var ticketsFromHandler = await handler.HandleAsync(new TicketQuery());

            var ticketsFromHandlerCount = ticketsFromHandler.ToList().Count;

            var firstCompetitionFromDatabase = this.context.Competitions.FirstOrDefault();
            var firstCompetitorFromDatabase  = this.context.Competitors.FirstOrDefault();
            var firstGamblerFromDatabase     = this.context.Gamblers.FirstOrDefault();

            //Act - do something
            BuyTicketCommand command = new BuyTicketCommand
            {
                Id                = Guid.NewGuid(),
                CompetitionId     = firstCompetitionFromDatabase.Id,
                CompetitorId      = firstCompetitorFromDatabase.Id,
                GamblerId         = firstGamblerFromDatabase.Id,
                IsPaymentReceived = false
            };


            //Assert - check results
            try
            {
                await buyTicketHandler.HandleAsync(command);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
        public async Task <IActionResult> Tickets()
        {
            var handler            = new TicketQueryHandler();
            var ticketsFromHandler = await handler.HandleAsync(new TicketQuery());

            var tickets = ticketsFromHandler.ToList();

            return(View(model: tickets));
        }
        public async Task TicketsCount_ShouldReturnTicketsCount()
        {
            //Arrange
            var handler            = new TicketQueryHandler();
            var ticketsFromHandler = await handler.HandleAsync(new TicketQuery());

            var tickets = ticketsFromHandler.ToList();

            //Act - do something
            var ticketsFromHandlerCount = ticketsFromHandler.ToList().Count;

            var ticketsFromDatabaseCount = this.context.Tickets.Count();

            //Assert - check results
            Assert.AreEqual(ticketsFromHandlerCount, ticketsFromDatabaseCount);
        }
Ejemplo n.º 5
0
        public async Task RegisterGambler_ShouldRegisterGambler()
        {
            //Arrange
            var handler             = new TicketQueryHandler();
            var gamblersFromHandler = await handler.HandleAsync(new TicketQuery());

            var gamblersFromHandlerCount = gamblersFromHandler.ToList().Count;

            //Act - do something

            CreateGamblerCommand command = new CreateGamblerCommand
            {
                Id   = Guid.NewGuid(),
                Name = "Mikey"
            };

            await createGamblerHandler.HandleAsync(command);

            var gamblersFromDatabaseCount = this.context.Gamblers.Count();

            Assert.AreNotEqual(gamblersFromDatabaseCount, gamblersFromHandlerCount);
        }