public async Task ReturnFailureWhenConcertDoesNotExist()
        {
            var concertRepo = SetupConcertRepoWithNoConcert();
            var service = new SellTicketsService(
                concertRepo, 
                Mock.Of<IBuyerRepository>(),
                Mock.Of<ITicketsService>(), 
                Mock.Of<IPublishEvents>());

            var purchaseResult = await service.SellTickets(_request);

            Assert.True(purchaseResult.IsFailure);
            Assert.Equal(Errors.ConcertNotFound, purchaseResult.Error);
        }
        public async Task PublishFailureWhenSellingTicketsFails()
        {
            var concertRepo = SetupConcertRepoWithNoConcert();
            var publisherMock = new Mock<IPublishEvents>();
            var service = new SellTicketsService(
                concertRepo,
                Mock.Of<IBuyerRepository>(),
                Mock.Of<ITicketsService>(),
                publisherMock.Object);

            var purchaseResult = await service.SellTickets(_request);

            Assert.True(purchaseResult.IsFailure);
            publisherMock.Verify(publisher => publisher.Publish(It.IsAny<PurchaseFailedEvent>()), Times.Once);
        }
        public async Task ReturnSuccessWhenSellingTicketsSucceeds()
        {
            var concertRepo = SetupConcertRepoWithConcert();
            var buyerRepo = SetupBuyerRepoWithBuyer();
            var purchase = BuildPurchase();
            var ticketService = SetupTicketsServiceWhichSucceedsWithPurchase(purchase);
            var service = new SellTicketsService(
                concertRepo,
                buyerRepo,
                ticketService,
                Mock.Of<IPublishEvents>());

            var purchaseResult = await service.SellTickets(_request);

            Assert.True(purchaseResult.IsSuccess);
            Assert.Equal(purchase, purchaseResult.Value);
        }
        public async Task ReturnFailureWhenSellingTicketsFails()
        {
            var concertRepo = SetupConcertRepoWithConcert();
            var buyerRepo = SetupBuyerRepoWithBuyer();
            var error = "some error occured";
            var ticketService = SetupTicketsServiceWhichFailsWithError(error);
            var service = new SellTicketsService(
                concertRepo,
                buyerRepo,
                ticketService,
                Mock.Of<IPublishEvents>());

            var purchaseResult = await service.SellTickets(_request);

            Assert.True(purchaseResult.IsFailure);
            Assert.Equal(error, purchaseResult.Error);
        }
        public async Task PublicSuccessWhenSellingTicketsSucceeds()
        {
            var concertRepo = SetupConcertRepoWithConcert();
            var buyerRepo = SetupBuyerRepoWithBuyer();
            var purchase = BuildPurchase();
            var ticketService = SetupTicketsServiceWhichSucceedsWithPurchase(purchase);
            var publisherMock = new Mock<IPublishEvents>();
            var service = new SellTicketsService(
                concertRepo,
                buyerRepo,
                ticketService,
                publisherMock.Object);

            var purchaseResult = await service.SellTickets(_request);

            Assert.True(purchaseResult.IsSuccess);
            publisherMock.Verify(publisher => publisher.Publish(It.IsAny<PurchaseSuccessfullyMadeEvent>()), Times.Once);
        }