public static void Init(VisualAssertionsConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (config.ScreenshotComparisonStrategy == null) { throw new InvalidOperationException($"{nameof(config.ScreenshotComparisonStrategy)} must be specified"); } var testOutputWriter = config.TestOutputWriter ?? Console.WriteLine; var testRunnerAdapter = TestRunnerAdapterFactory.CreateForCurrentEnvironment(testOutputWriter); var sessionContext = PersistanceEngine.GetSessionContext(); var projectRepository = new Repository <Project>(sessionContext); var comparisonStrategy = config.ScreenshotComparisonStrategy; _visualAssertionsService?.Dispose(); _visualAssertionsService = new VisualAssertionsService(projectRepository, testRunnerAdapter, config.ProcessScreenshotsAsynchronously, comparisonStrategy) { ProjectName = config.ProjectName, ScreenshotCategory = config.ScreenshotCategory, BrowserName = config.BrowserName }; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); container = new WindsorContainer(); container.Register( Classes.FromAssemblyContaining <WebAssemblyIdentity>() .BasedOn <Controller>() .LifestyleTransient(), Classes.FromAssemblyContaining <WebAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Classes.FromAssemblyContaining <MvcPagesAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Classes.FromAssemblyContaining <VisualAssertionsAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Component.For <ISessionFactory>() .UsingFactoryMethod(kernel => PersistanceEngine.CreateSessionFactory <WebSessionContext>()) .LifestyleSingleton() ); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddDistributedMemoryCache(); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSession(options => { // Set a short timeout for easy testing. options.IdleTimeout = TimeSpan.FromSeconds(10); //options.CookieHttpOnly = true; }); var container = new WindsorContainer(); container.Register( Classes.FromAssemblyContaining <WebAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Classes.FromAssemblyContaining <MvcPagesAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Classes.FromAssemblyContaining <VisualAssertionsAssemblyIdentity>() .Where(type => type.GetInterfaces().Any()) .WithServiceAllInterfaces() .LifestyleSingleton(), Component.For <ISessionFactory>() .UsingFactoryMethod(kernel => PersistanceEngine.CreateSessionFactory <AspCoreSessionContext>()) .LifestyleSingleton() ); ServiceLocator.Init(container); return(WindsorRegistrationHelper.CreateServiceProvider(container, services)); }
private void CheckScreenshotWithPattern(Screenshot screenshot) { if (screenshot == null) { throw new ArgumentNullException(nameof(screenshot)); } byte[] image = screenshot.Data; ScreenshotIdentity screenshotIdentity = screenshot.Identity; try { Action finishNotification; using (var transaction = PersistanceEngine.GetSession().BeginTransaction()) { var project = this.GetProject(screenshotIdentity.ProjectName); var testCase = GetTestCase(project, screenshotIdentity); var activePattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName); var newPattern = activePattern == null?testCase.AddNewPattern(image, screenshotIdentity.BrowserName) : null; var testResult = GetTestResult(image, screenshotIdentity, activePattern, newPattern); var testSession = GetCurrentTestSession(project); testSession.AddTestResult(testResult); finishNotification = () => { switch (testResult.Status) { case TestResultStatus.Failed: testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage); break; case TestResultStatus.Passed: testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage); break; case TestResultStatus.NewPattern: testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern, testResult.TestResultMessage); break; default: throw new ArgumentOutOfRangeException(); } }; transaction.Commit(); } finishNotification.Invoke(); } catch (Exception ex) { testRunnerAdapter.NotifyAboutError(ex); } }
private void Init(VisualAssertionsConfig config) { var sessionContext = PersistanceEngine.GetSessionContext(); var projectRepository = new Repository <Project>(sessionContext); _visualAssertionsService?.Dispose(); _visualAssertionsService = new VisualAssertionsService(projectRepository, TestRunnerAdapter, config.ProcessScreenshotsAsynchronously, ScreenshotComparisonStrategy) { ProjectName = config.ProjectName, ScreenshotCategory = config.ScreenshotCategory, BrowserName = config.BrowserName }; }
public static void Init(VisualAssertionsConfig config) { var testOutputWriter = config.TestOutputWriter ?? Console.WriteLine; var testRunnerAdapter = TestRunnerAdapterFactory.CreateForCurrentEnvironment(testOutputWriter); var projectRepository = new Repository <Project>(PersistanceEngine.GetSessionContext()); visualAssertionsService = new VisualAssertionsService(projectRepository, testRunnerAdapter) { ProjectName = config.ProjectName, ScreenshotCategory = config.ScreenshotCategory, BrowserName = config.BrowserName }; }
private void CheckScreenshotWithPattern(byte[] image, ScreenshotIdentity screenshotIdentity) { try { Action finishNotification; using (var tx = PersistanceEngine.GetSession().BeginTransaction()) { var project = this.GetProject(screenshotIdentity.ProjectName); var testCase = GetTestCase(project, screenshotIdentity); var browserPattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName); var testSession = GetCurrentTestSession(project); if (browserPattern == null) { var newPattern = testCase.AddNewPattern(image, screenshotIdentity.BrowserName); finishNotification = () => testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern); } else { var testResult = GetTestResult(image, screenshotIdentity, browserPattern); testSession.AddTestResult(testResult); finishNotification = () => { if (testResult.TestPassed) { testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, browserPattern); } else { testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, browserPattern); } }; } tx.Commit(); } finishNotification.Invoke(); } catch (Exception ex) { testRunnerAdapter.NotifyAboutError(ex); } }