-
Notifications
You must be signed in to change notification settings - Fork 0
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 #5 from RolandKoenig/3-create-viewservicehostuserc…
…ontrol-base-class 3 create viewservicehostusercontrol base class
- Loading branch information
Showing
6 changed files
with
91 additions
and
10 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
60 changes: 60 additions & 0 deletions
60
src/RolandK.AvaloniaExtensions.Tests/ViewServices/ViewServiceHostUserControlTests.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,60 @@ | ||
using RolandK.AvaloniaExtensions.Mvvm.Markup; | ||
using RolandK.AvaloniaExtensions.Tests.Util; | ||
using RolandK.AvaloniaExtensions.ViewServices; | ||
using RolandK.AvaloniaExtensions.ViewServices.Base; | ||
|
||
namespace RolandK.AvaloniaExtensions.Tests.ViewServices; | ||
|
||
[Collection(nameof(ApplicationTestCollection))] | ||
public class ViewServiceHostUserControlTests | ||
{ | ||
[Fact] | ||
public Task DefaultViewService_from_ViewServiceHostUserControl() | ||
{ | ||
return UnitTestApplication.RunInApplicationContextAsync(() => | ||
{ | ||
// Arrange | ||
var testViewServiceUserControl = new ViewServiceHostUserControl(); | ||
|
||
var hostWindow = new TestRootWindow(); | ||
hostWindow.Content = testViewServiceUserControl; | ||
|
||
// Act | ||
var srvOpenFileDialog = testViewServiceUserControl.TryFindViewService<IOpenFileViewService>(); | ||
|
||
// Assert | ||
Assert.NotNull(srvOpenFileDialog); | ||
|
||
GC.KeepAlive(hostWindow); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public Task Find_ViewService_From_ParentContainer() | ||
{ | ||
return UnitTestApplication.RunInApplicationContextAsync(() => | ||
{ | ||
// Arrange | ||
var testViewServiceUserControl = new ViewServiceHostUserControl(); | ||
|
||
var parentViewServiceUserControl = new ViewServiceHostUserControl(); | ||
parentViewServiceUserControl.Content = testViewServiceUserControl; | ||
parentViewServiceUserControl.ViewServices.Add(new DummyViewService()); | ||
|
||
var hostWindow = new TestRootWindow(); | ||
hostWindow.Content = parentViewServiceUserControl; | ||
|
||
// Act | ||
var srvOpenFileDialog = testViewServiceUserControl.TryFindViewService<IDummyViewService>(); | ||
|
||
// Assert | ||
Assert.NotNull(srvOpenFileDialog); | ||
|
||
GC.KeepAlive(hostWindow); | ||
}); | ||
} | ||
|
||
private interface IDummyViewService : IViewService { } | ||
|
||
private class DummyViewService : ViewServiceBase, IDummyViewService { } | ||
} |
27 changes: 27 additions & 0 deletions
27
src/RolandK.AvaloniaExtensions/Mvvm/Markup/ViewServiceHostUserControl.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,27 @@ | ||
using Avalonia.Controls; | ||
using RolandK.AvaloniaExtensions.ViewServices; | ||
using RolandK.AvaloniaExtensions.ViewServices.Base; | ||
|
||
namespace RolandK.AvaloniaExtensions.Mvvm.Markup; | ||
|
||
public class ViewServiceHostUserControl : UserControl, IViewServiceHost | ||
{ | ||
private ViewServiceContainer _viewServiceContainer; | ||
|
||
/// <inheritdoc /> | ||
public ICollection<IViewService> ViewServices => _viewServiceContainer.ViewServices; | ||
|
||
/// <inheritdoc /> | ||
public IViewServiceHost? ParentViewServiceHost => this.TryGetParentViewServiceHost(); | ||
|
||
public ViewServiceHostUserControl() | ||
{ | ||
_viewServiceContainer = new ViewServiceContainer(this); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public object? TryGetDefaultViewService(Type viewServiceType) | ||
{ | ||
return DefaultViewServices.TryGetDefaultViewService(this, viewServiceType); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/RolandK.AvaloniaExtensions/ViewServices/DefaultViewServices.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
7 changes: 1 addition & 6 deletions
7
src/RolandK.AvaloniaExtensions/ViewServices/IOpenDirectoryViewService.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