/// <summary /> public MockTable GetMockTable() { var columns = this.Fields.Select(i => (i.Name, i.DataType)).ToArray(); var table = new MockTable().AddColumns(columns); foreach (var row in this.Rows) { table.AddRow(row); } return(table); }
/// <summary /> public static MockTable FromCsv(string content, string delimiter, CsvImportOptions options) { var table = MockTable.Empty(); Type[] types = null; bool isFirstRow = true; // First row = Column names bool isFirstDataRow = false; // Second row = First data row bool mustRemoveEmptyLines = (options & CsvImportOptions.RemoveEmptyLines) == CsvImportOptions.RemoveEmptyLines; bool mustTrimLines = (options & CsvImportOptions.TrimLines) == CsvImportOptions.TrimLines; foreach (string row in content.Split(SPLIT_NEWLINE, StringSplitOptions.None)) { if (mustRemoveEmptyLines && string.IsNullOrEmpty(row)) { } else { string[] data; string[] split_delimiter = new string[] { delimiter }; if (mustTrimLines) { data = row.Trim().Split(split_delimiter, StringSplitOptions.None); } else { data = row.Split(split_delimiter, StringSplitOptions.None); } if (isFirstRow) { table.AddColumns(data); } else { if (isFirstDataRow) { types = GetTypesOfFirstDataRow(data); } table.AddRow(ConvertStringToTypes(data, types)); } isFirstRow = false; isFirstDataRow = !isFirstDataRow ? true : isFirstDataRow; } } return(table); }
/// <summary> /// Load all Embedded resource "[TagName].txt" with Fixed format. /// And add it as <see cref="WhenTag(string)"/> method. /// </summary> /// <param name="assembly"></param> /// <param name="fileNames"></param> public void LoadTagsFromResources(Assembly assembly, params string[] fileNames) { string[] allResources = assembly.GetManifestResourceNames(); foreach (var filename in fileNames) { string resourceName = allResources.FirstOrDefault(i => i.EndsWith($".{filename}.{MockResourceOptions.Extension}", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(resourceName)) { // Split the filename to "[Identifier]-[TagName]" string[] resourceNameParts = filename.Split(new[] { MockResourceOptions.TagSeparator }, StringSplitOptions.RemoveEmptyEntries); string tagName = resourceNameParts.Length == 2 ? resourceNameParts[1] : filename; this.WhenTag(tagName) .ReturnsTable(MockTable.FromFixed(assembly, resourceName)); } } }
/// <summary> /// Sets <seealso cref="MockTable"/> with sample data, when the condition occured. /// </summary> /// <param name="returns"><seealso cref="MockTable"/> with sample data</param> public void ReturnsTable(MockTable returns) { ReturnsFunction = (cmd) => new[] { returns }; }
/// <summary> /// Sets <seealso cref="MockTable"/> with sample data, when the condition occured. /// </summary> /// <param name="returns"><seealso cref="MockTable"/> with sample data</param> public void ReturnsRow(MockTable returns) { ReturnsFunction = (cmd) => returns; }