public ReportSuspiciousFactTests() { var builder = new StructureMapContainerBuilder(); var container = builder.Build(new Server.AppSettings()); container.Inject(Substitute.For <IEventPublisher>()); container.Inject(Substitute.For <IWebSiteChecker>()); container.Inject <IEventStore>(container.GetInstance <InMemoryEventStore>()); _commandSender = container.GetInstance <ICommandSender>(); _eventPublisher = container.GetInstance <IEventPublisher>(); _webSiteChecker = container.GetInstance <IWebSiteChecker>(); _webSiteChecker.IsOnline(Arg.Any <string>()).Returns(Task.FromResult(true)); _webSiteChecker.IsOnline(UNREACHABLE_WEB_PAGE).Returns(false); }
public async Task Handle(ReportSuspiciousFactCommand command) { if (await webSiteChecker.IsOnline(command.WebPageUrl) == false) { throw new UnreachableWebPage(command.WebPageUrl); } var fact = new Fact( command.Reporter, command.Wording, command.WebPageUrl, XPath.Parse(command.StartNodeXPath), command.StartOffset, XPath.Parse(command.EndNodeXPath), command.EndOffset ); await repository.Save(fact); }
static void Main(string[] args) { //Configure simple DI container Configure(); //Get parser and website checker instances ISiteCredentialParser parser = ObjectFactory.GetInstance <ISiteCredentialParser>(); IWebSiteChecker webSiteChecker = ObjectFactory.GetInstance <IWebSiteChecker>(); //If there are arguments, take first as filename. Would be a bit more sophisticated in real life of course. if (args.Length != 0) { fileName = args[0]; } //Parse file List <Site> sites = parser.ParseFile(fileName); //And order results. I didn't put that in service not to generate not neeeded overhead. Not always we need sorted list. sites = sites.OrderBy(p => p.Name).ToList(); //While printing each Site details we will count total credentials. //Could be done by var totalCredentials = (from s in sites select s.LoginCredentials.Count).Sum(); but we must pass the list anyway. int totalCredentials = 0; //Print results foreach (Site site in sites) { Console.WriteLine( String.Format("{0}\tIsOnline: {1}", site.ToString(), webSiteChecker.IsOnline(site.Url).ToString()) ); totalCredentials += site.LoginCredentials.Count; } //Empty line and total number of credentials Console.WriteLine(); Console.WriteLine("Total number of credentials: " + totalCredentials); Console.ReadLine(); }