public void SetUp(ReporterSettings reporterSettings) { Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() .CreateLogger(); SerilogLogger.Debug("Logger initialization done"); }
public void CanCreateWithSettings() { ReporterManager.TearDown(); var s = new ReporterSettings { DefaultSettings = new ProjectSettings { RunGuid = Guid.NewGuid().ToString(), DataServiceFile = "Ghpr.LocalFileSystem.dll", LoggerFile = "", OutputPath = @"\\server\folder", ProjectName = "cool project", RealTimeGeneration = true, ReportName = "report name", Retention = new RetentionSettings { Amount = 3, Till = DateTime.Now }, RunName = "run name", RunsToDisplay = 7 } }; ReporterManager.Initialize(s, new MockTestDataProvider()); Assert.AreEqual(s.DefaultSettings.OutputPath, ReporterManager.OutputPath); }
public void InitTest() { var logger = new EmptyLogger(); var settings = new ReporterSettings(); var cache = CommonCache.Instance; Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataReader()); Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataWriter()); Assert.Throws <NullReferenceException>(() => cache.SaveTestRun(new TestRunDto(), new TestOutputDto())); Assert.Throws <NullReferenceException>(() => cache.GetTestRun(new ItemInfoDto())); Assert.Throws <NullReferenceException>(() => cache.GetReportSettings()); Assert.Throws <NullReferenceException>(() => cache.GetLatestTestRun(Guid.NewGuid())); Assert.Throws <NullReferenceException>(() => cache.GetRun(Guid.NewGuid())); Assert.Throws <NullReferenceException>(() => cache.GetRunInfos()); Assert.Throws <NullReferenceException>(() => cache.GetTestInfos(Guid.NewGuid())); Assert.Throws <NullReferenceException>(() => cache.GetTestOutput(new TestRunDto())); Assert.Throws <NullReferenceException>(() => cache.GetTestRunsFromRun(new RunDto())); Assert.Throws <NullReferenceException>(() => cache.GetTestScreenshots(new TestRunDto())); Assert.Throws <NullReferenceException>(() => cache.SaveReportSettings(new ReportSettingsDto(1, 2, "", ""))); Assert.Throws <NullReferenceException>(() => cache.SaveRun(new RunDto())); var scr = new TestScreenshotDto { Base64Data = "adfas", Format = "png", TestGuid = Guid.NewGuid(), TestScreenshotInfo = new SimpleItemInfoDto { Date = DateTime.Now, ItemName = "item" } }; Assert.Throws <NullReferenceException>(() => cache.SaveScreenshot(scr)); Assert.Throws <NullReferenceException>(() => cache.UpdateTestOutput(new ItemInfoDto(), new TestOutputDto())); Assert.Throws <NullReferenceException>(() => cache.DeleteRun(new ItemInfoDto())); Assert.Throws <NullReferenceException>(() => cache.DeleteTest(new TestRunDto())); Assert.Throws <NullReferenceException>(() => cache.DeleteTestOutput(new TestRunDto(), new TestOutputDto())); Assert.Throws <NullReferenceException>(() => cache.DeleteTestScreenshot(new TestRunDto(), new TestScreenshotDto())); cache.InitializeDataWriter(settings.DefaultSettings, logger); cache.InitializeDataReader(settings.DefaultSettings, logger); Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataReader()); Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataWriter()); Assert.DoesNotThrow(() => cache.SaveTestRun(new TestRunDto(), new TestOutputDto())); Assert.DoesNotThrow(() => cache.GetTestRun(new ItemInfoDto())); Assert.DoesNotThrow(() => cache.GetReportSettings()); Assert.DoesNotThrow(() => cache.GetLatestTestRun(Guid.NewGuid())); Assert.DoesNotThrow(() => cache.GetRun(Guid.NewGuid())); Assert.DoesNotThrow(() => cache.GetRunInfos()); Assert.DoesNotThrow(() => cache.GetTestInfos(Guid.NewGuid())); Assert.DoesNotThrow(() => cache.GetTestOutput(new TestRunDto())); Assert.DoesNotThrow(() => cache.GetTestRunsFromRun(new RunDto())); Assert.DoesNotThrow(() => cache.GetTestScreenshots(new TestRunDto())); Assert.DoesNotThrow(() => cache.SaveReportSettings(new ReportSettingsDto(1, 2, "", ""))); Assert.DoesNotThrow(() => cache.SaveRun(new RunDto())); Assert.DoesNotThrow(() => cache.SaveScreenshot(scr)); Assert.DoesNotThrow(() => cache.UpdateTestOutput(new ItemInfoDto(), new TestOutputDto())); Assert.DoesNotThrow(() => cache.DeleteRun(new ItemInfoDto())); Assert.DoesNotThrow(() => cache.DeleteTest(new TestRunDto())); Assert.DoesNotThrow(() => cache.DeleteTestOutput(new TestRunDto(), new TestOutputDto())); Assert.DoesNotThrow(() => cache.DeleteTestScreenshot(new TestRunDto(), scr)); cache.TearDown(); }
public void InitializeDataWriter(ReporterSettings settings, ILogger logger) { var couchDbSettings = "Ghpr.CouchDb.Settings.json".LoadSettingsAs <CouchDbSettings>(); Database = new CouchDbDatabase(couchDbSettings, logger); Database.CreateDb(); Database.ValidateConnection(); }
private static IReporter InitializeReporter(ReporterSettings settings, ITestDataProvider testDataProvider, string projectName = "") { ProjectSettings reporterProjectSettings; if (!string.IsNullOrEmpty(projectName) && settings.Projects.Any(s => projectName.Like(s.Pattern))) { var specificProjectSettings = settings.Projects.First(s => projectName.Like(s.Pattern)); reporterProjectSettings = specificProjectSettings.Settings.GetFromSourceOrDefault(settings.DefaultSettings); } else { reporterProjectSettings = settings.DefaultSettings; } if (reporterProjectSettings.OutputPath == null) { throw new ArgumentNullException(nameof(reporterProjectSettings.OutputPath), "Reporter Output path must be specified! Please fix your .json settings file. " + $"Your settings are: {JToken.FromObject(settings)}"); } var logger = CreateInstanceFromFile <ILogger>(reporterProjectSettings.LoggerFile, new EmptyLogger()); logger.SetUp(reporterProjectSettings); var dataReaderService = CreateInstanceFromFile <IDataReaderService>(reporterProjectSettings.DataServiceFile); dataReaderService.InitializeDataReader(reporterProjectSettings, logger); var dataWriterService = CreateInstanceFromFile <IDataWriterService>(reporterProjectSettings.DataServiceFile); dataWriterService.InitializeDataWriter(reporterProjectSettings, logger, dataReaderService); var actionHelper = new ActionHelper(logger); var reporter = new Reporter { Action = actionHelper, Logger = logger, TestDataProvider = testDataProvider, ReporterSettings = reporterProjectSettings, ReportSettings = new ReportSettingsDto(reporterProjectSettings.RunsToDisplay, reporterProjectSettings.TestsToDisplay, reporterProjectSettings.ReportName, reporterProjectSettings.ProjectName), DataWriterService = dataWriterService, DataReaderService = dataReaderService, RunRepository = new RunDtoRepository(), TestRunsRepository = new TestRunsRepository(), TestRunProcessor = new TestRunDtoProcessor(), ReportCleanUpProcessor = new ReportCleanUpProcessor(logger, actionHelper), TestRunStarted = false }; return(reporter); }
public void SetUp(ReporterSettings reporterSettings) { var settings = "Ghpr.SimpleFileLogger.Settings.json".LoadSettingsAs <LoggerSettings>(); _outputPath = settings.OutputPath ?? reporterSettings.OutputPath; _fileName = settings.FileName ?? "GhprLog.txt"; var success = Enum.TryParse(settings.LogLevel, out _loggerLogLevel); if (!success) { _loggerLogLevel = LogLevel.Info; } }
public void CanCreateWithSettings() { var s = new ReporterSettings { DefaultSettings = new ProjectSettings { RunGuid = Guid.NewGuid().ToString(), DataServiceFile = "Ghpr.LocalFileSystem.dll", LoggerFile = "", OutputPath = @"\\server\folder", ProjectName = "cool project", RealTimeGeneration = true, ReportName = "report name", Retention = new RetentionSettings { Amount = 3, Till = DateTime.Now }, RunName = "run name", RunsToDisplay = 7 } }; var r = ReporterFactory.Build(s, _provider); Assert.NotNull(r.ReporterSettings); Assert.NotNull(r.Action); Assert.NotNull(r.DataReaderService); Assert.NotNull(r.DataWriterService); Assert.NotNull(r.TestDataProvider); Assert.NotNull(r.Logger); Assert.IsInstanceOf(typeof(EmptyLogger), r.Logger); Assert.IsInstanceOf(typeof(MockTestDataProvider), r.TestDataProvider); Assert.IsInstanceOf(typeof(FileSystemDataReaderService), r.DataReaderService.GetDataReader()); Assert.IsInstanceOf(typeof(FileSystemDataWriterService), r.DataWriterService.GetDataWriter()); Assert.AreEqual(s.DefaultSettings.ProjectName, r.ReporterSettings.ProjectName); Assert.AreEqual(s.DefaultSettings.ReportName, r.ReporterSettings.ReportName); Assert.AreEqual(s.DefaultSettings.RunGuid, r.ReporterSettings.RunGuid); Assert.AreEqual(s.DefaultSettings.DataServiceFile, r.ReporterSettings.DataServiceFile); Assert.AreEqual(s.DefaultSettings.LoggerFile, r.ReporterSettings.LoggerFile); Assert.AreEqual(s.DefaultSettings.OutputPath, r.ReporterSettings.OutputPath); Assert.AreEqual(s.DefaultSettings.RealTimeGeneration, r.ReporterSettings.RealTimeGeneration); Assert.AreEqual(s.DefaultSettings.Retention.Till, r.ReporterSettings.Retention.Till); Assert.AreEqual(s.DefaultSettings.Retention.Amount, r.ReporterSettings.Retention.Amount); Assert.AreEqual(s.DefaultSettings.RunName, r.ReporterSettings.RunName); Assert.AreEqual(s.DefaultSettings.RunsToDisplay, r.ReporterSettings.RunsToDisplay); Assert.AreEqual(s.DefaultSettings.OutputPath, r.ReporterSettings.OutputPath); Assert.AreEqual(s.DefaultSettings.RunsToDisplay, r.ReportSettings.RunsToDisplay); Assert.AreEqual(s.DefaultSettings.TestsToDisplay, r.ReportSettings.TestsToDisplay); Assert.AreEqual(s.DefaultSettings.ProjectName, r.ReportSettings.ProjectName); Assert.AreEqual(s.DefaultSettings.ReportName, r.ReportSettings.ReportName); }
public void OnRunStarted(ReporterSettings settings, DateTime runStartDateTime) { CurrentRun = new RunDto { RunInfo = new ItemInfoDto { Guid = settings.RunGuid.Equals("") || settings.RunGuid.Equals("null") ? Guid.NewGuid() : Guid.Parse(settings.RunGuid), Start = runStartDateTime }, Name = settings.RunName, Sprint = settings.Sprint, TestsInfo = new List <ItemInfoDto>(), RunSummary = new RunSummaryDto() }; }
private static IReporter InitializeReporter(ReporterSettings settings, ITestDataProvider testDataProvider) { if (settings.OutputPath == null) { throw new ArgumentNullException(nameof(settings.OutputPath), "Reporter Output path must be specified. Please fix your .json settings file."); } StaticLog.Initialize(settings.OutputPath); var uri = new Uri(typeof(ReporterFactory).Assembly.CodeBase); var dataServiceAssemblyFullPath = Path.Combine(Path.GetDirectoryName(uri.LocalPath) ?? "", settings.DataServiceFile); var dataServiceAssembly = Assembly.LoadFrom(dataServiceAssemblyFullPath); var dataServiceType = dataServiceAssembly.GetTypes() .FirstOrDefault(t => typeof(IDataService).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract); if (dataServiceType == null) { throw new NullReferenceException($"Can't find implementation of {nameof(IDataService)} in {settings.DataServiceFile} file. " + "Please fix your .json settings file."); } var dataService = Activator.CreateInstance(dataServiceType) as IDataService; if (dataService == null) { throw new NullReferenceException($"Can't find create instance of type {nameof(dataServiceType)} from {settings.DataServiceFile} file. " + "Please fix your .json settings file."); } dataService.Initialize(settings); var reporter = new Reporter { Action = new ActionHelper(settings.OutputPath), TestDataProvider = testDataProvider, ReporterSettings = settings, ReportSettings = new ReportSettingsDto(settings.RunsToDisplay, settings.TestsToDisplay), DataService = dataService, RunRepository = new RunDtoRepository(), TestRunsRepository = new TestRunsRepository(), TestRunProcessor = new TestRunDtoProcessor(), TestRunStarted = false }; return(reporter); }
private static IReporter InitializeReporter(ReporterSettings settings, ITestDataProvider testDataProvider) { if (settings.OutputPath == null) { throw new ArgumentNullException(nameof(settings.OutputPath), "Reporter Output path must be specified. Please fix your .json settings file."); } var logger = CreateInstanceFromFile <ILogger>(settings.LoggerFile, new EmptyLogger()); logger.SetUp(settings); var dataWriterService = CreateInstanceFromFile <IDataWriterService>(settings.DataServiceFile); dataWriterService.InitializeDataWriter(settings, logger); var dataReaderService = CreateInstanceFromFile <IDataReaderService>(settings.DataServiceFile); dataReaderService.InitializeDataReader(settings, logger); CommonCache.Instance.InitializeDataReader(settings, logger); CommonCache.Instance.InitializeDataWriter(settings, logger); var actionHelper = new ActionHelper(logger); var reporter = new Reporter { Action = actionHelper, Logger = logger, TestDataProvider = testDataProvider, ReporterSettings = settings, ReportSettings = new ReportSettingsDto(settings.RunsToDisplay, settings.TestsToDisplay, settings.ReportName), DataWriterService = new DataWriterService(dataWriterService, CommonCache.Instance), DataReaderService = new DataReaderService(dataReaderService, CommonCache.Instance), RunRepository = new RunDtoRepository(), TestRunsRepository = new TestRunsRepository(), TestRunProcessor = new TestRunDtoProcessor(), ReportCleanUpProcessor = new ReportCleanUpProcessor(logger, actionHelper), TestRunStarted = false }; return(reporter); }
public override void GenerateReport(string reportFilePath, ReporterSettings reporterSettings) { using (DocX document = DocX.Create(reportFilePath)) { for (int i = 0; i < FilesToProcess.Length; i++) { if (System.IO.File.Exists(FilesToProcess[i])) { OnNameReport("Генерация отчета"); DocX docToInsert = null; try { docToInsert = PrepareReport(reportFilePath, FilesToProcess[i], reporterSettings); } catch (Exception ex) { Logging.Logger.Log(Logging.SeverityGrades.Error, string.Format("Can't create report for file {0}, reason: {1}", FilesToProcess[i], ex.Message)); continue; } document.InsertDocument(docToInsert); if (i != FilesToProcess.Length - 1) { document.InsertSectionPageBreak(); } OnProgressReport((int)(i / (float)FilesToProcess.Length * 100)); OnCancelWorker(); } } document.Save(); } }
public void InitializeDataWriter(ReporterSettings settings, ILogger logger) { _dataWriterService.InitializeDataWriter(settings, logger); _cache.InitializeDataWriter(settings, logger); }
public static IReporter Build(ReporterSettings settings, ITestDataProvider testDataProvider) { return(InitializeReporter(settings, testDataProvider)); }
private DocX PrepareReport(string reportFilePath, string locatorFilePath, ReporterSettings reporterSettings) { DocX document = DocX.Create(reportFilePath); var prop = new Files.FileProperties(locatorFilePath); var fileHeader = Factories.Header.Abstract.HeaderFactory.GetFactory(prop) .Create(locatorFilePath); var file = Factories.File.Abstract.FileFactory.GetFactory(prop) .Create(prop, fileHeader, null); Paragraph p = document.InsertParagraph(); p.Alignment = Alignment.center; p.Append(System.IO.Path.GetFileName(locatorFilePath)).Bold().FontSize(20) .Append(Environment.NewLine) .Append(Environment.NewLine); if (reporterSettings.AddArea) { p.Append(string.Format("Площадь засвеченной поверхности: {0}км2", (Factories.AreaSizeCalc.Abstract.AreaSizeCalcFactory.GetFactory(file .Properties).Create(file.Header).CalculateArea(file.Width, file.Height) / 1000 / 1000) .ToString(".################################"))) .Append(Environment.NewLine); } var cornerCoord = Factories.CornerCoords.Abstract.CornerCoordFactory .GetFactory(file.Properties) .Create(file, reporterSettings.FirstLineOffset, reporterSettings.LastLineOffset, reporterSettings.ReadToEnd); if (reporterSettings.AddTimes) { Paragraph timesParagraph = document.InsertParagraph(); timesParagraph.Alignment = Alignment.left; foreach (var entry in cornerCoord.GetZoneStartAndEndTimes()) { timesParagraph.Append(string.Format("{0}: {1}", entry.Item1, entry.Item2)); timesParagraph.Append(Environment.NewLine); } } if (reporterSettings.AddCenter) { Paragraph cornersParagraph = document.InsertParagraph(); cornersParagraph.Alignment = Alignment.left; foreach (var entry in cornerCoord.GetCenterCoordinates()) { cornersParagraph.Append(string.Format("{0}: {1}", entry.Item1, entry.Item2)); cornersParagraph.Append(Environment.NewLine); } } if (reporterSettings.AddCorners) { Paragraph cornersParagraph = document.InsertParagraph(); cornersParagraph.Alignment = Alignment.left; foreach (var entry in cornerCoord.GetCoornerCoordinates()) { cornersParagraph.Append(string.Format("{0}: {1}", entry.Item1, entry.Item2)); cornersParagraph.Append(Environment.NewLine); } } if (reporterSettings.AddParametersTable) { foreach (var subHeaderInfo in file.Header.HeaderInfo) { var headerTable = PrepareHeaderInfoTable(document, subHeaderInfo); headerTable.AutoFit = AutoFit.Window; document.InsertTable(headerTable); } } return document; }
public void InitializeDataWriter(ReporterSettings settings, ILogger logger) { _locationsProvider = new LocationsProvider(settings.OutputPath); _logger = logger; }
public void SetUp(ReporterSettings reporterSettings) { }
public void Initialize(ReporterSettings settings) { _locationsProvider = new LocationsProvider(settings.OutputPath); ReporterSettings = settings; }
public abstract void GenerateReport(string reportFilePath, ReporterSettings reporterSettings);
public static IReporter Build(ReporterSettings settings, ITestDataProvider testDataProvider, string projectName = "") { return(InitializeReporter(settings, testDataProvider, projectName)); }