public void GetChairsPaged() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); List <Chair> chairsFull = new List <Chair>(); for (int i = 1; i < 30; i++) { chairsFull.Add(new Chair() { Id = i }); } mockChairRepo.Setup(x => x.GetChairs()).Returns(() => chairsFull); IChairService chairService = new ChairService(mockChairRepo.Object); //Test var page = 1; var itemsOnPage = 10; var chairsPaged = chairService.GetChairsPaged(page, itemsOnPage); Assert.Equal(itemsOnPage, chairsPaged.Count); Assert.Equal(1, chairsPaged[0].Id); Assert.Equal(10, chairsPaged[9].Id); }
private void DeleteButton_Click(object sender, EventArgs args) { Program app = Program.GetInstance(); ChairService chairManager = app.GetService <ChairService>("chairs"); // Find the chair Chair chair = chairManager.GetChairByRoomAndPosition(room, row, column); if (chair == null) { GuiHelper.ShowError("Er bestaat geen stoel op deze positie"); return; } // Ask for confirmation if (!GuiHelper.ShowConfirm("Weet je zeker dat je deze stoel wilt verwijderen?")) { return; } // Delete it if (!chairManager.DeleteChair(chair)) { GuiHelper.ShowError("Kon stoel niet verwijderen"); return; } saveButton.Text = "Stoel aanmaken"; deleteButton.Enabled = false; GuiHelper.ShowInfo("Stoel succesvol verwijderd"); }
public void CreateValidChairTest() { //Setup Dictionary <int, Chair> chairs = new Dictionary <int, Chair>(); int Id = 1; Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); mockChairRepo.Setup(x => x.AddChair(It.IsAny <Chair>())).Returns <Chair>(arg => InsertIntoDictionaryAndAddId(Id, chairs, arg)); IChairService chairService = new ChairService(mockChairRepo.Object); Chair validChair = new Chair() { Name = "someName", Price = 1 }; //Test Chair chair = chairService.AddChair(validChair); Assert.Single(chairs); // cheks if there as been added ONE chair to the "Repositorie" Assert.NotNull(chair); Assert.Equal(Id, chair.Id); // cheks if the returned chair has the given id Assert.Equal(chairs[Id], chair); }
private void AddButton_Click(object sender, EventArgs args) { Program app = Program.GetInstance(); ChairService chairManager = app.GetService <ChairService>("chairs"); // Find or create chair Chair chair = chairManager.GetChairByRoomAndPosition(room, row, column); bool isNew = false; if (chair == null) { chair = new Chair(room.id, row, column, 0, "default"); isNew = true; } chair.price = (double)priceInput.Value; // Save chair if (!chairManager.SaveChair(chair)) { GuiHelper.ShowError(ValidationHelper.GetErrorList(chair)); return; } saveButton.Text = "Stoel opslaan"; deleteButton.Enabled = true; GuiHelper.ShowInfo("Stoel succesvol " + (isNew ? "aangemaakt" : "aangepast")); }
void ChairButton_Click(object sender, EventArgs e, string buttonString) { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); ReservationService reservationService = app.GetService <ReservationService>("reservations"); ReservationCreate reservationScreen = app.GetScreen <ReservationCreate>("reservationCreate"); // Parse button data string[] parts = buttonString.Replace("button", "").Split('-'); int row = ValidationHelper.ParseInt(parts[0]); int col = ValidationHelper.ParseInt(parts[1]); // Get chair Chair chair = chairService.GetChairByRoomAndPosition(show.GetRoom(), row, col); if (reservationService.IsChairTaken(chair, show) || reservationScreen.ContainsChair(chair)) { GuiHelper.ShowError("Deze stoel is niet beschikbaar"); return; } reservationScreen.AddChair(chair); // Redirect to screen app.ShowScreen(reservationScreen); }
public void GetChairsPagedWithZeroPagesAndItemsExpectExeption() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); IChairService chairService = new ChairService(mockChairRepo.Object); //Test Assert.Throws <InvalidDataException>(() => chairService.GetChairsPaged(1, 0)); Assert.Throws <InvalidDataException>(() => chairService.GetChairsPaged(0, 1)); }
public void DeleteChair() { Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); mockChairRepo.Setup(x => x.GetChair(It.IsAny <int>())).Returns(() => new Chair()); IChairService chairService = new ChairService(mockChairRepo.Object); chairService.DeleteChair(1); mockChairRepo.Verify(m => m.DeleteChair(1), Times.Once()); }
private void SaveButton_Click(object sender, EventArgs e) { Program app = Program.GetInstance(); ChairService chairManager = app.GetService <ChairService>("chairs"); RoomService roomManager = app.GetService <RoomService>("rooms"); // Create bulk update BulkUpdate bulkUpdate = new BulkUpdate(); bulkUpdate.Begin(); // Save room Room room = new Room((int)numberInput.Value); if (!roomManager.SaveRoom(room)) { GuiHelper.ShowError(ValidationHelper.GetErrorList(room)); return; } // Disable save button saveButton.Enabled = false; // Create chairs int rows = (int)rowInput.Value; int columns = (int)columnInput.Value; double price = (double)priceInput.Value; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= columns; j++) { Chair chair = new Chair(room.id, i, j, price, "default"); if (!chairManager.SaveChair(chair)) { GuiHelper.ShowError(ValidationHelper.GetErrorList(room)); } } } // End bulk update bulkUpdate.End(); // Enable save button saveButton.Enabled = true; // Redirect to screen RoomDetail roomDetail = app.GetScreen <RoomDetail>("roomDetail"); roomDetail.SetRoom(room); app.ShowScreen(roomDetail); GuiHelper.ShowInfo("Zaal succesvol aangemaakt"); }
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 AddChairWithoutNameExpectExeption() { //Setup Mock <IChairRepository> mockChairRepo = new Mock <IChairRepository>(); IChairService chairService = new ChairService(mockChairRepo.Object); //Test var chair = new Chair() { Price = 1 }; Assert.Throws <InvalidDataException>(() => chairService.AddChair(chair)); mockChairRepo.Verify(m => m.AddChair(chair), Times.Never()); }
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 override void OnShow() { Program app = Program.GetInstance(); ChairService chairManager = app.GetService <ChairService>("chairs"); Chair chair = chairManager.GetChairByRoomAndPosition(room, row, column); base.OnShow(); columnValue.Text = "Kolom " + column; rowValue.Text = "Rij " + row; // Update price input priceInput.Value = chair != null ? (decimal)chair.price : 0; // Update save button saveButton.Text = chair != null ? "Stoel opslaan" : "Stoel aanmaken"; deleteButton.Enabled = chair != null; }
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); }
public override bool Validate() { Program app = Program.GetInstance(); RoomService roomService = app.GetService <RoomService>("rooms"); ChairService chairService = app.GetService <ChairService>("chairs"); // Make sure the room exists Room room = roomService.GetRoomById(roomId); if (room == null) { AddError("roomId", "Ongeldige zaal"); return(false); } // Make sure the row + number combo is unique Chair chair = chairService.GetChairByRoomAndPosition(room, row, number); if (chair != null && chair.id != id) { AddError("number", "Nummer moet uniek zijn voor de gekozen rij"); return(false); } // Make sure price is 0 or higher if (price < 0) { AddError("price", "Prijs mag niet negatief zijn"); return(false); } // Make a valid type was selected if (!TYPES.Contains(type)) { AddError("type", "Ongeldig type"); return(false); } return(true); }
// Returns all chairs that belong to this Room public List <Chair> GetChairs() { ChairService chairService = Program.GetInstance().GetService <ChairService>("chairs"); return(chairService.GetChairsByRoom(this)); }
public override void OnShow() { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); RoomService roomService = app.GetService <RoomService>("rooms"); MovieService movieservice = app.GetService <MovieService>("movies"); ShowService showService = app.GetService <ShowService>("shows"); base.OnShow(); title.Text = movie.name; descriptionInput.Text = movie.description; durationLabel.Text = "Speeltijd " + movie.duration + " Minuten"; genreLabel.Text = "Genre " + movie.genre; imagePreview.Image = movie.GetImage(); // Clear grid container.Controls.Clear(); container.RowStyles.Clear(); container.ColumnStyles.Clear(); // Prepare list int rowCount = 15; int columnCount = 5; container.ColumnCount = columnCount; container.RowCount = rowCount; for (int i = 0; i < columnCount; i++) { container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columnCount)); } for (int i = 0; i < rowCount; i++) { container.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / rowCount)); } // Build list List <Show> shows = showService.GetShowsByMovie(movie); List <Show> list = shows.Where(i => i.startTime > DateTime.Now).OrderBy(i => i.startTime).Take(rowCount * columnCount).ToList(); int rowIndex = 0; int columnIndex = 0; foreach (Show show in list) { Button button = new Button(); button.Text = show.startTime.ToString(Program.DATETIME_FORMAT); button.Name = "" + show.id; button.BackColor = Color.FromArgb(193, 193, 193); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ShowButton_Click(sender, e, show.id); }; container.Controls.Add(button, rowIndex, columnIndex); columnIndex += 1; if (columnIndex >= columnCount) { columnIndex = 0; rowIndex += 1; } } }
public override void OnShow() { base.OnShow(); Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); RoomService roomService = app.GetService <RoomService>("rooms"); MovieService movieservice = app.GetService <MovieService>("movies"); ShowService showService = app.GetService <ShowService>("shows"); title.Text = movie.name; descriptionInput.Text = movie.description; durationLabel.Text = "Speeltijd =" + movie.duration + " Minuten"; genreLabel.Text = "Genre = " + movie.genre; imagePreview.Image = movie.GetImage(); // Clear grid container.Controls.Clear(); container.RowStyles.Clear(); container.ColumnStyles.Clear(); // Print shows List <Show> shows = showService.GetShowsByMovie(movie); List <Show> list = shows.Where(i => i.startTime > DateTime.Now).OrderBy(i => i.startTime).ToList(); int maximum = list.Count; int rowCount = 15; int columnCount = 5; int showIndex = 0; container.ColumnCount = columnCount; container.RowCount = rowCount; for (int i = 0; i < columnCount; i++) { container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columnCount)); } for (int i = 0; i < rowCount; i++) { container.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / rowCount)); } for (int i = 0; i < rowCount && showIndex < list.Count; i++) { for (int j = 0; j < columnCount && showIndex < list.Count; j++) { Button button = new Button(); Show show = list[showIndex]; button.Text = show.startTime.ToString(Program.DATETIME_FORMAT); button.Name = "" + showIndex; button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ShowButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); showIndex += 1; } } }
// Returns the chair public Chair GetChair() { ChairService chairService = Program.GetInstance().GetService <ChairService>("chairs"); return(chairService.GetChairById(chairId)); }
public override void OnShow() { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); RoomService roomService = app.GetService <RoomService>("rooms"); ReservationService reservationService = app.GetService <ReservationService>("reservations"); ReservationCreate reservationCreate = app.GetScreen <ReservationCreate>("reservationCreate"); base.OnShow(); container.Controls.Clear(); container.RowStyles.Clear(); container.ColumnStyles.Clear(); // Get chairs and room size List <Chair> chairs = chairService.GetChairsByRoom(show.GetRoom()); int Maximum = chairs.Count; int highestRow = 0; int highestColum = 0; for (int x = 1; x < Maximum; x++) { if (highestRow < chairs[x].row) { highestRow = chairs[x].row; } if (highestColum < chairs[x].number) { highestColum = chairs[x].number; } } container.ColumnCount = highestColum; container.RowCount = highestRow; for (int i = 0; i < highestColum; i++) { container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / highestColum)); } for (int i = 0; i < highestRow; i++) { container.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / highestRow)); } for (int i = 0; i < highestRow; i++) { for (int j = 0; j < highestColum; j++) { Chair chair = chairService.GetChairByRoomAndPosition(show.GetRoom(), i + 1, j + 1); // Ignore if chair doesn't exist if (chair == null) { continue; } if (reservationService.IsChairTaken(chair, show) || reservationCreate.ContainsChair(chair)) { Button button = new Button(); button.Text = string.Format("Niet beschikbaar"); button.BackColor = Color.Red; button.Name = string.Format("button" + (i + 1) + "-" + (j + 1)); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ChairButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); } else { Button button = new Button(); button.Text = string.Format("R" + i + "-N" + j + " prijs: " + chair.price); button.BackColor = Color.Green; button.Name = string.Format("button" + (i + 1) + "-" + (j + 1)); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ChairButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); } } } }
public override void OnShow() { Program app = Program.GetInstance(); ChairService chairService = app.GetService <ChairService>("chairs"); RoomService roomService = app.GetService <RoomService>("rooms"); base.OnShow(); subTitle.Text = "Zaal " + room.number; container.Controls.Clear(); container.RowStyles.Clear(); container.ColumnStyles.Clear(); // Create grid List <Chair> chairs = chairService.GetChairsByRoom(room); int maximum = chairs.Count; int highestRow = 0; int highestColumn = 0; for (int x = 1; x < maximum; x++) { if (highestRow < chairs[x].row) { highestRow = chairs[x].row; } if (highestColumn < chairs[x].number) { highestColumn = chairs[x].number; } } container.ColumnCount = highestColumn; container.RowCount = highestRow; for (int i = 0; i < highestColumn; i++) { container.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / highestColumn)); } for (int i = 0; i < highestRow; i++) { container.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / highestRow)); } for (int i = 0; i < highestRow; i++) { for (int j = 0; j < highestColumn; j++) { Button button = new Button(); bool taken = chairService.GetChairByRoomAndPosition(room, i + 1, j + 1) != null; button.Text = string.Format(taken ? "{0}-{1}" : "Leeg", i + 1, j + 1); button.Name = string.Format("button" + (i + 1) + "-" + (j + 1)); button.Dock = DockStyle.Fill; button.Click += (sender, e) => { ChairButton_Click(sender, e, button.Name); }; container.Controls.Add(button, j, i); } } }