Skip to content

Commit b56be4f

Browse files
committed
Save test case on assigning a test data source
Dropping a test data source on test case should update the test case.
1 parent a94d442 commit b56be4f

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

src/Pixel.Automation.Designer.ViewModels/DragDropHandlers/ComponentDragHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
using Pixel.Automation.Core.Components;
1111
using Pixel.Automation.Core.Components.Prefabs;
1212
using Pixel.Automation.Core.Components.Sequences;
13-
using Pixel.Automation.Core.Components.TestCase;
1413
using Pixel.Automation.Core.Enums;
1514
using Pixel.Automation.Core.Interfaces;
1615
using Pixel.Automation.Editor.Core;
1716
using Pixel.Automation.Editor.Core.Interfaces;
1817
using Pixel.Automation.Editor.Core.ViewModels;
19-
using Pixel.Scripting.Editor.Core.Contracts;
2018
using Serilog;
2119
using System.IO;
2220
using System.Windows;

src/Pixel.Automation.TestExplorer.ViewModels/Pixel.Automation.TestExplorer.ViewModels.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Caliburn.Micro" Version="4.0.212" />
13+
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup>
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using GongSolutions.Wpf.DragDrop;
1+
using Dawn;
2+
using GongSolutions.Wpf.DragDrop;
23
using Pixel.Automation.Core.TestData;
34
using Pixel.Automation.TestExplorer.ViewModels;
5+
using Pixel.Persistence.Services.Client.Interfaces;
46
using Serilog;
57
using System;
68
using System.Windows;
@@ -9,6 +11,14 @@ namespace Pixel.Automation.TestExplorer.Views
911
{
1012
public class TestDataSourceDropHandler : IDropTarget
1113
{
14+
private readonly ILogger logger = Log.ForContext<TestDataSourceDropHandler>();
15+
private readonly ITestCaseManager testCaseManager;
16+
17+
public TestDataSourceDropHandler(ITestCaseManager testCaseManager)
18+
{
19+
this.testCaseManager = Guard.Argument(testCaseManager, nameof(testCaseManager)).NotNull().Value;
20+
}
21+
1222
public void DragOver(IDropInfo dropInfo)
1323
{
1424
if (dropInfo.Data != null)
@@ -33,12 +43,13 @@ public void Drop(IDropInfo dropInfo)
3343
if (dropInfo.Data is TestDataSource testDataSource)
3444
{
3545
var testCase = (dropInfo.VisualTarget as FrameworkElement).DataContext as TestCaseViewModel;
36-
testCase.SetTestDataSource(testDataSource.DataSourceId);
46+
testCase.SetTestDataSource(testDataSource.DataSourceId);
47+
_ = this.testCaseManager.UpdateTestCaseAsync(testCase.TestCase);
3748
}
3849
}
3950
catch (Exception ex)
4051
{
41-
Log.Error(ex, ex.Message);
52+
logger.Error(ex, ex.Message);
4253
}
4354
}
4455
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using Caliburn.Micro;
22
using Dawn;
3+
using GongSolutions.Wpf.DragDrop;
34
using Pixel.Automation.Core;
45
using Pixel.Automation.Core.Components.TestCase;
56
using Pixel.Automation.Core.Enums;
67
using Pixel.Automation.Core.Interfaces;
78
using Pixel.Automation.Core.TestData;
89
using Pixel.Automation.Editor.Core.Interfaces;
910
using Pixel.Automation.Editor.Notifications;
11+
using Pixel.Automation.TestExplorer.Views;
1012
using Pixel.Persistence.Services.Client.Interfaces;
1113
using Pixel.Scripting.Editor.Core;
1214
using Pixel.Scripting.Editor.Core.Contracts;
@@ -47,6 +49,8 @@ public class TestExplorerViewModel : Screen, ITestExplorer, IHandle<TestFilterNo
4749

4850
public ITestRunner TestRunner { get; private set; }
4951

52+
public IDropTarget TestDataSourceDropHandler { get;}
53+
5054
/// <summary>
5155
/// A collection of TestFixtures belonging to the Automation Project
5256
/// </summary>
@@ -100,6 +104,7 @@ public TestExplorerViewModel(IEventAggregator eventAggregator, IAutomationProjec
100104
this.platformProvider = Guard.Argument(platformProvider).NotNull().Value;
101105
this.applicationSettings = Guard.Argument(applicationSettings).NotNull();
102106
this.eventAggregator.SubscribeOnPublishedThread(this);
107+
this.TestDataSourceDropHandler = new TestDataSourceDropHandler(this.testCaseManager);
103108

104109
CreateDefaultView();
105110
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
<converters:TrimmedTextConverter x:Key="trimmedTextConverter"/>
2121
<BooleanToVisibilityConverter x:Key="boolToVisConverter"/>
2222

23-
<local:TestDataSourceDropHandler x:Key="dataSourceDropHandler"/>
24-
2523
<HierarchicalDataTemplate DataType="{x:Type localVM:TestFixtureViewModel}" ItemsSource="{Binding Tests}">
2624
</HierarchicalDataTemplate>
2725

@@ -83,7 +81,7 @@
8381
<ControlTemplate TargetType="TreeViewItem">
8482
<Border x:Name="TestCase" ToolTip="{Binding Description}" ToolTipService.Placement="Right">
8583
<StackPanel Orientation="Vertical" dd:DragDrop.IsDropTarget="True"
86-
dd:DragDrop.DropHandler="{StaticResource dataSourceDropHandler}">
84+
dd:DragDrop.DropHandler="{Binding DataContext.TestDataSourceDropHandler, ElementName=TestExplorerTreeView}">
8785
<StackPanel Orientation="Horizontal" Margin="10 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center"
8886
Background="{DynamicResource MahApps.Brushes.Control.Background}"
8987
Tag="{Binding DataContext, ElementName=TestExplorerTreeView}">

0 commit comments

Comments
 (0)