Example #1
0
        public void when_can_execute_is_property_name_then_retrieves_value_from_target()
        {
            var command = new JsonCommand (
                JObject.Parse (@"{ ""$CanExecute"": ""IsEnabled"", ""Name"": ""kzu""  }"),
                JObject.Parse (@"{ ""IsEnabled"": true  }"));

            Assert.True (command.CanExecute (null));
        }
Example #2
0
        public void when_can_execute_changes_then_raises_can_execute_changed()
        {
            var json = JObject.Parse (@"{ ""$CanExecute"": false, ""Name"": ""kzu""  }");
            var command = new JsonCommand (json,
                JObject.Parse (@"{ ""Name"": ""vga""  }"));

            var changed = false;
            command.CanExecuteChanged += (_, __) => changed = true;

            Assert.False (json.Property ("$CanExecute").Value.Value<bool> ());
            Assert.False (command.CanExecute (null));

            json.Property ("$CanExecute").Value = true;

            Assert.True (command.CanExecute (null));
            Assert.True (changed);
        }
Example #3
0
        public void when_command_executed_then_applies_changes()
        {
            var target = JObject.Parse (@"{ ""Name"": ""kzu""  }");
            var command = new JsonCommand (
                JObject.Parse (@"{ ""Name"": ""vga""  }"),
                target);

            command.Execute (null);

            Assert.Equal ("vga", target.Property ("Name").Value.Value<string> ());
        }
Example #4
0
        public void when_no_can_execute_exists_then_can_execute_true()
        {
            var command = new JsonCommand (
                JObject.Parse (@"{ ""Name"": ""kzu""  }"),
                JObject.Parse (@"{ ""Name"": ""vga""  }"));

            Assert.True (command.CanExecute (null));
        }
Example #5
0
        public void when_can_execute_property_path_changes_then_raises_can_execute_changed()
        {
            var target = JObject.Parse (@"
            {
            ""Connection"": {
            ""Status"": {
            ""IsEnabled"": true
            }
            }
            }");
            var command = new JsonCommand (
                JObject.Parse (@"{ ""$CanExecute"": ""Connection.Status.IsEnabled"", ""Name"": ""kzu""  }"),
                target);

            var changed = false;
            command.CanExecuteChanged += (_, __) => changed = true;

            target.Property ("Connection").Value.Value<JObject> ()
                .Property ("Status").Value.Value<JObject> ()
                .Property ("IsEnabled").Value = false;

            Assert.False (command.CanExecute (null));
            Assert.True (changed);
        }