Exemplo n.º 1
0
        public void GetGenre_WhenMethodIsCall_ShouldReturnGenre()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "GetGenre").Options;

            var validationMock = new Mock <IValidations>();

            string genreName = "Genre";
            string book1     = "book1";
            string book2     = "book2";

            var authorBooks = new List <Book>();

            authorBooks.Add(new Book()
            {
                Title = book1
            });
            authorBooks.Add(new Book()
            {
                Title = book2
            });

            var genre = new Genre()
            {
                Id        = 1,
                GenreName = genreName,
                Books     = authorBooks
            };

            using (var arrangeContext = new LibrarySystemContext(contexInMemory))
            {
                arrangeContext.Genres.Add(genre);
                arrangeContext.SaveChanges();
            }

            GenreViewModel result;

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unitOfWork = new UnitOfWork(actContext);
                var service    = new GenreServices(unitOfWork, validationMock.Object);

                result = service.GetGenre(genreName);
            }

            // Assert
            Assert.AreEqual(genreName, result.GenreName);
            Assert.AreEqual(2, result.BooksByGenre.Count);
        }
Exemplo n.º 2
0
        public void GetGenre_WhenGenreDontExist_ThrowException()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "GetGenreDontExist").Options;

            var validationMock = new Mock <IValidations>();

            string genreName = "Genre";

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unitOfWork = new UnitOfWork(actContext);
                var service    = new GenreServices(unitOfWork, validationMock.Object);

                service.GetGenre(genreName);
            }
        }
        private void addCustomeType_Click(object sender, RoutedEventArgs e)
        {
            AddLink addlink = new AddLink();

            addlink.ShowDialog();
            if (string.IsNullOrWhiteSpace(addlink.Link) == false)
            {
                string newtype = addlink.Link;
                GenreServices.GetGenre(newtype, _objEntity.ObjectType);
                bool bExist = RootPanel.Children.Cast <CheckBox>().Any(item => item.Content.ToString() == newtype);

                if (bExist == false)
                {
                    CheckBox objCheckBox = new CheckBox();
                    objCheckBox.Margin = new Thickness(5, 0, 0, 0);

                    objCheckBox.Content   = newtype;
                    objCheckBox.IsChecked = true;
                    RootPanel.Children.Add(objCheckBox);
                }
            }
        }
Exemplo n.º 4
0
        public static Hashtable Parse(string strId)
        {
            Hashtable objResults = new Hashtable();

            try
            {
                const string imageUrl = @"http://thegamesdb.net/banners/";
                Uri          strUrl   = new Uri(string.Format(Url + @"/GetGame.php?id={0}", strId));
                string       results  = Util.GetRest(strUrl);

                if (string.IsNullOrWhiteSpace(results))
                {
                    return(null);
                }

                XElement restResponse = XElement.Parse(results);

                TheGamesDb game = TheGamesDb.GamesToObject(restResponse);
                if (game != null)
                {
                    if (string.IsNullOrWhiteSpace(game.Background) == false)
                    {
                        objResults.Add("Background", imageUrl + game.Background);
                    }

                    if (string.IsNullOrWhiteSpace(game.Cover) == false)
                    {
                        objResults.Add("Image", imageUrl + game.Cover);
                    }

                    if (string.IsNullOrWhiteSpace(game.Description) == false)
                    {
                        objResults.Add("Description", game.Description);
                    }

                    if (string.IsNullOrWhiteSpace(game.Platform) == false)
                    {
                        objResults.Add("Platform", game.Platform);
                    }

                    if (string.IsNullOrWhiteSpace(game.Rating) == false)
                    {
                        double intTmp;
                        if (double.TryParse(game.Rating, NumberStyles.Any, new CultureInfo("en-US", true), out intTmp))
                        {
                            objResults.Add("Rating", intTmp * 2);
                        }
                    }

                    if (game.Released != null)
                    {
                        objResults.Add("Released", game.Released);
                    }

                    if (string.IsNullOrWhiteSpace(game.Studio) == false)
                    {
                        objResults.Add("Editor", game.Studio);
                    }

                    if (string.IsNullOrWhiteSpace(game.Title) == false)
                    {
                        objResults.Add("Title", game.Title);
                    }

                    if (string.IsNullOrWhiteSpace(game.Link) == false)
                    {
                        objResults.Add("Links", game.Link);
                    }

                    List <Genre> gamesTypes = new List <Genre>();
                    foreach (string item in game.Types)
                    {
                        Genre gametype = GenreServices.GetGenre(item, EntityType.Games);
                        gamesTypes.Add(gametype);
                    }

                    objResults.Add("Types", gamesTypes);
                }

                return(objResults);
            }
            catch (Exception ex)
            {
                Util.LogException(ex, strId);
                return(null);
            }
        }
Exemplo n.º 5
0
        public static Hashtable Parse(string strUrl, string strSearch)
        {
            Hashtable objResults = new Hashtable();

            try
            {
                string strResults = Util.GetHtmlPage(strUrl, Encoding.UTF8);

                if (strResults == null)
                {
                    return(null);
                }

                objResults.Add("Title", strSearch);
                objResults.Add("Links", strUrl);

                #region Description
                string strParsing = @"Descriptif :";
                int    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";
                    objResults.Add("Description", Util.PurgeHtml(HttpUtility.HtmlDecode(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim())));
                }
                #endregion
                #region Editor
                strParsing = @"Editeur :";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @""">";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"</a>";
                    objResults.Add("Editor", strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim());
                }
                else
                {
                    strParsing = @"<strong>D&amp;eacute;veloppeur :</strong>";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @""">";
                        strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"</a>";
                        objResults.Add("Editor", strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim());
                    }
                }
                #endregion
                #region Types
                strParsing = @"<strong>Type :</strong>";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";
                    string types = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                    if (types.Contains(@""">"))
                    {
                        string[]     lstTypes   = Regex.Split(types, @""">");
                        List <Genre> gamesTypes = new List <Genre>();
                        foreach (string lstType in lstTypes)
                        {
                            if (lstType.StartsWith("<") == false)
                            {
                                strParsing = @"<";
                                string item     = lstType.Substring(0, lstType.IndexOf(strParsing, StringComparison.Ordinal));
                                Genre  gametype = GenreServices.GetGenre(item, EntityType.Games);
                                gamesTypes.Add(gametype);
                            }
                        }

                        objResults.Add("Types", gamesTypes);
                    }
                    else
                    {
                        objResults.Add("Types", new List <string> {
                            types
                        });
                    }
                }
                #endregion
                #region Released Date
                strParsing = @"<strong>Sortie France :</strong>";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"</li>";

                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    strParsing = @"<br";
                    int intTmp2 = strResults.IndexOf(strParsing, StringComparison.Ordinal);

                    if (intTmp2 == -1 || intTmp2 > intTmp1)
                    {
                        objResults.Add("Released", strResults.Substring(0, intTmp1).Trim());
                    }
                    else
                    {
                        objResults.Add("Released", strResults.Substring(0, intTmp2).Trim());
                    }
                }
                #endregion
                strParsing = @"note_redac";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @":";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"<";

                    string strTemp = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal));
                    if (string.IsNullOrEmpty(strTemp) == false)
                    {
                        strTemp = strTemp.Trim().Split('/')[0];
                        if (Util.IsNumeric(strTemp) == true)
                        {
                            int intTmp = Convert.ToInt32(strTemp, CultureInfo.InvariantCulture);
                            objResults.Add("Rating", intTmp);
                        }
                    }

                    strParsing = @"<li>";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"</li>";

                    objResults.Add("Comments", Util.PurgeHtml(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.InvariantCultureIgnoreCase)).Trim()));
                }
                if (objResults.ContainsKey("Rating") == false)
                {
                    strParsing = @"Note moyenne des Lecteurs :";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @"<";

                        string strTemp = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal));
                        if (string.IsNullOrEmpty(strTemp) == false)
                        {
                            strTemp = strTemp.Trim().Split('/')[0];
                            if (Util.IsNumeric(strTemp) == true)
                            {
                                int intTmp = Convert.ToInt32(strTemp, CultureInfo.InvariantCulture);
                                objResults.Add("Rating", intTmp);
                            }
                        }
                    }
                }
                if (objResults.ContainsKey("Comments") == false)
                {
                    strParsing = @"Dernier avis :";
                    intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                    if (intTmp1 > -1)
                    {
                        strResults = strResults.Substring(intTmp1 + strParsing.Length);
                        strParsing = @">";
                        strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"<";

                        objResults.Add("Comments", Util.PurgeHtml(strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.InvariantCultureIgnoreCase)).Trim()));
                    }
                }
                #region Image
                strParsing = @"li class=""recto_verso"">";
                intTmp1    = strResults.IndexOf(strParsing, StringComparison.Ordinal);
                if (intTmp1 > -1)
                {
                    strResults = strResults.Substring(intTmp1 + strParsing.Length);
                    strParsing = @"<a href=""";
                    strResults = strResults.Substring(strResults.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                    strParsing = @"""";
                    strResults = strResults.Substring(0, strResults.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                    strParsing = @"affpic.htm?";

                    if (strResults.Contains(strParsing))
                    {
                        strResults = strResults.Replace(strParsing, "");
                    }

                    if (strResults.Contains(".htm") == false)
                    {
                        objResults.Add("Image", strResults);
                    }
                    else
                    {
                        string pageimage = Util.GetHtmlPage(strResults, Encoding.GetEncoding("iso-8859-1"));
                        strParsing = strResults;
                        pageimage  = pageimage.Substring(pageimage.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"src='";
                        pageimage  = pageimage.Substring(pageimage.IndexOf(strParsing, StringComparison.Ordinal) + strParsing.Length);
                        strParsing = @"'";
                        pageimage  = pageimage.Substring(0, pageimage.IndexOf(strParsing, StringComparison.Ordinal)).Trim();
                        objResults.Add("Image", pageimage);
                    }
                }
                #endregion
                objResults.Add("Platform", GetPlateform(strUrl));

                return(objResults);
            }
            catch (Exception ex)
            {
                Util.LogException(ex);
                return(null);
            }
        }