public void Setup() { var data2 = new List <Genre> //Genres { new Genre { Id = 1, Name = "Genre 1" }, new Genre { Id = 2, Name = "Genre 2" }, new Genre { Id = 3, Name = "Genre 3" }, }.AsQueryable(); mockDBSetGenres = new Mock <DbSet <Genre> >(); mockDBSetGenres.As <IQueryable <Genre> >().Setup(m => m.Provider).Returns(data2.Provider); mockDBSetGenres.As <IQueryable <Genre> >().Setup(m => m.Expression).Returns(data2.Expression); mockDBSetGenres.As <IQueryable <Genre> >().Setup(m => m.ElementType).Returns(data2.ElementType); mockDBSetGenres.As <IQueryable <Genre> >().Setup(m => m.GetEnumerator()).Returns(data2.GetEnumerator()); mockContext = new Mock <LibraryContext>(); mockContext.Setup(c => c.Genres).Returns(mockDBSetGenres.Object); genreBusiness = new GenreBusiness(mockContext.Object); }
public void GetGamesListByPlatform_Test() { GenreBusiness.Fill(); var games = APIFunctions.GetGamesListByPlatform("6", "", ""); Assert.IsNotNull(games); }
private void buttonDelete_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count < 1) { return; } Genre genre = (Genre)dataGridView.SelectedRows[0].Tag; if (MessageBox.Show(string.Format("Do you want do delete the genre {0} ?", genre.Name), "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } int romCount = RomBusiness.GetAll().Where(x => x.Genre == genre).Count(); if (romCount > 0) { FormCustomMessage.ShowError(string.Format("The genre {0} is associated with {1} roms. You cannot delete it.", genre.Name, romCount)); return; } foreach (DataGridViewRow item in dataGridView.SelectedRows) { GenreBusiness.Delete(item.Cells[0].Value.ToString()); dataGridView.Rows.Remove(item); } Updated = true; Clean(); }
public void GetGameDetails_Test() { GenreBusiness.Fill(); var access = ""; var games = APIFunctions.GetGameDetails("136", new Platform(), out access); Assert.IsNotNull(games); }
public void GetGameByName_Test() { GenreBusiness.Fill(); var access = ""; var games = APIFunctions.GetGameByName("136", "Super Mario World", out access); Assert.IsNotNull(games); }
private void LoadComboBoxGenres() { List <Genre> genres = GenreBusiness.GetAll(); genres.Insert(0, new Genre()); comboBoxGenre.DataSource = genres; comboBoxGenre.DisplayMember = "Name"; comboBoxGenre.ValueMember = "Name"; }
public void GetGameArtUrls_Test() { GenreBusiness.Fill(); string box, title, gameplay = ""; var access = ""; var result = APIFunctions.GetGameArtUrls("136", out box, out title, out gameplay, out access); Assert.IsTrue(result); Assert.IsNotNull(box); Assert.IsNotNull(title); Assert.IsNotNull(gameplay); }
private void changeGenreToolStripMenuItem_Click(object sender, EventArgs e) { try { Genre selected = null; if (!FormChoose.ChooseGenre(out selected)) { return; } List <Rom> romList = new List <Rom>(); foreach (DataGridViewRow row in dataGridView.SelectedRows) { romList.Add((Rom)row.Tag); } GenreBusiness.ChangeRomsGenre(romList, selected); foreach (DataGridViewRow row in dataGridView.SelectedRows) { Rom rom = (Rom)row.Tag; if (rom.Genre != null) { row.Cells[columnGenre.Index].Value = rom.Genre.Name; row.Cells[columnGenre.Index].Style.BackColor = rom.Genre.Color; row.Cells[columnGenre.Index].Style.ForeColor = Functions.SetFontContrast(rom.Genre.Color); } else { row.Cells[columnGenre.Index].Value = ""; row.Cells[columnGenre.Index].Style.BackColor = Color.White; row.Cells[columnGenre.Index].Style.ForeColor = Color.Black; } } dataGridView.Refresh(); } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
private FormChoose(Type type) : this() { selectedType = type; if (type == typeof(RomLabel)) { List <RomLabel> labels = RomLabelBusiness.GetAll(); labels.Insert(0, new RomLabel()); comboBox.DataSource = labels; comboBox.DisplayMember = "Name"; comboBox.ValueMember = "Name"; labelChoose.Text = "Choose Label"; this.Text = "Choose Label"; buttonCancel.Visible = false; buttonClose.Text = "Cancel and close"; buttonAdd.Text = "Save and close"; } else if (type == typeof(Genre)) { List <Genre> genres = GenreBusiness.GetAll(); genres.Insert(0, new Genre()); comboBox.DataSource = genres; comboBox.DisplayMember = "Name"; comboBox.ValueMember = "Name"; labelChoose.Text = "Choose Genre"; this.Text = "Choose Genre"; buttonCancel.Visible = false; buttonClose.Text = "Cancel and close"; buttonAdd.Text = "Save and close"; } else if (type == typeof(string)) { var status = Values.Status.ToArray().ToList(); status.Insert(0, ""); comboBox.DataSource = status; labelChoose.Text = "Choose Status"; this.Text = "Choose Status"; buttonCancel.Visible = false; buttonClose.Text = "Cancel and close"; buttonAdd.Text = "Save and close"; } }
private void FormGenre_Load(object sender, EventArgs e) { buttonAdd.Click += buttonAdd_Click; buttonDelete.Click += buttonDelete_Click; buttonCancel.Click += buttonCancel_Click; updating = true; dataGridView.ClearSelection(); dataGridView.Rows.Clear(); List <Genre> genres = GenreBusiness.GetAll(); foreach (Genre genre in genres) { AddToGrid(genre, -1); } updating = false; Clean(); }
private void buttonAdd_Click(object sender, EventArgs e) { updating = true; Genre genre = null; int index = -1; if (string.IsNullOrEmpty(textBoxName.Text.Trim())) { FormCustomMessage.ShowError("Can not save without a valid name."); return; } if (textBoxName.Enabled) { if (GenreBusiness.Get(textBoxName.Text.Trim()) != null) { FormCustomMessage.ShowError("This genre already exists."); return; } genre = new Genre(); } else { DataGridViewRow row = dataGridView.SelectedRows[0]; index = row.Index; genre = (Genre)row.Tag; textBoxName.Enabled = true; buttonAdd.Text = "Add"; } genre.Name = textBoxName.Text.Trim(); genre.Color = buttonColor.BackColor; AddToGrid(genre, index); GenreBusiness.Set(genre); updating = false; Updated = true; Clean(); }
private void FillGenreFilter(string genre = "") { updating = true; List <Genre> genres = GenreBusiness.GetAll(); genres.Insert(0, new Genre()); genres.Insert(1, new Genre() { Name = "<none>" }); comboBoxGenre.DataSource = genres.Select(x => x.Name).ToList(); if (genre == "") { comboBoxGenre.SelectedIndex = 0; } else { comboBoxGenre.Text = genre; } updating = false; }
private void buttonSync_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(textBoxXMLPath.Text)) { FormCustomMessage.ShowError("Load the XML file first"); return; } if (!File.Exists(textBoxXMLPath.Text)) { FormCustomMessage.ShowError("Invalid file path"); return; } if (string.IsNullOrEmpty(comboBoxPlatform.Text)) { FormCustomMessage.ShowError("Choose a platform"); return; } XmlDocument doc = new XmlDocument(); doc.Load(textBoxXMLPath.Text); var roms = RomBusiness.GetAll().Where(x => x.Platform != null && x.Platform.Name == comboBoxPlatform.Text).ToList(); XmlNode list = doc.ChildNodes[1]; int count = 0; Dictionary <string, Rom> romsDic = new Dictionary <string, Rom>(); Dictionary <string, XmlNode> nodesDic = new Dictionary <string, XmlNode>(); string name = ""; foreach (var item in roms) { name = RomFunctions.TrimRomName(item.Name); if (!romsDic.ContainsKey(name)) { romsDic.Add(name, item); } } foreach (XmlNode node in list) { name = RomFunctions.TrimRomName(node.ChildNodes[1].InnerText); if (!nodesDic.ContainsKey(name)) { nodesDic.Add(name, node); } } foreach (string node in nodesDic.Keys) { if (!romsDic.ContainsKey(node)) { continue; } var rom = romsDic[node]; XmlNode selectedNode = nodesDic[node]; bool updated = false; if (rom != null) { foreach (XmlNode childNode in selectedNode.ChildNodes) { if (childNode.Name == "releasedate") { if (string.IsNullOrEmpty(rom.YearReleased) && !string.IsNullOrEmpty(selectedNode.InnerText) && selectedNode.InnerText.Length > 3) { rom.YearReleased = childNode.InnerText.Substring(0, 4); updated = true; } } else if (childNode.Name == "name") { if (string.IsNullOrEmpty(rom.DBName)) { rom.DBName = childNode.InnerText; updated = true; } } else if (childNode.Name == "desc") { if (string.IsNullOrEmpty(rom.Description)) { rom.Description = childNode.InnerText; updated = true; } } else if (childNode.Name == "publisher") { if (string.IsNullOrEmpty(rom.Publisher)) { rom.Publisher = childNode.InnerText; updated = true; } } else if (childNode.Name == "developer") { if (string.IsNullOrEmpty(rom.Developer)) { rom.Developer = childNode.InnerText; updated = true; } } else if (childNode.Name == "genre") { var genrename = childNode.InnerText; if (rom.Genre == null && !string.IsNullOrEmpty(genrename)) { updated = true; var genre = GenreBusiness.Get(genrename); if (genre == null) { //genre = RomFunctions.CreateNewGenre(genrename); } else { rom.Genre = genre; } } } } if (updated) { count++; Updated = true; } } } RomBusiness.SetRom(roms); FormCustomMessage.ShowSuccess(count + " roms updated"); } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
public GenreDisplay() { genreBusiness = new GenreBusiness(); Input(); }