コード例 #1
0
        public async Task WithChildPopulationTest()
        {
            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"),
                ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"),
            };
            analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>());


            PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 1
                }
            }
                                                               );

            foreach (string key in analyzer.TypeMap.Keys)
            {
                // -1 because of the "DoesNotExist" property.
                Assert.IsTrue(rs.Keys.Count() >= analyzer.TypeMap.Count() - 1);
            }
        }
コード例 #2
0
        public async Task BasicCollection()
        {
            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}")
            };

            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            PopulationResultCollection rs = await DataCollector.CollectData(analyzer, new HttpServiceOptions
            {
                PrefixKey  = "post",
                Parameters = new
                {
                    PostId = 1
                }
            });

            PopulationResult data = rs.Dequeue();

            foreach (string key in data.Keys)
            {
                Assert.IsTrue(analyzer.TypeMap.Keys.Contains(key));
            }
        }
コード例 #3
0
        public async Task WithMissingChildPopulationTest()
        {
            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"),
                ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"),
            };
            analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>());


            PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 0
                }
            }
                                                               );

            Assert.IsTrue(!rs.Keys.Any());
        }
コード例 #4
0
        public void Analyze_LongPost_NoProblems()
        {
            var  postAnalyzer = new PostAnalyzer(null);
            Post post         = new Post {
                text = "<blockquote>\n<p>Głupie rozmowy z HR i menadżerami, gdzie zadawane są mi pytania typu \"a jak pan zobaczy błąd w aplikacji, to co pan zrobi?\". Czasami mam ochotę odpowiedzieć \"zesram się i ucieknę\".</p>\n</blockquote>\n<p>IMO pytanie jak pytanie, w sumie nawet dobre.  Może sprawdzają czy ktoś ma w dupie wszystko albo czy będzie pracował dobrze jako członek większego zespołu.  Moja odpowiedź na takie pytanie byłaby taka że jak to bug w kodzie to zgłoszę do osoby odpowiedzialnej.  Jak ją znajdę - zależy, może po prostu wiem kto się tym zajmuje, może jest coś w stylu MAINTAINERS z Linuksa a w ostateczności zobaczę git blame kto ostatnio dotykał tego fragmentu.  Jak to bug nie w kodzie tylko w zachowaniu aplikacji to gorzej, odłożenie na TODO listę i ticket na lokalnym bug trackerze.</p>\n<blockquote>\n<p>Lwia część ludzi przeprowadzających te rozmowy nie powinna być na nie wogóle dopuszczona. I nie chodzi o to że są ubrani jak lumpy pod monopolem, bo to nie jest dla mnie problem. Większym problemem jest to, że te rozmowy nie wiadomo do czego prowadzą. Ostatnio byłem na jednej, gdzie przeszedłem test z podstaw programowania, gdzie pytania były typu \"czym się różni interfejs od klasy abstrakcyjnej (klasyk na rozmowach)\",. Co oni chcą sprawdzić u kandydata dając mu zadania i pytania na poziomie II roku studiów?</p>\n</blockquote>\n<p>Może nauczeni smutnym doświadczeniem wiedzą że są tacy którzy tego nie wiedzą. Albo co gorsze dla nich, nie potrafią <em>zwięźle</em> wyjaśnić.  Teraz dużo chodzę na rozmowy - takie proste pytania czasem pochodzą od osób które się nie za bardzo znają i chcą zadać jakiekolwiek najprostsze pytanie na które znają odpowiedź. Albo jest to pytanie które jest wstępem do kolejnego pytania - kiedy się czego do czego używa albo jak jest coś zaimplementowane pod spodem, jaki ma overhead etc.</p>\n<blockquote>\n<p>No i best part, czyli hajs. Mieszkam i pracuję w Warszawie, od kilku lat pracuję w .net, ostatnio w net core, znajomość front, angular, ef itd, na rozmowie odpowiadam na przynajmniej 80% głupich pytań, a jak mówię że chcę zarabiać 14lk netto na fakturę, to robią czasami oczy. Ostatnio mnie odrzucili z jednej firmy i po uzyskaniu feedbacku dowiedziałem się że chodzi o wymagania finansowe. To dlaczego firmy nie negocjują? Ja zawsze mówię stawkę 10-15% wyższą niż chcę, mogą zadzwonić i ponegocjować, jeżeli praca mi się podoba to mogę zejść z wymagań.</p>\n</blockquote>\n<p>No ale co się dziwisz, 14k to od cholery pieniędzy, pewnie mają tańszych.  Ja po 8 latach \"kariery\" w embedded szukam nowej pracy i jak na razie czekam na odpowiedź od firmy gdzie wstępnie powiedziałem 120 PLN/h ale od razu powiedzieli że bez płatnych urlopów bo się boją kontroli, i to do tej pory była największa oferta finansowa ale wątpię czy tyle dostane.  We wcześniejszej chcieli dać 750 PLN dziennie a jak powiedziałem że więcej chcę to się przestali odzywać.</p>\n<p>EDIT: aha, no i wiesz, 4 lata doświadczenia to naprawdę mało.</p>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Empty(result);
        }
コード例 #5
0
        public void Analyze_SimplePost_NoProblems()
        {
            var  postAnalyzer = new PostAnalyzer(null);
            Post post         = new Post {
                text = "<p>A to Kotlin już nie na topie?</p>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Empty(result);
        }
コード例 #6
0
        public void Analyze_PostWithQuotes_NoProblems()
        {
            var  postAnalyzer = new PostAnalyzer(null);
            Post post         = new Post {
                text = "<blockquote>\n<h5><a href=\"https://4programmers.net/Forum/1625684\">cmd napisał(a)</a>:</h5>\n<p>U mnie w firmie było do przejścia jedno zadanie na tablicy, był to fizzbuzz</p>\n</blockquote>\n<p>ale to tylko dla juniorów tak? czy mid deweloperzy tez u was fizzfuzz nie przechodzili?</p>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Empty(result);
        }
コード例 #7
0
        public void Analyze_PostWithProperCode_NoProblems()
        {
            var  postAnalyzer = new PostAnalyzer(null);
            Post post         = new Post {
                text = "<pre><code class=\"language-python line-numbers\">\n\n'''\n\n                            Online Python Interpreter.\n                Code, Compile, Run and Debug python program online.\nWrite your code in this editor and press \"Run\" button to execute it.\n\n'''\n\nclass Hand: # nie programuj w python2 tylko w python3 (python2 ma tylko wsparcie do konca roku)\n    \"\"\" Ręka - wszystkie karty trzymane przez gracza. \"\"\"\n    def __init__(self):\n        self.cards = []\n\n    def __str__(self):\n        if self.cards:\n           rep = \"\"\n           for card in self.cards:\n               rep += str(card) + \"\\t\"\n        else:\n            rep = \"&lt;pusta&gt;\"\n        return rep\n\n    def add(self, card: \"Card\") -&gt; None: # dodawaj typowanie argumentow i to co funkcja zwraca \n        self.cards.append(card)\n\nclass Card:\n    \"\"\" Karta do gry. \"\"\"\n    RANKS = [\"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\",\n             \"9\", \"10\", \"J\", \"Q\", \"K\", \"A\"]\n    SUITS = [\"pik\", \"kier\", \"trefl\", \"karo\"]\n\n    def __init__(self, rank, suit):\n        self.rank = rank\n        self.suit = suit\n\n    def __str__(self):\n        rep = f\"{self.rank} {self.suit}\" # poczytaj co to f stringi  :) \n        return rep\n\nclass WarCard(Card): # piszemy kod po angielsku. nazwy klas sa uppercase czyli WarCard nigdy War_Card to jest mic uppercase z snakecase\n    \"\"\" Karta do wojny. Ustawienie wartości kart. \"\"\"\n\n    @property\n    def value(self) -&gt; int:\n        value = WarCard.RANKS.index(self.rank)\n        return value # co to znaczy v? staraj sie pisac doslowniej, bo kiedys sie zgubisz w wiekszysc kodzie\n\nclass WarHand(Hand): # tu tak samo jak wyzej\n    \"\"\" Ręka w wojnie. \"\"\"\n    def __init__(self, name):\n        super().__init__() # w python3 nie musisz do super przekazywac klasy \n        self.name = name\n\n    def __str__(self):\n        rep = f\"{self.name}    {super(WarHand, self).__str__()}\"\n        if self.total:\n            rep += f\"(ma {self.total} punktów)\"\n        return rep\n\n    @property\n    def total(self) -&gt; int:\n        t = 0\n        for card in self.cards:\n            t += card.value\n        return t \n\ncard1 = WarCard(\"3\", \"pik\")\nprint(\"karta: \" + str(card1) + \". Jej wartość wynosi: \" + str(card1.value))\n\ncard2 = WarCard(\"2\", \"kier\")\nprint(\"karta: \" + str(card2) + \". Jej wartość wynosi: \" + str(card2.value))\n\nreka = WarHand(\"Tomasz\")\nreka.add(card1)\nprint(reka)\n\nreka = WarHand(\"Jan\")\nreka.add(card2)\nprint(reka)\n\ninput(\"\\n\\nAby zakończyć program, naciśnij klawisz Enter.\")\n\ndalem Ci pare wskazowek plus tutaj WarHand/WarCard jest zbedne i dziedziczenie po Hand/Card mozesz spokojnie w tych klasach te metody z War klas przeniesc</code></pre>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Empty(result);
        }
コード例 #8
0
        public void Analyze_PostWithUnformattedCode_UnformattedCodeFound()
        {
            var  postAnalyzer = new PostAnalyzer(null);
            Post post         = new Post {
                text = "<p>Witam zrobilem zadanie , z systemu 10 na system 16, ma ktoś jakiś pomysł na lepsze rozwiązanie?<br />\n#include &lt;iostream&gt;</p>\n<p>using namespace std;</p>\n<p>int main()<br />\n{<br />\nint n;<br />\ncin&gt;&gt;n;<br />\nint w;<br />\nint c=0;<br />\nint tab[c];<br />\nwhile(n&gt;0)<br />\n{<br />\nc++;<br />\nw=n%16;<br />\nn=n/16;</p>\n<pre><code>tab[c]=w;</code></pre>\n<p>}<br />\ncout&lt;&lt;\"System szesnastkowy to: \";<br />\nfor(int i=c; i&gt;0; i--)<br />\n{<br />\nif(tab[i]==10)<br />\n{<br />\ncout&lt;&lt;\"A\";<br />\n}<br />\nelse if(tab[i]==11)<br />\n{<br />\ncout&lt;&lt;\"B\";<br />\n}<br />\nelse if(tab[i]==12)<br />\n{<br />\ncout&lt;&lt;\"C\";<br />\n}<br />\nelse if(tab[i]==13)<br />\n{<br />\ncout&lt;&lt;\"D\";<br />\n}<br />\nelse if(tab[i]==14)<br />\n{<br />\ncout&lt;&lt;\"E\";<br />\n}<br />\nelse if(tab[i]==15)<br />\n{<br />\ncout&lt;&lt;\"F\";<br />\n}<br />\nelse<br />\n{<br />\ncout&lt;&lt;tab[i];<br />\n}<br />\n}<br />\n}</p>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Single(result);
            Assert.IsType <NotFormattedCodeFound>(result[0]);
        }
コード例 #9
0
        public void AnalyzePost_TestExtractAuthor6()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/sramim-se");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("drlesar", author);
            Assert.AreEqual("drlesar", authorHtml);
        }
コード例 #10
0
        public void AnalyzePost_TestExtractAuthor5()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/tko-drma-hac-om");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("2bbc", author);
            Assert.AreEqual("2bbc", authorHtml);
        }
コード例 #11
0
        public void AnalyzePost_TestExtractAuthor3()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/pollitika-kao-quotevo-siljim-drvo-da-ubijem-meduquot");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("Mali Hans", author);
            Assert.AreEqual("mali-hans", authorHtml);
        }
コード例 #12
0
        public void AnalyzePost_TestExtractAuthor2()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/kukavicje-jaje");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("Rebel", author);
            Assert.AreEqual("rebel", authorHtml);
        }
コード例 #13
0
        public void AnalyzePost_TestExtractAuthor1()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/hrvatsko-zdravstvo-i-sovjetska-automobilska-industrija");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("žaki", author);
            Assert.AreEqual("zaki", authorHtml);
        }
コード例 #14
0
        public void AnalyzePost_TestExtractAuthor7()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/nered-na-trzi-tu-dobra-stvar");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("Simun", author);
            Assert.AreEqual("simun", authorHtml);
        }
コード例 #15
0
        public void AnalyzePost_TestExtractAuthor8()
        {
            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument htmlDocument = htmlWeb.Load("http://pollitika.com/zvoni-radikalnom-naden-kratki-spoj-u-mozgu ");

            string author, authorHtml;

            PostAnalyzer.ScrapePostAuthor(htmlDocument.DocumentNode, out author, out authorHtml);

            Assert.AreEqual("Zvone Radikalni", author);
            Assert.AreEqual("zvone-radikalni", authorHtml);
        }
コード例 #16
0
        public void MultipleSameServiceTest()
        {
            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";

            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"),
                ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"),
            };
            analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>());
            analyzer.Property(p => p.Id).GetFromService("UsersService", new AnalyticalObject <User>());
        }
コード例 #17
0
        public void AnalyzePost_CompletePostTest7()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/nered-na-trzi-tu-dobra-stvar", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(50, post.Id);
            Assert.AreEqual("http://pollitika.com/nered-na-trzi-tu-dobra-stvar", post.HrefLink);
            Assert.AreEqual("Nered na tržištu - dobra stvar?", post.Title);
            Assert.AreEqual("/node/50/who_voted", post.VotesLink);
            Assert.AreEqual("Simun", post.Author.Name);
            Assert.AreEqual("simun", post.Author.NameHtml);
            Assert.AreEqual(4, post.NumCommentsScrapped);
            Assert.AreEqual(0, post.GetNumberOfVotes());
            Assert.AreEqual(4, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2006, 10, 13, 0, 37, 0), post.DatePosted);
        }
コード例 #18
0
        public void AnalyzePost_CompletePostTest6()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/sramim-se", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(406, post.Id);
            Assert.AreEqual("http://pollitika.com/sramim-se", post.HrefLink);
            Assert.AreEqual("Sramim se!", post.Title);
            Assert.AreEqual("/node/406/who_voted", post.VotesLink);
            Assert.AreEqual("drlesar", post.Author.Name);
            Assert.AreEqual("drlesar", post.Author.NameHtml);
            Assert.AreEqual(16, post.NumCommentsScrapped);
            Assert.AreEqual(0, post.GetNumberOfVotes());
            Assert.AreEqual(16, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2007, 1, 12, 22, 21, 0), post.DatePosted);
        }
コード例 #19
0
        public void AnalyzePost_CompletePostTest5()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/che-guevarina-skola", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(11768, post.Id);
            Assert.AreEqual("http://pollitika.com/che-guevarina-skola", post.HrefLink);
            Assert.AreEqual("Che Guevarina škola", post.Title);
            Assert.AreEqual("/node/11768/who_voted", post.VotesLink);
            Assert.AreEqual("Golgota", post.Author.Name);
            Assert.AreEqual("golgota", post.Author.NameHtml);
            Assert.AreEqual(167, post.NumCommentsScrapped);
            Assert.AreEqual(33, post.GetNumberOfVotes());
            Assert.AreEqual(167, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2012, 10, 10, 14, 20, 0), post.DatePosted);
        }
コード例 #20
0
        public void AnalyzePost_CompletePostTest4()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/dubrovnik-dubravka-cijepanje-drva-uz-sviranje-klavira", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(6425, post.Id);
            Assert.AreEqual("http://pollitika.com/dubrovnik-dubravka-cijepanje-drva-uz-sviranje-klavira", post.HrefLink);
            Assert.AreEqual(" Dubrovnik, Dubravka, cijepanje drva uz sviranje klavira", post.Title);
            Assert.AreEqual("/node/6425/who_voted", post.VotesLink);
            Assert.AreEqual("Marshal", post.Author.Name);
            Assert.AreEqual("marshal", post.Author.NameHtml);
            Assert.AreEqual(6, post.NumCommentsScrapped);
            Assert.AreEqual(12, post.GetNumberOfVotes());
            Assert.AreEqual(6, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2009, 6, 13, 13, 11, 0), post.DatePosted);     // 13/06/2009 - 13:11
        }
コード例 #21
0
        public void AnalyzePost_CompletePostTest3()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/trijumf-trollova", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(14888, post.Id);
            Assert.AreEqual("http://pollitika.com/trijumf-trollova", post.HrefLink);
            Assert.AreEqual("Trijumf trollova", post.Title);
            Assert.AreEqual("/node/14888/who_voted", post.VotesLink);
            Assert.AreEqual("magarac", post.Author.Name);
            Assert.AreEqual("magarac", post.Author.NameHtml);
            Assert.AreEqual(161, post.NumCommentsScrapped);
            Assert.AreEqual(41, post.GetNumberOfVotes());
            Assert.AreEqual(161, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2016, 3, 17, 17, 34, 0), post.DatePosted);
        }
コード例 #22
0
        public void AnalyzePost_CompletePostTest2()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/kukavicje-jaje", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(12480, post.Id);
            Assert.AreEqual("http://pollitika.com/kukavicje-jaje", post.HrefLink);
            Assert.AreEqual("Kukavičje jaje", post.Title);
            Assert.AreEqual("/node/12480/who_voted", post.VotesLink);
            Assert.AreEqual("Rebel", post.Author.Name);
            Assert.AreEqual("rebel", post.Author.NameHtml);
            Assert.AreEqual(55, post.NumCommentsScrapped);
            Assert.AreEqual(26, post.GetNumberOfVotes());
            Assert.AreEqual(55, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2013, 6, 7, 9, 3, 0), post.DatePosted); // 07/06/2013 - 09:03
        }
コード例 #23
0
        public async Task ShadowPropertyInsertionTest()
        {
            MySqlConnection connection = new MySqlConnection(config.GetConnectionString("TestConnection"));
            await connection.RunCommandAsync("DROP TABLE IF EXISTS Post");

            await connection.RunCommandAsync("DROP TABLE IF EXISTS AnalyzedModelHashes");

            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"]         = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"),
                ["ArbitraryUserService"] = new HttpService("https://jsonplaceholder.typicode.com/users/1"),
            };


            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.GetFromService("PostsService");
            analyzer.Property("arbitaryUser", new AnalyticalObject <User>())
            .GetFromService("ArbitraryUserService", new AnalyticalObject <User>());

            PopulationResult result = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 1
                }
            });

            DataIngester ingester = new DataIngester(new MariaDbProvider(MariaDbTableEngine.InnoDB, new Dictionary <InternalType, string>()
            {
                [InternalType.STRING]   = "TEXT",
                [InternalType.INTEGER]  = "BIGINT",
                [InternalType.FLOAT]    = "FLOAT",
                [InternalType.BOOLEAN]  = "BOOLEAN",
                [InternalType.DATETIME] = "DATETIME"
            }));
            await ingester.Insert(result, connection);

            string username = await connection.RunCommandGetString("select * from Post", "user_username");

            Assert.AreEqual(username, "Bret");

            await connection.RunCommandAsync("DROP TABLE Post");

            await connection.RunCommandAsync("DROP TABLE AnalyzedModelHashes");
        }
コード例 #24
0
        static public void MultithreadedAnalyzePost(string postUrl, IModelRepository inRepo, bool isFrontPage, bool fetchCommentVotes, ScrapingBrowser inBrowser)
        {
            ILog log = log4net.LogManager.GetLogger(typeof(Program));

            log.DebugFormat("Starting post url {0}", postUrl);

            try
            {
                Post newPost = PostAnalyzer.AnalyzePost(postUrl, inRepo, isFrontPage, fetchCommentVotes, inBrowser);

                if (newPost != null)
                {
                    inRepo.AddPost(newPost);
                }
            }
            catch (Exception ex)
            {
                log.Error("ERROR " + postUrl + " MSG: " + ex.Message);
            }
        }
コード例 #25
0
ファイル: PostAnalyzerTests.cs プロジェクト: ktos/Eleia
        public void Analyze_PostWithLinksThreshold099_NoProblems()
        {
            var myConfiguration = new Dictionary <string, string>
            {
                { "threshold", "0.99" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(myConfiguration)
                                .Build();

            var  postAnalyzer = new PostAnalyzer(configuration);
            Post post         = new Post {
                html = "<pre><code class=\"language-csharp line-numbers\">protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n{\r\n    optionsBuilder\r\n        .ConfigureWarnings(w =&gt; w.Throw(RelationalEventId.QueryClientEvaluationWarning));\r\n}</code></pre>\r\n<p>Źródło: </p>\r\n<ol>\r\n<li><a href=\"https://compiledexperience.com/blog/posts/ef-core-client-side-eval\">https://compiledexperience.com/blog/posts/ef-core-client-side-eval</a></li>\r\n<li><a href=\"https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.configurewarnings?view=efcore-2.2\">https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.configurewarnings?view=efcore-2.2</a></li>\r\n</ol>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Empty(result);
        }
コード例 #26
0
ファイル: PostAnalyzerTests.cs プロジェクト: ktos/Eleia
        public void Analyze_PostWithUnformattedCodeThreshold097_UnformattedCodeFound()
        {
            var myConfiguration = new Dictionary <string, string>
            {
                { "threshold", "0.97" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(myConfiguration)
                                .Build();

            var  postAnalyzer = new PostAnalyzer(configuration);
            Post post         = new Post {
                html = "<p>Witam zrobilem zadanie , z systemu 10 na system 16, ma ktoś jakiś pomysł na lepsze rozwiązanie?<br />\n#include &lt;iostream&gt;</p>\n<p>using namespace std;</p>\n<p>int main()<br />\n{<br />\nint n;<br />\ncin&gt;&gt;n;<br />\nint w;<br />\nint c=0;<br />\nint tab[c];<br />\nwhile(n&gt;0)<br />\n{<br />\nc++;<br />\nw=n%16;<br />\nn=n/16;</p>\n<pre><code>tab[c]=w;</code></pre>\n<p>}<br />\ncout&lt;&lt;\"System szesnastkowy to: \";<br />\nfor(int i=c; i&gt;0; i--)<br />\n{<br />\nif(tab[i]==10)<br />\n{<br />\ncout&lt;&lt;\"A\";<br />\n}<br />\nelse if(tab[i]==11)<br />\n{<br />\ncout&lt;&lt;\"B\";<br />\n}<br />\nelse if(tab[i]==12)<br />\n{<br />\ncout&lt;&lt;\"C\";<br />\n}<br />\nelse if(tab[i]==13)<br />\n{<br />\ncout&lt;&lt;\"D\";<br />\n}<br />\nelse if(tab[i]==14)<br />\n{<br />\ncout&lt;&lt;\"E\";<br />\n}<br />\nelse if(tab[i]==15)<br />\n{<br />\ncout&lt;&lt;\"F\";<br />\n}<br />\nelse<br />\n{<br />\ncout&lt;&lt;tab[i];<br />\n}<br />\n}<br />\n}</p>"
            };

            var result = postAnalyzer.Analyze(post);

            Assert.Single(result);
            Assert.IsType <NotFormattedCodeFound>(result[0]);
        }
コード例 #27
0
        public async Task BasicPopulationTest()
        {
            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}")
            };

            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.ServiceName = "PostsService";
            PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 1
                }
            }
                                                               );

            foreach (string key in rs.Keys)
            {
                Assert.IsTrue(analyzer.TypeMap.Keys.Count >= rs.Keys.Count());
            }
        }
コード例 #28
0
        public async Task ChangingSchemaTest()
        {
            MySqlConnection connection = new MySqlConnection(config.GetConnectionString("TestConnection"));
            await connection.RunCommandAsync("DROP TABLE IF EXISTS Post");

            await connection.RunCommandAsync("DROP TABLE IF EXISTS AnalyzedModelHashes");

            FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions
            {
                ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"),
                ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"),
            };

            PostAnalyzer analyzer = new PostAnalyzer();

            analyzer.GetFromService("PostsService");
            analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>());
            analyzer.Remove(p => p.Body);


            PopulationResult result = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 1
                }
            });

            DataIngester ingester = new DataIngester(new MariaDbProvider(MariaDbTableEngine.InnoDB, new Dictionary <InternalType, string>()
            {
                [InternalType.STRING]   = "TEXT",
                [InternalType.INTEGER]  = "BIGINT",
                [InternalType.FLOAT]    = "FLOAT",
                [InternalType.BOOLEAN]  = "BOOLEAN",
                [InternalType.DATETIME] = "DATETIME"
            }));

            await ingester.Insert(result, connection);


            string username = await connection.RunCommandGetString("select * from Post", "user_username");

            Assert.AreEqual(username, "Bret");


            analyzer.Property(p => p.Body);
            PopulationResult result2 = await analyzer.PopulateAsync(new HttpServiceOptions
            {
                Parameters = new
                {
                    PostId = 1
                }
            });


            await ingester.Insert(result2, connection);

            string body = await connection.RunCommandGetString("select * from Post where Id=2", "post_body");



            string bodyFromApi =
                "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto";

            Assert.AreEqual(body, bodyFromApi);


            await connection.RunCommandAsync("DROP TABLE Post");

            await connection.RunCommandAsync("DROP TABLE AnalyzedModelHashes");
        }
コード例 #29
0
        public void AnalyzePost_CompletePostTest1()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/hrvatsko-zdravstvo-i-sovjetska-automobilska-industrija", _repo, true, true);

            // testing post attributes
            Assert.AreEqual(15397, post.Id);
            Assert.AreEqual("http://pollitika.com/hrvatsko-zdravstvo-i-sovjetska-automobilska-industrija", post.HrefLink);
            Assert.AreEqual("Hrvatsko zdravstvo i sovjetska automobilska industrija", post.Title);
            Assert.AreEqual("/node/15397/who_voted", post.VotesLink);
            Assert.AreEqual("žaki", post.Author.Name);
            Assert.AreEqual("zaki", post.Author.NameHtml);
            Assert.AreEqual(13, post.NumCommentsScrapped);
            Assert.AreEqual(24, post.GetNumberOfVotes());
            Assert.AreEqual(13, post.GetNumberOfComments());
            Assert.AreEqual(new DateTime(2016, 11, 14, 18, 7, 0), post.DatePosted);


            // testing votes
            List <string> usersWhoVoted = new List <string>
            {
                "ppetra", "leddevet", "otpisani", "Quinquaginta", "z00ey", "NolS", "magarac", "antonac", "martin", "profesor", "Elnino",
                "pravednik vz", "boltek", "marival", "lunoprof", "Skviki", "lignja", "Jura", "mario121", "hlad", "gledamokosebe", "zaphod", "indian", "Bigulica"
            };

            // check all user names who voted
            for (int i = 0; i < usersWhoVoted.Count; i++)
            {
                Assert.AreEqual(usersWhoVoted[i], post.Votes[i].ByUser.Name);
            }

            Assert.AreEqual("ppetra", post.Votes[0].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 12, 8, 22, 53, 0), post.Votes[0].DatePosted);
            Assert.AreEqual(1, post.Votes[0].UpOrDown);

            Assert.AreEqual("magarac", post.Votes[6].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 10, 52, 0), post.Votes[6].DatePosted);
            Assert.AreEqual(1, post.Votes[6].UpOrDown);


            // testing comments
            Assert.AreEqual(13, post.Comments.Count);

            // check all user names who commentes

            // check individual comments
            Comment comm = post.Comments[0];

            Assert.AreEqual("Skviki", comm.Author.Name);
            Assert.AreEqual(0, comm.NumScrappedVotes);
            Assert.AreEqual(522047, comm.Id);
            Assert.AreEqual(new DateTime(2016, 11, 28, 16, 16, 0), comm.DatePosted);
            Assert.AreEqual(0, comm.NumScrappedVotes);
            Assert.AreEqual(2, comm.Votes.Count);
            Assert.AreEqual("Liberty Valance", comm.Votes[0].ByUser.Name);
            Assert.AreEqual(new DateTime(2017, 01, 28, 12, 18, 0), comm.Votes[0].DatePosted);
            Assert.AreEqual(-1, comm.Votes[0].UpOrDown);
            Assert.AreEqual("Zvone Radikalni", comm.Votes[1].ByUser.Name);
            Assert.AreEqual("zvone-radikalni", comm.Votes[1].ByUser.NameHtml);
            Assert.AreEqual(new DateTime(2017, 01, 28, 12, 16, 0), comm.Votes[1].DatePosted);
            Assert.AreEqual(1, comm.Votes[1].UpOrDown);

            comm = post.Comments[4];
            Assert.AreEqual("magarac", comm.Author.Name);
            Assert.AreEqual(2, comm.NumScrappedVotes);
            Assert.AreEqual(521866, comm.Id);
            Assert.AreEqual(new DateTime(2016, 11, 16, 11, 19, 0), comm.DatePosted);
            Assert.AreEqual(2, comm.NumScrappedVotes);
            Assert.AreEqual(2, comm.Votes.Count);
            Assert.AreEqual("fuminanti", comm.Votes[0].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 22, 10, 46, 0), comm.Votes[0].DatePosted);
            Assert.AreEqual(1, comm.Votes[0].UpOrDown);
            Assert.AreEqual("hlad", comm.Votes[1].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 11, 39, 0), comm.Votes[1].DatePosted);
            Assert.AreEqual(1, comm.Votes[1].UpOrDown);


            comm = post.Comments[6];
            Assert.AreEqual("lignja", comm.Author.Name);
            Assert.AreEqual(4, comm.NumScrappedVotes);
            Assert.AreEqual(521868, comm.Id);
            Assert.AreEqual(new DateTime(2016, 11, 16, 14, 03, 0), comm.DatePosted);
            Assert.AreEqual(4, comm.NumScrappedVotes);
            Assert.AreEqual(4, comm.Votes.Count);
            Assert.AreEqual("mario121", comm.Votes[0].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 22, 22, 0), comm.Votes[0].DatePosted);
            Assert.AreEqual(1, comm.Votes[0].UpOrDown);
            Assert.AreEqual("Skviki", comm.Votes[1].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 16, 01, 0), comm.Votes[1].DatePosted);
            Assert.AreEqual(1, comm.Votes[1].UpOrDown);
            Assert.AreEqual("indian", comm.Votes[2].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 15, 51, 0), comm.Votes[2].DatePosted);
            Assert.AreEqual(1, comm.Votes[2].UpOrDown);
            Assert.AreEqual("magarac", comm.Votes[3].ByUser.Name);
            Assert.AreEqual(new DateTime(2016, 11, 16, 15, 34, 0), comm.Votes[3].DatePosted);
            Assert.AreEqual(1, comm.Votes[3].UpOrDown);


            // TODO - definirati votes za komentare
            comm = post.Comments[10];
            Assert.AreEqual("sjenka", comm.Author.Name);
            Assert.AreEqual(2, comm.NumScrappedVotes);
            Assert.AreEqual(522048, comm.Id);
            Assert.AreEqual(new DateTime(2016, 11, 28, 17, 27, 0), comm.DatePosted);


            comm = post.Comments[11];
            Assert.AreEqual("ppetra", comm.Author.Name);
            Assert.AreEqual(-1, comm.NumScrappedVotes);
            Assert.AreEqual(521867, comm.Id);
            Assert.AreEqual(new DateTime(2016, 11, 16, 12, 55, 0), comm.DatePosted);
        }
コード例 #30
0
        public void AnalyzePost_TestGetPostDate10()
        {
            Post post = PostAnalyzer.AnalyzePost("http://pollitika.com/nered-na-trzi-tu-dobra-stvar", _repo, true, false);

            Assert.AreEqual(new DateTime(2006, 10, 13, 0, 37, 0), post.DatePosted);     // 13/10/2006 - 00:37
        }