-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/load_optional_file_for_genbil_(#582)' into develop
- Loading branch information
Showing
8 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
NBi.Testing.GenbiL/Action/Case/LoadFileOptionalCaseActionTest.cs
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,38 @@ | ||
using NBi.GenbiL; | ||
using NBi.GenbiL.Action.Case; | ||
using NBi.GenbiL.Stateful; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.Testing.GenbiL.Action.Case | ||
{ | ||
public class LoadFileOptionalCaseActionTest | ||
{ | ||
public class LoadOptionalCaseFromFileActionTestable : LoadOptionalCaseFromFileAction | ||
{ | ||
public LoadOptionalCaseFromFileActionTestable(string filename, IEnumerable<string> columnNames) | ||
: base(filename, columnNames) { } | ||
|
||
protected override bool IsExistingFile() => false; | ||
} | ||
|
||
[Test] | ||
public void Execute_FileMissing_EmptyDataSetWithExpectedColumns() | ||
{ | ||
var state = new GenerationState(); | ||
var action = new LoadOptionalCaseFromFileActionTestable("file.csv", new[] { "foo", "bar" }); | ||
action.Execute(state); | ||
|
||
var caseSet = state.CaseCollection.First().Value; | ||
Assert.That(caseSet.Content.Rows, Has.Count.EqualTo(0)); | ||
Assert.That(caseSet.Content.Columns, Has.Count.EqualTo(2)); | ||
Assert.That(caseSet.Content.Columns.Cast<DataColumn>().Select(x => x.ColumnName), Does.Contain("foo")); | ||
Assert.That(caseSet.Content.Columns.Cast<DataColumn>().Select(x => x.ColumnName), Does.Contain("bar")); | ||
} | ||
} | ||
} |
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
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using NBi.Core.FlatFile; | ||
using NBi.GenbiL.Stateful; | ||
|
||
namespace NBi.GenbiL.Action.Case | ||
{ | ||
public class LoadOptionalCaseFromFileAction : LoadCaseFromFileAction | ||
{ | ||
public IEnumerable<string> ColumnNames { get; set; } | ||
|
||
public LoadOptionalCaseFromFileAction(string filename, IEnumerable<string> columnNames) | ||
: base(filename) => ColumnNames = columnNames; | ||
|
||
public override void Execute(CaseSet testCases) | ||
{ | ||
if (IsExistingFile()) | ||
base.Execute(testCases); | ||
else | ||
{ | ||
testCases.Content = new DataTable(); | ||
foreach (var columnName in ColumnNames) | ||
testCases.Content.Columns.Add(new DataColumn(columnName, typeof(object))); | ||
testCases.Content.AcceptChanges(); | ||
} | ||
} | ||
|
||
protected virtual bool IsExistingFile() => File.Exists(Filename); | ||
|
||
public override string Display => $"Loading test-cases from CSV file '{Filename}', if missing create empty test-case with following columns {string.Join(", ", ColumnNames)}."; | ||
} | ||
} |
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