This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert AsyncValueCommandSupport"
This reverts commit 07a178c.
- Loading branch information
1 parent
07a178c
commit 7c82bc8
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...s/ObjectModel/ICommandTests/CommandFactoryTests/CommandFactory_AsyncValueCommand_Tests.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,115 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xamarin.CommunityToolkit.Exceptions; | ||
using Xamarin.CommunityToolkit.ObjectModel; | ||
using Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.AsyncValueCommandTests; | ||
using Xunit; | ||
|
||
namespace Xamarin.CommunityToolkit.UnitTests.ObjectModel.ICommandTests.CommandFactoryTests | ||
{ | ||
public class CommandFactoryAsyncValueCommandTests : BaseAsyncValueCommandTests | ||
{ | ||
|
||
[Fact] | ||
public void NullExecuteParameter() | ||
{ | ||
// Arrange | ||
Func<ValueTask> execute = null; | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.Throws<ArgumentNullException>(() => CommandFactory.Create(execute)); | ||
} | ||
|
||
[Fact] | ||
public void NullCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create(NoParameterTask, null); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.True(command.CanExecute(null)); | ||
Assert.True(command.CanExecute(string.Empty)); | ||
Assert.True(command.CanExecute(0)); | ||
} | ||
|
||
[Fact] | ||
public void IntExecuteNullCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create<int>(IntParameterTask, null); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.True(command.CanExecute(null)); | ||
Assert.True(command.CanExecute(string.Empty)); | ||
Assert.True(command.CanExecute(0)); | ||
|
||
command.Execute(0); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.Execute(null)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.Execute(string.Empty)); | ||
} | ||
|
||
[Fact] | ||
public void IntExecuteTrueCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create<int>(IntParameterTask, CanExecuteTrue); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.True(command.CanExecute(null)); | ||
Assert.True(command.CanExecute(string.Empty)); | ||
Assert.True(command.CanExecute(0)); | ||
} | ||
|
||
[Fact] | ||
public void IntExecuteFalseCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create<int>(IntParameterTask, CanExecuteFalse); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.False(command.CanExecute(null)); | ||
Assert.False(command.CanExecute(string.Empty)); | ||
Assert.False(command.CanExecute(0)); | ||
} | ||
|
||
[Fact] | ||
public void IntExecuteNullTypedCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create<int, bool>(IntParameterTask, null); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.True(command.CanExecute(true)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(null)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(string.Empty)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(0)); | ||
} | ||
|
||
[Fact] | ||
public void IntExecuteBoolCanExecuteParameter() | ||
{ | ||
// Arrange | ||
var command = CommandFactory.Create<int, bool>(IntParameterTask, CanExecuteTrue); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.True(command.CanExecute(true)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(null)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(string.Empty)); | ||
Assert.Throws<InvalidCommandParameterException>(() => command.CanExecute(0)); | ||
} | ||
} | ||
} |
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