Пример #1
0
    /// <summary>
    /// Read an excel file and extract the meta, variables, and parsable rows.
    /// </summary>
    /// <param name="assetPath"></param>
    public static void ReadXLSX(string assetPath, ref ReadBundle bundle) {

        Debug.Log("START TIMELINE IMPORT PROCESS FOR XLSX");

        // get an absolute path to the asset
        string absolutePath = System.IO.Directory.GetCurrentDirectory() + "/" + assetPath;

        // open a file stream to the asset
        using (FileStream fs = new FileStream(absolutePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {

            // get workbook
            XSSFWorkbook wb = new XSSFWorkbook(fs);

			// get field names
			GetFieldNames(ref bundle.fieldNames, wb);

            // get key/value meta data
            GetKeyValData(ref bundle.meta, wb, "#");

            // get key/value 
            GetKeyValData(ref bundle.vars, wb, "$");

            // get the parsable rows
            GetParsableRows(ref bundle.rows, wb);
        }
    }
Пример #2
0
	public void ReadXlsxTest()
	{
        ExcelReader reader = new ExcelReader();
        ReadBundle readBundle = new ReadBundle();
        string testDataLocation = "/Assets/Vendor/DataHelpers/Editor/Tests/Fixtures/TestData.xlsx";
        
        ExcelReader.ReadXLSX(testDataLocation, ref readBundle);
        
        Assert.AreEqual(3, readBundle.fieldNames.Count, "it should load 3 field names");
        Assert.AreEqual(2, readBundle.rows.Count, "it should load 2 rows of data");
	}
Пример #3
0
    public void AddParsableNodesToValidatorChain()
    {
        Validator validator = new Validator();

        ParsableRow row = new ParsableRow();
        row.cells = new string[2] { "foo", "bar" };

        ReadBundle rb = new ReadBundle();
        rb.fieldNames.Add("Foo");
        rb.fieldNames.Add("Bar");
        rb.rows.Add(row);

        validator.AddParsableRows(rb);

        Assert.AreEqual(1, validator.Nodes.Length, "should have added the row to the validation chain");
    }
Пример #4
0
    public void PassCheckableNodesToUserValidator()
    {
        Validator validator = new Validator();

        ParsableRow row = new ParsableRow();
        row.cells = new string[2] { "foo", "bar" };

        ReadBundle rb = new ReadBundle();
        rb.fieldNames.Add("Foo");
        rb.fieldNames.Add("Bar");
        rb.rows.Add(row);

        validator.AddParsableRows(rb);

        IValidator userValidator = Substitute.For<IValidator>();

        validator.IsValid(rb, userValidator);

        userValidator.Received().Validate(validator.Nodes[0], validator);
    }