public async Task publish_suspicious_fact_detected() { // Arrange var command = new ReportSuspiciousFactCommand { Wording = "Our president has been elected by more that 60% of the population.", WebPageUrl = "https://wwww.fakenews/president.html", StartNodeXPath = "//*[@id=\"content\"]/div/div/div[1]/div/div/div/div[3]/p[6]/text()", EndNodeXPath = "//*[@id=\"content\"]/div/div/div[1]/div/div/div/div[3]/p[6]/text()", StartOffset = 10, EndOffset = 76 }; // Act await _commandSender.Send(command); // Assert await _eventPublisher.Received(1).Publish(Arg.Is <SuspiciousFactDetected>(@event => @event.Id != default(Guid) && @event.Wording == command.Wording && @event.WebPageUrl == command.WebPageUrl && @event.Location.StartNodeXPath.ToString() == command.StartNodeXPath && @event.Location.EndNodeXPath.ToString() == command.EndNodeXPath && @event.Location.StartOffset == command.StartOffset && @event.Location.EndOffset == command.EndOffset )); }
public FactModule(IQueryProcessor queryProcessor, ICommandSender dispatcher) : base() { Get("/api/fact", async _ => { var base64Url = (string)this.Request.Query.url; var listFacts = new ListFactsQuery( string.IsNullOrEmpty(base64Url) == false ? Encoding.UTF8.GetString(Convert.FromBase64String(base64Url)) : null, (int?)this.Request.Query.skip, (int?)this.Request.Query.take ); return(await queryProcessor.Query(listFacts)); }); Post("/api/fact", async _ => { try { var command = new ReportSuspiciousFactCommand() { StartNodeXPath = Request.Form.startNodeXPath, StartOffset = Request.Form.startOffset, EndNodeXPath = Request.Form.endNodeXPath, EndOffset = Request.Form.endOffset, Reporter = Guid.Parse(Context.CurrentUser.FindFirstValue("userId")), WebPageUrl = GetFactUrl(), Wording = Request.Form.wording }; await dispatcher.Send(command); return(Negotiate.WithStatusCode(HttpStatusCode.OK)); } catch (DomainException ex) { return(BadRequest(ex)); } }); }
public async Task throw_exception_when_web_page_unreachable() { await Assert.ThrowsAsync <UnreachableWebPage>(async() => { // Arrange var command = new ReportSuspiciousFactCommand { WebPageUrl = UNREACHABLE_WEB_PAGE }; // Act await _commandSender.Send(command); }); }
public async Task accept_different_xpath_format(string xpath) { // Arrange var command = new ReportSuspiciousFactCommand { Wording = "Our president has been elected by more that 60% of the population.", WebPageUrl = "https://wwww.fakenews/president.html", StartNodeXPath = xpath, EndNodeXPath = xpath, StartOffset = 10, EndOffset = 76 }; // Act await _commandSender.Send(command); }
public async Task throw_exception_when_invalid_html_xpath_location(string beginXPath, string endXPath) { await Assert.ThrowsAsync <InvalidXPathFormat>(async() => { // Arrange var command = new ReportSuspiciousFactCommand { WebPageUrl = REACHABLE_WEB_PAGE, Wording = SOME_WORDING, StartNodeXPath = beginXPath, EndNodeXPath = endXPath }; // Act await _commandSender.Send(command); }); }
public async Task throw_exception_when_to_many_words(string wordingSample) { await Assert.ThrowsAsync <ToManyWords>(async() => { // Arrange var command = new ReportSuspiciousFactCommand { WebPageUrl = REACHABLE_WEB_PAGE, Wording = wordingSample, StartNodeXPath = SOME_XPATH, EndNodeXPath = SOME_XPATH }; // Act await _commandSender.Send(command); }); }
public async Task throw_exception_when_fact_spread_over_multiple_paragraphs(string beginElement, string endElement) { await Assert.ThrowsAsync <FactSpreadOverMultipleParagraphs>(async() => { // Arrange var command = new ReportSuspiciousFactCommand { WebPageUrl = REACHABLE_WEB_PAGE, Wording = SOME_WORDING, StartNodeXPath = $"/html/body/{beginElement}/text()", EndNodeXPath = $"/html/body/{endElement}/text()", StartOffset = 0, EndOffset = 5 }; // Act await _commandSender.Send(command); }); }
public async Task clear_wording_from_duplicated_spaces() { // Arrange var command = new ReportSuspiciousFactCommand { Wording = "Our president has been elected by more that 60% of the population.", WebPageUrl = REACHABLE_WEB_PAGE, StartNodeXPath = SOME_XPATH, EndNodeXPath = SOME_XPATH, StartOffset = 10, EndOffset = 76 }; // Act await _commandSender.Send(command); // Assert await _eventPublisher.Received(1).Publish(Arg.Is <SuspiciousFactDetected>(@event => @event.Wording == "Our president has been elected by more that 60% of the population." )); }
public async Task do_not_throw_exception_when_fact_in_same_paragraph(string beginXPath, string endXPath) { try { // Arrange var command = new ReportSuspiciousFactCommand { WebPageUrl = REACHABLE_WEB_PAGE, Wording = SOME_WORDING, StartNodeXPath = beginXPath, EndNodeXPath = endXPath, StartOffset = 0, EndOffset = 5 }; // Act await _commandSender.Send(command); } catch (FactSpreadOverMultipleParagraphs) { throw; } catch {} }