public async Task AsyncValueCommandExecuteAsync_StringParameter_Test(string parameter)
        {
            //Arrange
            AsyncValueCommand <string> command = new AsyncValueCommand <string>(StringParameterTask);

            //Act
            await command.ExecuteAsync(parameter);

            //Assert
        }
        public async Task AsyncValueCommandExecuteAsync_IntParameter_Test(int parameter)
        {
            //Arrange
            AsyncValueCommand <int> command = new AsyncValueCommand <int>(IntParameterTask);

            //Act
            await command.ExecuteAsync(parameter);

            //Assert
        }
Beispiel #3
0
        public async Task AsyncValueCommandExecuteAsync_StringParameter_Test(string parameter)
        {
            // Arrange
            var command  = new AsyncValueCommand <string>(StringParameterTask);
            var command2 = new AsyncValueCommand <string, bool>(StringParameterTask, CanExecuteTrue);

            // Act
            await command.ExecuteAsync(parameter);

            await command2.ExecuteAsync(parameter);

            // Assert
        }
Beispiel #4
0
        public async Task AsyncValueCommandExecuteAsync_IntParameter_Test(int parameter)
        {
            // Arrange
            var command  = new AsyncValueCommand <int>(IntParameterTask);
            var command2 = new AsyncValueCommand <int, string>(IntParameterTask, CanExecuteTrue);

            // Act
            await command.ExecuteAsync(parameter);

            await command2.ExecuteAsync(parameter);

            // Assert
        }
        public async Task AsyncValueCommand_ExecuteAsync_StringParameter_Test(string parameter)
        {
            // Arrange
            IAsyncValueCommand <string>      command  = new AsyncValueCommand <string>(StringParameterTask);
            IAsyncValueCommand <string, int> command2 = new AsyncValueCommand <string, int>(StringParameterTask);

            // Act
            await command.ExecuteAsync(parameter).ConfigureAwait(false);

            await command2.ExecuteAsync(parameter).ConfigureAwait(false);

            // Assert
        }
Beispiel #6
0
        public async Task AsyncValueCommand_NoParameter_CanExecuteChanged_DoesNotAllowMultipleExecutions_Test()
        {
            // Arrange
            var semaphoreSlim              = new SemaphoreSlim(1, 1);
            var canExecuteChangedCount     = 0;
            var handleCanExecuteChangedTCS = new TaskCompletionSource <int>();

            var command = new AsyncValueCommand(() => IntParameterTask(Delay), allowsMultipleExecutions: false);

            command.CanExecuteChanged += handleCanExecuteChanged;

            async void handleCanExecuteChanged(object?sender, EventArgs e)
            {
                await semaphoreSlim.WaitAsync().ConfigureAwait(false);

                try
                {
                    if (++canExecuteChangedCount is 2)
                    {
                        command.CanExecuteChanged -= handleCanExecuteChanged;
                        handleCanExecuteChangedTCS.SetResult(canExecuteChangedCount);
                    }
                }
                finally
                {
                    semaphoreSlim.Release();
                }
            }

            Assert.False(command.AllowsMultipleExecutions);

            // Act
            var asyncCommandTask = command.ExecuteAsync();

            // Assert
            Assert.IsTrue(command.IsExecuting);
            Assert.False(command.CanExecute(null));

            // Act
            await asyncCommandTask.ConfigureAwait(false);

            var handleCanExecuteChangedResult = await handleCanExecuteChangedTCS.Task.ConfigureAwait(false);

            // Assert
            Assert.IsTrue(command.CanExecute(null));
            Assert.AreEqual(2, canExecuteChangedCount);
            Assert.AreEqual(canExecuteChangedCount, handleCanExecuteChangedResult);
        }