protected void Initialise( string specificationNamespace, string specificationName) { workbook = Workbook(specificationNamespace); worksheet = Worksheet(specificationName); }
public string GenerateCSharpTestCode(IEnumerable <string> usings, string assertionClassPrefix, ITabularPage worksheet, string projectRootNamespace, string workBookName) { _worksheet = worksheet; _code = new AutoIndentingStringBuilder(" "); _column = 1; _row = 1; _assertionClassPrefix = assertionClassPrefix ?? ""; var description = DoSpecification(); DoGiven(usings, description, projectRootNamespace, workBookName); DoWhen(); DoAssert(); EndSpecification(); return(_code.ToString()); }
string OutputWorkSheet(string workBookName, ITabularPage sheet) { var sheetConverter = new ExcelToCode(new CodeNameToExcelNameConverter(assertionClassPrefix)); sheetConverter.AddVisitor(givenClassRecorder); var generatedTest = sheetConverter.GenerateCSharpTestCode( usings, sheet, projectRootNamespace, workBookName); generatedTest.Errors.ToList().ForEach(error => logger.LogWorkbookError(workBookName, sheet.Name, error)); generatedTest.Warnings.ToList().ForEach(warning => logger.LogWarning(workBookName, sheet.Name, warning)); generatedTest.IssuesPreventingRoundTrip.ToList().ForEach(issue => logger.LogIssuePreventingRoundTrip(workBookName, sheet.Name, issue)); return(generatedTest.Code); }
GeneratedTest TryGenerateCSharpTestCode( IEnumerable <string> usings, ITabularPage worksheet, string projectRootNamespace, string workBookName) { Initialise(worksheet); var sutName = ReadSutName(); var description = ReadDescription(); DoHeaders( sutName, usings, description, projectRootNamespace, workBookName); DoGiven(sutName); excel.MoveDown(); CheckExactlyOneBlankLineBetweenGivenAndWhen(); DoWhen(sutName); excel.MoveDown(); // Looks like there should be a CheckExactlyOneBlankLineBetweenWhenAndThen() function DoThen(sutName); DoFooters(); return (new GeneratedTest( code.GeneratedCode, log.Errors, log.Warnings, log.IssuesPreventingRoundTrip )); }
public GeneratedTest GenerateCSharpTestCode( IEnumerable <string> usings, ITabularPage worksheet, string projectRootNamespace, string workBookName) { try { return(TryGenerateCSharpTestCode( usings, worksheet, projectRootNamespace, workBookName)); } catch (ExcelToCodeException exception) { return(Error(exception.Message)); } catch (Exception exception) { return(Error($"Unable to convert worksheet due to an unexpected internal error:\n{exception.ToString()}")); } }
public void Initialise(ITabularPage worksheet) { Excel.Initialise(worksheet); Code.Initialise(); Log.Initialise(); }
bool IsTestSheet(ITabularPage excelSheet) => excelSheet.GetCell(1, 1).Value != null && (excelSheet.GetCell(1, 1).Value.ToString() == "Specification");
void Initialise(ITabularPage worksheet) => excelToCodeState.Initialise(worksheet);
internal void Initialise(ITabularPage worksheet) { Worksheet = worksheet; Row = 1; Column = 1; }
private static string OutputWorkSheet(string outputFolder, IEnumerable <string> usings, string assertionClassPrefix, string workBookName, ITabularPage sheet, string projectRootNamespace) { var sheetConverter = new ExcelToCode(new CodeNameToExcelNameConverter(assertionClassPrefix)); var projectRelativePath = Path.Combine(workBookName, sheet.Name + ".cs"); var outputPath = Path.Combine(outputFolder, projectRelativePath); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); using (var outputFile = new StreamWriter(outputPath)) { try { outputFile.Write(sheetConverter.GenerateCSharpTestCode(usings, assertionClassPrefix, sheet, projectRootNamespace, workBookName)); } catch (Exception ex) { outputFile.Write(string.Format("Error creating c# from Excel: {0}", ex.Message)); } } return(projectRelativePath); }
private static bool IsTestSheet(ITabularPage excelSheet) { return(excelSheet.GetCell(1, 1).Value != null ? (excelSheet.GetCell(1, 1).Value.ToString() == "Specification") : false); }