Skip to content

Commit

Permalink
Adding xunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benday committed Aug 18, 2024
1 parent eae6a66 commit a2601d0
Show file tree
Hide file tree
Showing 29 changed files with 1,827 additions and 102 deletions.
45 changes: 44 additions & 1 deletion MauiControlsDevelopment.sln → Benday.Presentation-Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation", "Bend
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation.Controls", "Benday.Presentation.Controls\Benday.Presentation.Controls.csproj", "{3C077B8B-D474-412C-A789-76DB38C9C3CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benday.Presentation.DemoApp", "Benday.Presentation.DemoApp\Benday.Presentation.DemoApp.csproj", "{03F339F4-5A2F-4DAD-A22F-EB20AB057EE9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation.DemoApp", "Benday.Presentation.DemoApp\Benday.Presentation.DemoApp.csproj", "{03F339F4-5A2F-4DAD-A22F-EB20AB057EE9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{01022E0C-A8E1-45DD-826E-3AE0FAC699C6}"
ProjectSection(SolutionItems) = preProject
copy-docfx-site-to-docs.sh = copy-docfx-site-to-docs.sh
generate-docfx-docs.sh = generate-docfx-docs.sh
LICENSE = LICENSE
README-for-nuget-controls.md = README-for-nuget-controls.md
README-for-nuget-presentation.md = README-for-nuget-presentation.md
README.md = README.md
run-on-iphone-simulator.sh = run-on-iphone-simulator.sh
run-on-physical-iphone.sh = run-on-physical-iphone.sh
serve-docfx-docs.sh = serve-docfx-docs.sh
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation.DemoApp.Api", "Benday.Presentation.DemoApp.Api\Benday.Presentation.DemoApp.Api.csproj", "{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation.UnitTests", "Benday.Presentation.UnitTests\Benday.Presentation.UnitTests.csproj", "{3B7792A0-8EFD-4A20-9420-97503D8B131C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benday.Presentation.DemoApp.UnitTests", "Benday.Presentation.DemoApp.UnitTests\Benday.Presentation.DemoApp.UnitTests.csproj", "{B33A341A-A13D-490E-84E3-61089B43247D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -45,6 +64,30 @@ Global
{03F339F4-5A2F-4DAD-A22F-EB20AB057EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03F339F4-5A2F-4DAD-A22F-EB20AB057EE9}.Release|Any CPU.Build.0 = Release|Any CPU
{03F339F4-5A2F-4DAD-A22F-EB20AB057EE9}.Release|Any CPU.Deploy.0 = Release|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Debug-nuget-pkgs|Any CPU.ActiveCfg = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Debug-nuget-pkgs|Any CPU.Build.0 = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.debug-only-nuget|Any CPU.ActiveCfg = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.debug-only-nuget|Any CPU.Build.0 = Debug|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81EC89F1-2785-4D4D-AFCE-9645077FAEC9}.Release|Any CPU.Build.0 = Release|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Debug-nuget-pkgs|Any CPU.ActiveCfg = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Debug-nuget-pkgs|Any CPU.Build.0 = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.debug-only-nuget|Any CPU.ActiveCfg = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.debug-only-nuget|Any CPU.Build.0 = Debug|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B7792A0-8EFD-4A20-9420-97503D8B131C}.Release|Any CPU.Build.0 = Release|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Debug-nuget-pkgs|Any CPU.ActiveCfg = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Debug-nuget-pkgs|Any CPU.Build.0 = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.debug-only-nuget|Any CPU.ActiveCfg = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.debug-only-nuget|Any CPU.Build.0 = Debug|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B33A341A-A13D-490E-84E3-61089B43247D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@


<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.80" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.80" />
</ItemGroup>

<Choose>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8;net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.80" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.80" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Benday.Presentation\Benday.Presentation.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Benday.Presentation.DemoApp.Api.Platforms.Android;

// All the code in this file is only included on Android.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Benday.Presentation.DemoApp.Api.Platforms.MacCatalyst;

// All the code in this file is only included on Mac Catalyst.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace Benday.ControlsAndViewModelSample.Api;
// All the code in this file is only included on Tizen.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Benday.Presentation.DemoApp.Api.Platforms.Windows;

// All the code in this file is only included on Windows.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Benday.Presentation.DemoApp.Api.Platforms.iOS;

// All the code in this file is only included on iOS.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System;
using Benday.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Benday.Presentation.DemoApp.ViewModels;
internal class MainPageViewModel : MessagingViewModelBase
namespace Benday.Presentation.DemoApp.Api.ViewModels;
public class MainPageViewModel : MessagingViewModelBase
{
public MainPageViewModel(IMessageManager messageManager) : base(messageManager)
{
StringField = new ViewModelField<string>(String.Empty);
IntField = new ViewModelField<int>(123);
SingleSelectField = new SingleSelectListViewModel(GetSampleItems("Combobox", 4));
ListboxSingleSelectField = new SingleSelectListViewModel(GetSampleItems("Listbox", 3));
SingleSelectField = new SingleSelectListViewModel(GetSampleItems("Combobox"));
ListboxSingleSelectField = new SingleSelectListViewModel(GetSampleItems("Single Select Listbox"));
LabelField = new ViewModelField<string>(String.Empty);
}

Expand All @@ -24,14 +25,17 @@ public MainPageViewModel(IMessageManager messageManager) : base(messageManager)
public SingleSelectListViewModel ListboxSingleSelectField { get; private set; }

private static IList<ISelectableItem> GetSampleItems(
string controlName, int itemCount)
string controlName)
{
var items = new List<ISelectableItem>();

for (int i = 1; i <= itemCount; i++)
{
items.Add(new SelectableItem(false, $"{controlName}: Item {i}"));
}
items.Add(new SelectableItem(false, $"{controlName}: Item 1"));
items.Add(new SelectableItem(true, $"{controlName}: Item 2"));
items.Add(new SelectableItem(false, $"{controlName}: Item 3"));
items.Add(new SelectableItem(false, $"{controlName}: Item 4"));
items.Add(new SelectableItem(false, $"{controlName}: Item 5"));
items.Add(new SelectableItem(false, $"{controlName}: Item 6"));
items.Add(new SelectableItem(false, $"{controlName}: Item 7"));

return items;
}
Expand All @@ -58,6 +62,26 @@ public ICommand ShowMessageCommand
}
}

private ICommand? _ShowErrorMessageCommand;
public ICommand ShowErrorMessageCommand
{
get
{
if (_ShowErrorMessageCommand == null)
{
_ShowErrorMessageCommand =
new ExceptionHandlingRelayCommand(
Messages, () =>
{
throw new InvalidOperationException(
"This is an error message.");
});
}

return _ShowErrorMessageCommand;
}
}

private ICommand? _ShowSummaryCommand;
public ICommand ShowSummaryCommand
{
Expand Down Expand Up @@ -167,8 +191,7 @@ public ICommand UpdateLabelFieldCommand
_UpdateLabelFieldCommand =
new ExceptionHandlingRelayCommand(
Messages,
() =>
{
() => {
LabelField.Value = $"Label: {DateTime.Now}";
});
}
Expand Down Expand Up @@ -205,97 +228,97 @@ private void ToggleIsValid()
}

private static void ChangeFieldSelection(SingleSelectListViewModel field)
{
var itemCount = field.Items.Count;

if (field.SelectedItem == null)
{
field.Items[0].IsSelected = true;
}
else
{
var itemCount = field.Items.Count;
var indexOf = field.Items.IndexOf(field.SelectedItem);

var newIndex = indexOf + 1;

if (field.SelectedItem == null)
if (newIndex >= itemCount)
{
field.Items[0].IsSelected = true;
newIndex = 0;
}
else
{
var indexOf = field.Items.IndexOf(field.SelectedItem);

var newIndex = indexOf + 1;

if (newIndex >= itemCount)
{
newIndex = 0;
}

field.Items[newIndex].IsSelected = true;
}
field.Items[newIndex].IsSelected = true;
}
}


private void ShowSummary()
private void ShowSummary()
{
var builder = new StringBuilder();

builder.AppendLine("Button clicked.");
builder.Append("String Field: ");
builder.AppendLine(StringField.Value);
builder.Append("Visible: ");
builder.AppendLine(StringField.IsVisible.ToString());
builder.Append("Valid: ");
builder.AppendLine(StringField.IsValid.ToString());

builder.Append("Int Field: ");
builder.AppendLine(IntField.Value.ToString());
builder.Append("Visible: ");
builder.AppendLine(IntField.IsVisible.ToString());
builder.Append("Valid: ");
builder.AppendLine(IntField.IsValid.ToString());

SummarizeSingleSelect(builder,
SingleSelectField,
"Combobox Single Select Field");

SummarizeSingleSelect(builder,
ListboxSingleSelectField,
"Listbox Single Select Field");

Messages.ShowMessage(builder.ToString(), "Summary");
}

private static void SummarizeSingleSelect(
StringBuilder builder, SingleSelectListViewModel viewModel,
string description)
{
builder.AppendLine("***");
builder.Append($"{description}: ");
if (viewModel.SelectedItem == null)
{
var builder = new StringBuilder();

builder.AppendLine("Button clicked.");
builder.Append("String Field: ");
builder.AppendLine(StringField.Value);
builder.Append("Visible: ");
builder.AppendLine(StringField.IsVisible.ToString());
builder.Append("Valid: ");
builder.AppendLine(StringField.IsValid.ToString());

builder.Append("Int Field: ");
builder.AppendLine(IntField.Value.ToString());
builder.Append("Visible: ");
builder.AppendLine(IntField.IsVisible.ToString());
builder.Append("Valid: ");
builder.AppendLine(IntField.IsValid.ToString());

SummarizeSingleSelect(builder,
SingleSelectField,
"Combobox Single Select Field");

SummarizeSingleSelect(builder,
ListboxSingleSelectField,
"Listbox Single Select Field");

Messages.ShowMessage(builder.ToString(), "Summary");
builder.AppendLine("(value is null)");
}

private static void SummarizeSingleSelect(
StringBuilder builder, SingleSelectListViewModel viewModel,
string description)
else
{
builder.AppendLine("***");
builder.Append($"{description}: ");
if (viewModel.SelectedItem == null)
{
builder.AppendLine("(value is null)");
}
else
{
builder.AppendLine(viewModel.SelectedItem.Text);
}
builder.AppendLine(viewModel.SelectedItem.Text);
}

builder.Append("Visible: ");
builder.AppendLine(viewModel.ToString());
builder.Append("Valid: ");
builder.AppendLine(viewModel.IsValid.ToString());
builder.Append("Visible: ");
builder.AppendLine(viewModel.ToString());
builder.Append("Valid: ");
builder.AppendLine(viewModel.IsValid.ToString());

builder.AppendLine();
}
builder.AppendLine();
}

public void ToggleVisibility()
{
StringField.IsVisible = !StringField.IsVisible;
LabelField.IsVisible = !LabelField.IsVisible;
IntField.IsVisible = !IntField.IsVisible;
SingleSelectField.IsVisible = !SingleSelectField.IsVisible;
ListboxSingleSelectField.IsVisible = !ListboxSingleSelectField.IsVisible;
}
public void ToggleVisibility()
{
StringField.IsVisible = !StringField.IsVisible;
LabelField.IsVisible = !LabelField.IsVisible;
IntField.IsVisible = !IntField.IsVisible;
SingleSelectField.IsVisible = !SingleSelectField.IsVisible;
ListboxSingleSelectField.IsVisible = !ListboxSingleSelectField.IsVisible;
}

public void ToggleEnabled()
{
StringField.IsEnabled = !StringField.IsEnabled;
LabelField.IsEnabled = !LabelField.IsEnabled;
IntField.IsEnabled = !IntField.IsEnabled;
SingleSelectField.IsEnabled = !SingleSelectField.IsEnabled;
ListboxSingleSelectField.IsEnabled = !ListboxSingleSelectField.IsEnabled;
}
public void ToggleEnabled()
{
StringField.IsEnabled = !StringField.IsEnabled;
LabelField.IsEnabled = !LabelField.IsEnabled;
IntField.IsEnabled = !IntField.IsEnabled;
SingleSelectField.IsEnabled = !SingleSelectField.IsEnabled;
ListboxSingleSelectField.IsEnabled = !ListboxSingleSelectField.IsEnabled;
}
}
Loading

0 comments on commit a2601d0

Please sign in to comment.