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

Tests and documentation for TabItem #386

Merged
merged 1 commit into from
Oct 1, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

using NSubstitute;
using Softeq.XToolkit.WhiteLabel.Bootstrapper.Abstract;
using Softeq.XToolkit.WhiteLabel.Model;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.ViewModels.Tab;
using Xunit;

namespace Softeq.XToolkit.WhiteLabel.Tests.Model.TabItemTests
{
public class TabItemTests
{
[Theory]
[CombinatorialData]
public void Ctor_WithViewModelAndKey_InitializesProperties(
[CombinatorialValues(null, "")] string title,
[CombinatorialValues(0, 1)] int key)
{
var container = Substitute.For<IContainer>();
var tabItem = new TabItem<ViewModelStub, int>(title, key, container);

Assert.Equal(title, tabItem.Title);
Assert.Equal(key, tabItem.Key);
}

[Theory]
[CombinatorialData]
public void CreateViewModel_CreatesAndInitializesViewModelCorrectly(
[CombinatorialValues(null, "")] string title,
[CombinatorialValues(0, 1)] int key)
{
var container = Substitute.For<IContainer>();
var frameNavigationService = Substitute.For<IFrameNavigationService>();
container.Resolve<IFrameNavigationService>().ReturnsForAnyArgs(frameNavigationService);

var tabItem = new TabItem<ViewModelStub, int>(title, key, container);
var viewModel = tabItem.CreateViewModel();

Assert.NotNull(viewModel);
Assert.IsAssignableFrom<TabViewModel<ViewModelStub, int>>(viewModel);
Assert.Equal(frameNavigationService, viewModel.FrameNavigationService);
Assert.Equal(title, viewModel.Title);
Assert.Equal(key, viewModel.Key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Softeq.XToolkit.WhiteLabel.Bootstrapper.Abstract
{
/// <summary>
/// An interface that decouples from any implementation of DI container that used for resolving dependencies.
/// DI container interface that is used for resolving dependencies.
/// </summary>
public interface IContainer
{
Expand Down
11 changes: 11 additions & 0 deletions Softeq.XToolkit.WhiteLabel/Model/DialogType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

namespace Softeq.XToolkit.WhiteLabel.Model
{
public enum DialogType
{
Default,
Destructive
}
}
7 changes: 0 additions & 7 deletions Softeq.XToolkit.WhiteLabel/Model/OpenDialogOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@

namespace Softeq.XToolkit.WhiteLabel.Model
{
public enum DialogType
{
Default,
Destructive
}

public class OpenDialogOptions
{
public bool ShouldShowBackgroundOverlay { get; set; }

public DialogType DialogType { get; set; }
}
}
38 changes: 37 additions & 1 deletion Softeq.XToolkit.WhiteLabel/Model/TabItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,66 @@

namespace Softeq.XToolkit.WhiteLabel.Model
{
/// <summary>
/// Model that represents a single tab.
/// </summary>
/// <typeparam name="TKey">Type of the tab key.</typeparam>
public abstract class TabItem<TKey>
{
/// <summary>
/// Initializes a new instance of the <see cref="TabItem{TKey}"/> class.
/// </summary>
/// <param name="title">Tab title.</param>
/// <param name="key">Tab key.</param>
protected TabItem(string title, TKey key)
{
Title = title;
Key = key;
}

/// <summary>
/// Gets the tab title.
/// </summary>
public string Title { get; }

/// <summary>
/// Gets the tab key.
/// </summary>
public TKey Key { get; }

/// <summary>
/// Creates <see cref="T:Softeq.XToolkit.WhiteLabel.ViewModels.Tab.TabViewModel`1"/>
/// and initializes it with the current <see cref="TabItem{TKey}"/>.
/// </summary>
/// <returns> Created TabViewModel.</returns>
public abstract TabViewModel<TKey> CreateViewModel();
}

/// <typeparam name="TFirstViewModel">Type of the ViewModel of the first tab.</typeparam>
/// <inheritdoc/>
public class TabItem<TFirstViewModel, TKey> : TabItem<TKey> where TFirstViewModel : ViewModelBase
{
public TabItem(string title, TKey key, IContainer container) : base(title, key)
/// <summary>
/// Initializes a new instance of the <see cref="TabItem{TFirstViewModel, TKey}"/> class.
/// </summary>
/// <param name="title">Tab title.</param>
/// <param name="key">Tab key.</param>
/// <param name="container">
/// Implementation of DI container that is required
/// for resolving the implementation of <see cref="T:Softeq.XToolkit.WhiteLabel.Navigation.IFrameNavigationService"/>.
/// </param>
public TabItem(string title, TKey key, IContainer container)
: base(title, key)
{
Container = container;
}

/// <summary>
/// Gets the implementation of DI container.
/// </summary>
protected IContainer Container { get; }

/// <inheritdoc/>
public override TabViewModel<TKey> CreateViewModel()
{
var frameNavigationService = Container.Resolve<IFrameNavigationService>();
Expand Down