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); }
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); }
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); })); }
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); }
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); }
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); }
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); }
public Tickets(Concert concert, TicketQuantity quantity) { Concert = concert; Quantity = quantity; }
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"); }
public string Write() { return($"{Id.ToString()};{PerformanceId.ToString()};{Date.Day.ToString()}/{Date.Month.ToString()}/{Date.Year.ToString()};{TicketQuantity.ToString()};{State.ToString()};{Environment.NewLine}"); }