forked from tryphotino/photino.NET
-
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.
Adding menu support. Fixes tryphotino#44.
- Loading branch information
Showing
18 changed files
with
927 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Versioning; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Photino.NET.Tests; | ||
|
||
[TestFixture] | ||
[Platform("win")] | ||
[SupportedOSPlatform("windows")] | ||
public sealed class MenuItemTests | ||
{ | ||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Add_ShouldThrow_WhenMenuItemHasParent() | ||
{ | ||
// Arrange | ||
|
||
using var menuItem1 = new MenuItem(new MenuItemOptions { Label = "Item 1" }); | ||
using var menuItem2 = new MenuItem(new MenuItemOptions { Label = "Item 2" }); | ||
using var menuItem3 = new MenuItem(new MenuItemOptions { Label = "Item 3" }); | ||
menuItem1.Add(menuItem3); | ||
|
||
// Act | ||
|
||
var act = () => | ||
{ | ||
menuItem2.Add(menuItem3); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<Exception>(); | ||
} | ||
|
||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Add_ShouldThrow_WhenMenuItemIsSelf() | ||
{ | ||
// Arrange | ||
|
||
using var menuItem = new MenuItem(new MenuItemOptions { Label = "Item 1" }); | ||
|
||
// Act | ||
|
||
var act = () => | ||
{ | ||
menuItem.Add(menuItem); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<Exception>(); | ||
} | ||
|
||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Add_ShouldThrow_WhenMenuSeparatorHasParent() | ||
{ | ||
// Arrange | ||
|
||
var window = new PhotinoWindow(); | ||
using var menu = new Menu(window); | ||
using var menuItem = new MenuItem(new MenuItemOptions { Label = "Item 1" }); | ||
using var menuSeparator = new MenuSeparator(); | ||
menu.Add(menuSeparator); | ||
|
||
// Act | ||
|
||
var act = () => | ||
{ | ||
menuItem.Add(menuSeparator); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<Exception>(); | ||
} | ||
|
||
[Test] | ||
public void MenuItem_ShouldInitialize_WhenImageIsNull() | ||
{ | ||
// Act & Assert | ||
|
||
_ = new MenuItem(new MenuItemOptions { Label = "Item 1" }); | ||
} | ||
|
||
[Test] | ||
public void MenuItem_ShouldInitialize_WhenLabelIsNull() | ||
{ | ||
// Act & Assert | ||
|
||
_ = new MenuItem(new MenuItemOptions { ImagePath = "image.png" }); | ||
} | ||
|
||
[Test] | ||
public void MenuItem_ShouldThrow_WhenImageDoesNotExist() | ||
{ | ||
// Act | ||
|
||
var act = () => | ||
{ | ||
_ = new MenuItem(new MenuItemOptions { ImagePath = "image_that_does_not_exist.png", Label = "Item" }); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<PhotinoNativeException>(); | ||
} | ||
} |
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,124 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Versioning; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Photino.NET.Tests; | ||
|
||
[TestFixture] | ||
[Platform("win")] | ||
[SupportedOSPlatform("windows")] | ||
public sealed class MenuTests | ||
{ | ||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Add_ShouldThrow_WhenMenuItemHasParent() | ||
{ | ||
// Arrange | ||
|
||
var window = new PhotinoWindow(); | ||
using var menu1 = new Menu(window); | ||
using var menu2 = new Menu(window); | ||
using var menuItem = new MenuItem(new MenuItemOptions { Label = "Item 1" }); | ||
menu1.Add(menuItem); | ||
|
||
// Act | ||
|
||
var act = () => | ||
{ | ||
menu2.Add(menuItem); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<Exception>(); | ||
} | ||
|
||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Add_ShouldThrow_WhenMenuSeparatorHasParent() | ||
{ | ||
// Arrange | ||
|
||
var window = new PhotinoWindow(); | ||
using var menu1 = new Menu(window); | ||
using var menu2 = new Menu(window); | ||
using var menuSeparator = new MenuSeparator(); | ||
menu1.Add(menuSeparator); | ||
|
||
// Act | ||
|
||
var act = () => | ||
{ | ||
menu2.Add(menuSeparator); | ||
}; | ||
|
||
// Assert | ||
|
||
act.Should().Throw<Exception>(); | ||
} | ||
|
||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public void Dispose_ShouldDisposeAllDescendants() | ||
{ | ||
// Arrange | ||
|
||
var window = new PhotinoWindow(); | ||
var menu = new Menu(window); | ||
|
||
MenuItem[] menuItems = | ||
[ | ||
new MenuItem(new MenuItemOptions { Label = "Item 1" }), | ||
new MenuItem(new MenuItemOptions { Label = "Item 2" }), | ||
new MenuItem(new MenuItemOptions { Label = "Item 3" }), | ||
new MenuItem(new MenuItemOptions { Label = "Item 4" }) | ||
]; | ||
|
||
menu.Add(menuItems[0]); | ||
menu.Add(menuItems[1]); | ||
menuItems[1].Add(menuItems[2]); | ||
menuItems[1].Add(menuItems[3]); | ||
|
||
// Act | ||
|
||
menu.Dispose(); | ||
|
||
// Assert | ||
|
||
using var undisposedMenuItem = new MenuItem(new MenuItemOptions { Label = "Item 5" }); | ||
|
||
foreach (var menuItem in menuItems) | ||
{ | ||
var add = () => | ||
{ | ||
menuItem.Add(undisposedMenuItem); | ||
}; | ||
|
||
add.Should().Throw<ObjectDisposedException>(); | ||
} | ||
} | ||
|
||
[Test] | ||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")] | ||
public async Task Show_ShouldThrow_WhenPhotinoHasNotInitialized() | ||
{ | ||
// Arrange | ||
|
||
var window = new PhotinoWindow(); | ||
using var menu = new Menu(window); | ||
|
||
// Act | ||
|
||
var act = async () => | ||
{ | ||
await menu.Show(0, 0); | ||
}; | ||
|
||
// Assert | ||
|
||
await act.Should().ThrowAsync<InvalidOperationException>(); | ||
} | ||
} |
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="NUnit" Version="3.14.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Photino.NET\Photino.NET.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="image.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Photino.NET; | ||
|
||
internal interface IMenuChild | ||
{ | ||
void ClearHandles(); | ||
} |
Oops, something went wrong.