-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8791 from par456/8784DataDateChecks
8784 Check if string column should be date when reading from excel
- Loading branch information
Showing
5 changed files
with
149 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using APSIM.Shared.Utilities; | ||
using Models.PostSimulationTools; | ||
using Models.Storage; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Data; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace UnitTests | ||
{ | ||
public class ExcelInputTests | ||
{ | ||
private IDatabaseConnection database; | ||
|
||
/// <summary>Find and return the file name of SQLite runtime .dll</summary> | ||
public static string FindSqlite3DLL() | ||
{ | ||
string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
string[] files = Directory.GetFiles(directory, "sqlite3.dll"); | ||
if (files.Length == 1) | ||
return files[0]; | ||
|
||
throw new Exception("Cannot find sqlite3 dll directory"); | ||
} | ||
|
||
[Test] | ||
public void LoadExcelInput() | ||
{ | ||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); | ||
|
||
if (ProcessUtilities.CurrentOS.IsWindows) | ||
{ | ||
string sqliteSourceFileName = FindSqlite3DLL(); | ||
Directory.SetCurrentDirectory(Path.GetDirectoryName(sqliteSourceFileName)); | ||
} | ||
|
||
database = new SQLite(); | ||
database.OpenDatabase(":memory:", readOnly: false); | ||
|
||
var dataStore = new DataStore(database); | ||
dataStore.Writer.TablesModified.Add("Observed"); | ||
|
||
ExcelInput excelInput = new ExcelInput(); | ||
excelInput.FileNames = new string[] {"%root%/Tests/UnitTests/PostSimulationTools/Input.xlsx"}; | ||
excelInput.SheetNames = new string[] {"Sheet1"}; | ||
|
||
Utilities.InjectLink(excelInput, "storage", dataStore); | ||
|
||
excelInput.Run(); | ||
dataStore.Writer.Stop(); | ||
dataStore.Reader.Refresh(); | ||
|
||
DataTable dt = dataStore.Reader.GetData("Sheet1"); | ||
|
||
Assert.AreEqual(dt.Columns[4].DataType, typeof(DateTime)); | ||
Assert.AreEqual(dt.Columns[5].DataType, typeof(string)); | ||
Assert.AreEqual(dt.Columns[6].DataType, typeof(string)); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters