Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 create viewservicehostusercontrol base class #5

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<!-- Version -->
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionSuffix>preview1</VersionSuffix>
</PropertyGroup>

<!-- Nuget -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using RolandK.AvaloniaExtensions.ViewServices;
using RolandK.AvaloniaExtensions.ViewServices.Base;

namespace RolandK.AvaloniaExtensions.Tests.Views;
namespace RolandK.AvaloniaExtensions.Tests.Mvvm;

[Collection(nameof(ApplicationTestCollection))]
public class MvvmUserControlTests
Expand Down
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 { }
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using RolandK.AvaloniaExtensions.Views;
using RolandK.AvaloniaExtensions.ViewServices.FileDialogs;
using RolandK.AvaloniaExtensions.ViewServices.MessageBox;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RolandK.AvaloniaExtensions.ViewServices.Base;
using RolandK.AvaloniaExtensions.ViewServices.Base;

namespace RolandK.AvaloniaExtensions.ViewServices;

Expand Down
Loading