public override bool Validate() { Program app = Program.GetInstance(); ShowService showService = app.GetService <ShowService>("shows"); UserService userService = app.GetService <UserService>("users"); ChairService chairService = app.GetService <ChairService>("chairs"); ReservationService reservationService = app.GetService <ReservationService>("reservations"); // Make sure the show exists Show show = showService.GetShowById(showId); if (show == null) { AddError("showId", "Ongeldige voorstelling"); return(false); } // Make sure the user exists User user = userService.GetUserById(userId); if (user == null) { AddError("userId", "Ongeldige gebruiker"); return(false); } // Make sure the chair exists Chair chair = chairService.GetChairById(chairId); if (chair == null) { AddError("chairId", "Ongeldige stoel"); return(false); } // Make sure the chair belongs to this room if (chair.roomId != show.roomId) { AddError("chairId", "De gekozen stoel hoort niet bij de gekozen zaal"); return(false); } // Make sure the chair hasn't been taken if (reservationService.IsChairTaken(chair, show)) { AddError("chairId", "De gekozen stoel is niet beschikbaar"); return(false); } return(true); }
public void GetChairByIdWhereIdDoesNotExistExpectExeption() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); mockChairRepo.Setup(x => x.GetChair(It.IsAny <int>())).Returns <int>(arg => null); IChairService chairService = new ChairService(mockChairRepo.Object); // Test Chair gottanChair = null; Assert.Throws <ArgumentException>(() => gottanChair = chairService.GetChairById(1)); Assert.Null(gottanChair); }
public void GetChairById() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); var testChair = new Chair() { Id = 1, Name = "Im the testChair", Price = 1 }; mockChairRepo.Setup(x => x.GetChair(It.IsAny <int>())).Returns <int>(arg => testChair); IChairService chairService = new ChairService(mockChairRepo.Object); // Test Chair gottanChair = chairService.GetChairById(1); Assert.NotNull(gottanChair); Assert.Equal(testChair, gottanChair); }
// Returns the chair public Chair GetChair() { ChairService chairService = Program.GetInstance().GetService <ChairService>("chairs"); return(chairService.GetChairById(chairId)); }