コード例 #1
0
        public void FailToIssueTicketsWhenThereAreNotEnoughOfThem()
        {
            var concert        = new Concert("Test concert", new TicketQuantity(3));
            var wantedQuantity = new TicketQuantity(5);

            var tickets = concert.IssueTickets(wantedQuantity);

            Assert.True(tickets.IsFailure);
            Assert.Equal(Errors.NoEnoughTickets, tickets.Error);
        }
コード例 #2
0
        public void IssueTicketsWhenThereAreEnoughOfThem()
        {
            var concert        = new Concert("Test concert", new TicketQuantity(10));
            var wantedQuantity = new TicketQuantity(5);

            var tickets = concert.IssueTickets(wantedQuantity);

            Assert.True(tickets.IsSuccess);
            Assert.Equal(5, tickets.Value.Quantity.Value);
        }
コード例 #3
0
        public Result <Purchase> SellTickets(IConcert concert, TicketsBuyer buyer, TicketQuantity quantity)
        {
            var ticketsResult = concert.IssueTickets(quantity);

            return(ticketsResult
                   .Map(tickets => {
                buyer.AddPurchase(tickets);
                return new Purchase(buyer, tickets);
            }));
        }
コード例 #4
0
        public void UpdateTicketsSoldWhenIssuingTickets()
        {
            var concert              = new Concert("Test concert", new TicketQuantity(10));
            var firstWantedQuantity  = new TicketQuantity(5);
            var secondWantedQuantity = new TicketQuantity(3);

            concert.IssueTickets(firstWantedQuantity);
            concert.IssueTickets(secondWantedQuantity);

            Assert.Equal(8, concert.TicketsSold);
        }
コード例 #5
0
        public void AddTicketsToBuyerWhenIssuingTicketsSucceeds()
        {
            var tickets        = BuildTickets();
            var concert        = SetUpConcertWhichIssueTickets(tickets);
            var buyer          = new TicketsBuyer("1", "Buyer name");
            var wantedQuantity = new TicketQuantity(5);
            var service        = new TicketsService();

            service.SellTickets(concert, buyer, wantedQuantity);

            Assert.NotEmpty(buyer.Purchases);
        }
コード例 #6
0
        public void ReturnFailureWhenIssuingTicketsFails()
        {
            var errorMessage   = "Some error occured";
            var concert        = SetUpConcertWhichDoesNotIssueTickets(errorMessage);
            var buyer          = new TicketsBuyer("1", "Buyer name");
            var wantedQuantity = new TicketQuantity(5);
            var service        = new TicketsService();

            var purchase = service.SellTickets(concert, buyer, wantedQuantity);

            Assert.True(purchase.IsFailure);
            Assert.Equal(errorMessage, purchase.Error);
        }
コード例 #7
0
        public void ReturnPurchaseWhenIssuingTicketsSucceeds()
        {
            var tickets        = BuildTickets();
            var concert        = SetUpConcertWhichIssueTickets(tickets);
            var buyer          = new TicketsBuyer("1", "Buyer name");
            var wantedQuantity = new TicketQuantity(5);
            var service        = new TicketsService();

            var purchase = service.SellTickets(concert, buyer, wantedQuantity);

            Assert.True(purchase.IsSuccess);
            Assert.Equal(buyer.Id, purchase.Value.Buyer.Id);
            Assert.Equal(tickets, purchase.Value.Tickets);
        }
コード例 #8
0
 public Tickets(Concert concert, TicketQuantity quantity)
 {
     Concert  = concert;
     Quantity = quantity;
 }
コード例 #9
0
 public override string ToString()
 {
     return($"Reservation:\n\tid: {Id.ToString()}\n\tperformance id: {PerformanceId.ToString()}\n\tdate of reservation: {Date.Day.ToString()}/{Date.Month.ToString()}/{Date.Year.ToString()}" +
            $"\n\tnumber of tickets:{TicketQuantity.ToString()}\n\tstate of reservation: {State.ToString()}\n\n");
 }
コード例 #10
0
 public string Write()
 {
     return($"{Id.ToString()};{PerformanceId.ToString()};{Date.Day.ToString()}/{Date.Month.ToString()}/{Date.Year.ToString()};{TicketQuantity.ToString()};{State.ToString()};{Environment.NewLine}");
 }