Skip to content

Commit ad9885e

Browse files
authored
Merge pull request #191 from Nfactor26/load-test-cases-on-fixture-expanded
Load test cases only when the fixture is expanded
2 parents 29bed63 + 4dff55b commit ad9885e

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/Pixel.Automation.TestExplorer.ViewModels/TestExplorerViewModel.cs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public TestExplorerViewModel(IEventAggregator eventAggregator, IAutomationProjec
112112
/// <summary>
113113
/// Load the fixtures and test case from local storage
114114
/// </summary>
115-
async Task LoadDataAsync()
115+
async Task LoadFixturesAsync()
116116
{
117117
try
118118
{
@@ -129,18 +129,6 @@ async Task LoadDataAsync()
129129
}
130130
TestFixtureViewModel testFixtureVM = new TestFixtureViewModel(testFixture);
131131
this.TestFixtures.Add(testFixtureVM);
132-
133-
foreach (var testCaseDirectory in Directory.GetDirectories(Path.Combine(this.fileSystem.TestCaseRepository, testFixture.FixtureId)))
134-
{
135-
var testCase = this.fileSystem.LoadFiles<TestCase>(testCaseDirectory).Single();
136-
if(testCase.IsDeleted)
137-
{
138-
continue;
139-
}
140-
TestCaseViewModel testCaseVM = new TestCaseViewModel(testCase);
141-
testFixtureVM.Tests.Add(testCaseVM);
142-
}
143-
144132
}
145133
isInitialized = true;
146134
}
@@ -151,6 +139,27 @@ async Task LoadDataAsync()
151139
}
152140
}
153141

142+
void LoadTestCasesForFixture(TestFixtureViewModel testFixtureViewModel)
143+
{
144+
try
145+
{
146+
foreach (var testCaseDirectory in Directory.GetDirectories(Path.Combine(this.fileSystem.TestCaseRepository, testFixtureViewModel.FixtureId)))
147+
{
148+
var testCase = this.fileSystem.LoadFiles<TestCase>(testCaseDirectory).Single();
149+
if (testCase.IsDeleted)
150+
{
151+
continue;
152+
}
153+
TestCaseViewModel testCaseVM = new TestCaseViewModel(testCase);
154+
testFixtureViewModel.Tests.Add(testCaseVM);
155+
}
156+
}
157+
catch (Exception ex)
158+
{
159+
logger.Error(ex, "There was an error while trying to load test cases for fixture : {0}", testFixtureViewModel.DisplayName);
160+
}
161+
}
162+
154163
/// <summary>
155164
/// Setup the collection view with grouping and sorting
156165
/// </summary>
@@ -171,6 +180,14 @@ private void CreateDefaultView()
171180
});
172181
}
173182

183+
public void OnFixtureExpanded(TestFixtureViewModel testFixtureViewModel)
184+
{
185+
if(!testFixtureViewModel.Tests.Any())
186+
{
187+
LoadTestCasesForFixture(testFixtureViewModel);
188+
}
189+
}
190+
174191
#endregion Constructor
175192

176193
#region Test Fixture
@@ -1155,7 +1172,10 @@ private async Task<bool> TryRunTestCaseAsync(TestCaseViewModel testCaseVM)
11551172
/// <returns></returns>
11561173
protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
11571174
{
1158-
await LoadDataAsync();
1175+
if(!isInitialized)
1176+
{
1177+
await LoadFixturesAsync();
1178+
}
11591179
await base.OnInitializeAsync(cancellationToken);
11601180
}
11611181

src/Pixel.Automation.TestExplorer.Views/TestExplorerView.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@
181181
<ControlTemplate TargetType="TreeViewItem">
182182
<StackPanel Orientation="Vertical">
183183
<Expander x:Name="TestCategory" Header="{Binding DisplayName, Converter={StaticResource trimmedTextConverter}, ConverterParameter = 20}"
184-
Tag="{Binding DataContext, ElementName=TestExplorerTreeView}"
185-
Background="{DynamicResource MahApps.Brushes.Window.Background}"
184+
Tag="{Binding DataContext, ElementName=TestExplorerTreeView}" Background="{DynamicResource MahApps.Brushes.Window.Background}"
185+
cal:Action.TargetWithoutContext="{Binding DataContext, ElementName=TestExplorerTreeView}"
186+
cal:Message.Attach="[Event Expanded] = [Action OnFixtureExpanded($dataContext)]"
186187
controls:HeaderedControlHelper.HeaderBackground="{DynamicResource MahApps.Brushes.Window.Background}"
187188
BorderThickness="0" Margin="5,0,0,0" FontSize="11">
188189
<ItemsPresenter x:Name="ItemsHost"/>

0 commit comments

Comments
 (0)