Ejemplo n.º 1
0
        public void ActionCommands_FireAsExpected()
        {
            // arrange
            var fireBasic = new MockActionCommand();
            var fireParameter = new MockActionCommand();

            ICommand basicCommand = new ActionCommand(fireBasic.ExecuteNone, fireBasic.CanExecute);
            ICommand valueTypeCommand = new ActionCommand<int>(fireParameter.ExecuteParam, fireParameter.CanExecuteParam);

            // act
            basicCommand.Execute(null);
            basicCommand.Execute("n/a input");
            valueTypeCommand.Execute(2);

            Assert.IsTrue(basicCommand.CanExecute(null));
            Assert.IsTrue(basicCommand.CanExecute("any input ignored"));
            Assert.IsTrue(valueTypeCommand.CanExecute(1));

            // assert
            Assert.IsTrue(fireBasic.ExecuteFired);
            Assert.IsTrue(fireBasic.TestFired);

            Assert.IsTrue(fireParameter.ExecuteFired);
            Assert.IsTrue(fireParameter.TestFired);
            Assert.AreEqual(2, fireParameter.ObjectsPassedIn.Count);
            Assert.AreEqual(3, fireParameter.ObjectsPassedIn.Sum());
        }
		public void Execute_and_Parameters() {
			const Int32 initial = Int32.MinValue;
			var value = initial;
			var command = new ActionCommand<Int32>(x => value = x);

			Assert.IsTrue(command.CanExecute(0));
			Assert.IsTrue(command.CanExecute(1));

			Assert.AreEqual(initial, value);
			command.Execute(1);
			Assert.AreEqual(1, value);

			command.Execute(0);
			Assert.AreEqual(0, value);
		}
Ejemplo n.º 3
0
        public void ActionCommands_InvalidInput_RespondsAsExpected()
        {
            // arrange
            var fireBasic = new MockActionCommand();
            var fireParameter = new MockActionCommand();

            ICommand parameterCommandInt32 = new ActionCommand<int>(fireParameter.ExecuteParam, fireParameter.CanExecuteParam);
            ICommand parameterCommandObject = new ActionCommand<object>((o) => { });
            ICommand parameterCommandObjectFunc = new ActionCommand<object>((o) => { }, (o) => { return true; });

            // assert
            try
            {
                parameterCommandInt32.CanExecute(null);
                Assert.Fail("Expected error");
            }
            catch (NullReferenceException) { }
            try
            {
                parameterCommandInt32.Execute(null);
                Assert.Fail("Expected error");
            }
            catch (NullReferenceException) { }

            parameterCommandObject.Execute(null);
            parameterCommandObjectFunc.Execute(null);

            Assert.IsTrue(parameterCommandObject.CanExecute(null));
            Assert.IsTrue(parameterCommandObjectFunc.CanExecute(null));
        }
Ejemplo n.º 4
0
        public void CanExecute_Generic()
        {
            var random = new Random();
            var parameter = random.Next();

            var command = new ActionCommand<int>(null, i => { return true; });

            Assert.IsTrue(command.CanExecute(parameter));
        }
Ejemplo n.º 5
0
        public void CanExecute_Default()
        {
            var random = new Random();
            var parameter = random.Next();

            var command = new ActionCommand(null, null);

            Assert.IsTrue(command.CanExecute(parameter));
        }