Exemplo n.º 1
0
        public async Task AsyncCommandBase_T_FrameworkMethodsMustBeCalledWithData_ReferenceType()
        {
            ICommand command = new AsyncTestCommand <string>();

            bool canExecute = command.CanExecute("240");

            Assert.True(canExecute);
            Assert.Throws <ArgumentNullException>("parameter", () => command.CanExecute(null));

            command.Execute("240");
            await Assert.ThrowsAsync <ArgumentNullException>("parameter", () => ((AsyncCommandBase <string>)command).InternalExecuteAsync(null));
        }
Exemplo n.º 2
0
        public async Task AsyncCommandBase_T_FrameworkMethodsMustBeCalledWithData_ValueType()
        {
            ICommand command = new AsyncTestCommand <int>();

            bool canExecute = command.CanExecute(240);

            Assert.True(canExecute);
            Assert.Throws <NullReferenceException>(() => command.CanExecute(null));

            command.Execute(240);
            await Assert.ThrowsAsync <NullReferenceException>(() => ((AsyncCommandBase <int>)command).InternalExecuteAsync(null));
        }
Exemplo n.º 3
0
        public async Task AsyncCommandBase_FrameworkMethodsMustBeCalledWithoutData()
        {
            ICommand command = new AsyncTestCommand();

            bool canExecute = command.CanExecute(null);

            Assert.True(canExecute);
            Assert.Throws <ArgumentException>("parameter", () => command.CanExecute(240));

            command.Execute(null);
            await Assert.ThrowsAsync <ArgumentException>("parameter", () => ((AsyncCommandBase)command).InternalExecuteAsync(240));
        }
Exemplo n.º 4
0
        public async Task AsyncCommandBase_T_NonGenericFrameworkMethodsMustBeCalledWithDataOfTypeCompatibleWithGenericTypeParameter()
        {
            ICommand command = new AsyncTestCommand <float>();

            Assert.Throws <InvalidCastException>(() => command.CanExecute(240.0));
            await Assert.ThrowsAsync <InvalidCastException>(() => ((AsyncCommandBase <float>)command).InternalExecuteAsync(240.0));
        }
Exemplo n.º 5
0
        public void AsyncCommandBase_T_FrameworkMethodsCallIntoStronglyTypedImplementations()
        {
            string?  text    = null;
            ICommand command = new AsyncTestCommand <string>(t => text = t, t => { text = t; return(Task.CompletedTask); });

            bool canExecute = command.CanExecute(nameof(ICommand.CanExecute));

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(nameof(ICommand.Execute));
            Assert.Equal("Execute", text);
        }
Exemplo n.º 6
0
        public void AsyncCommandBase_FrameworkMethodsCallIntoParameterlessImplementations()
        {
            string?  text    = null;
            ICommand command = new AsyncTestCommand(() => text = nameof(ICommand.CanExecute), () => { text = nameof(ICommand.Execute); return(Task.CompletedTask); });

            bool canExecute = command.CanExecute(null);

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(null);
            Assert.Equal("Execute", text);
        }