Esempio n. 1
0
        public async Task TwoWay_Command_Round_Trip()
        {
            _Command = new RelaySimpleCommand(() =>
            {
                _DataContext.MainSkill = new Skill();
                _DataContext.Skills.Add(_DataContext.MainSkill);
            });

            _DataContext.TestCommand = _Command;
            var test = new TestInContextAsync()
            {
                Bind = (win) => HtmlBinding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var js = mb.JsRootObject;

                    _DataContext.Skills.Should().HaveCount(2);

                    await DoSafeAsyncUIFullCycle(() =>
                    {
                        _Command.Execute(null);
                    });

                    var res = await GetCollectionAttributeAsync(js, "Skills");

                    res.Should().NotBeNull();
                    res.GetArrayLength().Should().Be(3);
                }
            };

            await RunAsync(test);
        }
        public ChangingCollectionViewModel()
        {
            _Items = new ObservableCollection <int>(new int[] { 1, 2, 3, 4, 5 });

            Replace = new RelaySimpleCommand(DoReplace);
            Add     = new RelaySimpleCommand(DoAdd);
        }
 public NavigationViewModel(IServiceLocator serviceLocator, IRouterSolver routerSolver)
 {
     _ServiceLocator      = serviceLocator;
     _RouterSolver        = routerSolver;
     AfterResolveCommand  = new RelaySimpleCommand <string>(AfterResolve);
     BeforeResolveCommand = RelayResultCommand.Create <string, BeforeRouterResult>(BeforeResolve);
 }
Esempio n. 4
0
 public MainViewModel(ExpandoObject child)
 {
     ExpandoObject   = child;
     DynamicObject   = new DynamicObjectViewModel();
     ChangeAttribute = new RelaySimpleCommand(DoChangeAttribute);
     AddAttribute    = new RelaySimpleCommand(DoAddAttribute);
 }
Esempio n. 5
0
        public void Execute_with_object_argument_does_not_call_action_if_type_mismatch()
        {
            var action             = Substitute.For <Action <int> >();
            var relaySimpleCommand = new RelaySimpleCommand <int>(action);

            relaySimpleCommand.Execute(null);
            action.DidNotReceive().Invoke(Arg.Any <int>());
        }
 public BasicFatherTestViewModel()
 {
     Command = new RelaySimpleCommand <BasicTestViewModel>(child =>
     {
         CallCount++;
         LastCallElement = child;
     });
 }
Esempio n. 7
0
        public WindowViewModel(Window window)
        {
            _Window   = window;
            Close     = new RelaySimpleCommand(() => _Window.Close());
            Minimize  = new RelaySimpleCommand(() => State = WindowState.Minimized);
            Maximize  = new RelaySimpleCommand(() => State = WindowState.Maximized);
            Normalize = new RelaySimpleCommand(() => State = (State == WindowState.Maximized) ? WindowState.Normal : WindowState.Maximized);

            _Window.StateChanged += StateChanged;
        }
        public void RelaySimpleCommandShouldCallAction()
        {
            var action = Substitute.For <Action>();
            var target = new RelaySimpleCommand(action);
            var arg    = new object();

            target.Execute(arg);

            action.Received(1).Invoke();
        }
Esempio n. 9
0
 public SkillsViewModel()
 {
     RemoveSkill = new RelaySimpleCommand <Skill>(s => this.Skills.Remove(s));
     AddSkill    = new RelaySimpleCommand(() => { MainSkill = new Skill()
                                                  {
                                                      Type = "Type", Name = "New skill"
                                                  }; this.Skills.Add(MainSkill); });
     Skills         = new ObservableCollection <Skill>();
     SelectedSkills = new ObservableCollection <Skill>();
 }
Esempio n. 10
0
 public MainViewModel(INavigator navigator, IApplication application, IMessageBox messageBox)
 {
     _Navigator   = navigator;
     _Application = application;
     _MessageBox  = messageBox;
     GoToAbout    = new RelaySimpleCommand(DoGoToAbout);
     Restart      = new RelaySimpleCommand(DoRestart);
     AddItem      = new RelaySimpleCommand(DoAddNewItem);
     RemoveItem   = new RelaySimpleCommand <ItemViewModel>(DoRemoveItem);
 }
Esempio n. 11
0
        public Person(ICommand forTest = null)
        {
            Skills = new ObservableCollection <Skill>();

            TestCommand  = forTest;
            Command      = new RelayToogleCommand(DoCommand);
            RemoveSkill  = new RelaySimpleCommand <Skill>(s => this.Skills.Remove(s));
            ChangeSkill  = new RelaySimpleCommand <Skill>(s => MainSkill = (this.Skills.Count > 0)?this.Skills[0] : null);
            RemoveSkills = new RelaySimpleCommand <Skill>(s => Skills.Clear());
        }
Esempio n. 12
0
        public ApplicationViewModel()
        {
            ParseSQL = new RelaySimpleCommand(() =>
            {
                try
                {
                    if (Input_SQL == null)
                    {
                        Input_Valid_SQL = false; return;
                    }
                    String sql = Input_SQL.Replace("\n", " ");
                    while (sql.Last() == ' ')
                    {
                        sql = sql.Substring(0, sql.Length - 1);
                    }
                    Input_Valid_SQL = true;
                    if (sql == "")
                    {
                        Input_Valid_SQL = false; return;
                    }

                    List <State>[] stateSets = sqlParser.Parse(sql);

                    if (!sqlParser.IsValid(stateSets))
                    {
                        Input_Valid_SQL = false; return;
                    }

                    stateSets = sqlParser.FilterAndReverse(stateSets);
                    TreeNode <String> tree = sqlParser.parse_tree(sql, stateSets);

                    this.Input_RA           = SqlToRa.TranslateQuery(tree);
                    this.Parsed_SQL         = sql;
                    this.Parsed_RA_From_SQL = this.Input_RA;
                    this.Input_Type         = "ra";
                    return;
                }
                catch (HeuristicException e)
                {
                    Console.WriteLine(e.ToString());
                    Error = e.Message.Replace(Environment.NewLine, "<br/>");
                    return;
                }
            });

            ParseRA = new RelaySimpleCommand(() =>
            {
                try
                {
                    if (Input_RA == null)
                    {
                        Input_Valid_RA = false; return;
                    }
                    String ra = Input_RA.Replace("\n", " ");
                    while (ra.Last() == ' ')
                    {
                        ra = ra.Substring(0, ra.Length - 1);
                    }
                    Input_Valid_RA = true;
                    if (Input_RA == "")
                    {
                        Input_Valid_RA = false; return;
                    }

                    List <State>[] stateSets = raParser.Parse(Input_RA);

                    if (!raParser.IsValid(stateSets))
                    {
                        Input_Valid_RA = false; return;
                    }

                    if (this.Input_RA == this.Parsed_RA_From_SQL)
                    {
                        this.SQL = this.Parsed_SQL;
                    }
                    else
                    {
                        this.SQL = "";
                    }

                    this.RA = Input_RA;

                    stateSets = raParser.FilterAndReverse(stateSets);
                    TreeNode <String> tree = raParser.parse_tree(Input_RA, stateSets);

                    Squish(tree);

                    this.ops = RAToOps.Translate(tree, Relations.ToDictionary(relation => relation.name));
                    ops      = new TreeNode <Operation>(new Query())
                    {
                        ops
                    };

                    new Heuristic0(ops).Complete();

                    HeuristicsArray = new Heuristic[] {
                        new Heuristic1(ops),
                        new Heuristic2(ops),
                        new Heuristic3(ops),
                        new Heuristic4(ops),
                        new Heuristic5(ops)
                    };

                    UpdateCurrentHeuristic();

                    this.OpsJSON     = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
                    this.CurrentView = "output";
                    return;
                }
                catch (HeuristicException e)
                {
                    Console.WriteLine(e.ToString());
                    Error = e.Message.Replace(Environment.NewLine, "<br/>");
                    return;
                }
            });

            Step = new RelaySimpleCommand(() =>
            {
                try
                {
                    UpdateCurrentHeuristic();
                    if (CurrentHeuristic != null)
                    {
                        CurrentHeuristic.Step();
                    }
                    this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
                    UpdateCurrentHeuristic();
                }
                catch (HeuristicException e)
                {
                    Console.WriteLine(e.ToString());
                    Error = e.Message.Replace(Environment.NewLine, "<br/>");
                    return;
                }
            });

            Complete = new RelaySimpleCommand(() =>
            {
                try
                {
                    UpdateCurrentHeuristic();
                    if (CurrentHeuristic != null)
                    {
                        CurrentHeuristic.Complete();
                    }
                    this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
                    UpdateCurrentHeuristic();
                }
                catch (HeuristicException e)
                {
                    Console.WriteLine(e.ToString());
                    Error = e.Message.Replace(Environment.NewLine, "<br/>");
                    return;
                }
            });

            Reset = new RelaySimpleCommand(() =>
            {
                try
                {
                    List <State>[] stateSets = raParser.Parse(RA);
                    stateSets = raParser.FilterAndReverse(stateSets);
                    TreeNode <String> tree = raParser.parse_tree(RA, stateSets);

                    Squish(tree);

                    this.ops = RAToOps.Translate(tree, Relations.ToDictionary(relation => relation.name));
                    ops      = new TreeNode <Operation>(new Query())
                    {
                        ops
                    };

                    new Heuristic0(ops).Complete();

                    HeuristicsArray = new Heuristic[] {
                        new Heuristic1(ops),
                        new Heuristic2(ops),
                        new Heuristic3(ops),
                        new Heuristic4(ops),
                        new Heuristic5(ops)
                    };

                    UpdateCurrentHeuristic();

                    this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
                    return;
                }
                catch (HeuristicException e)
                {
                    Console.WriteLine(e.ToString());
                    Error = e.Message.Replace(Environment.NewLine, "<br/>");
                    return;
                }
            });

            this.DeleteRelation = new RelaySimpleCommand <Relation>(relation =>
            {
                List <Relation> list = this.Relations.ToList();
                list.Remove(relation);
                this.Relations = list.ToArray();
            });

            this.NewRelation = new RelaySimpleCommand <String>(relation =>
            {
                List <Relation> list = this.Relations.ToList();
                list.Add(new Relation(relation, new List <Field>()
                {
                    new Field("", new List <String>()
                    {
                    }), new Field("", new List <String>()
                    {
                    }), new Field("", new List <String>()
                    {
                    }), new Field("", new List <String>()
                    {
                    })
                }));
                this.Relations = list.ToArray();
            });
        }
Esempio n. 13
0
 public CardViewModel()
 {
     Insert = new RelaySimpleCommand<ItemViewModel>((it) => _Items.Insert(_Items.IndexOf(it),new ItemViewModel()));
     Remove = new RelaySimpleCommand<ItemViewModel>((it) => _Items.Remove(it));
 }
Esempio n. 14
0
 public Couple()
 {
     MakeSelf  = new RelaySimpleCommand(DoMakeSelf);
     Duplicate = new RelaySimpleCommand(DoDuplicate);
 }
Esempio n. 15
0
 public CardViewModel()
 {
     Insert = new RelaySimpleCommand <ItemViewModel>((it) => _Items.Insert(_Items.IndexOf(it), new ItemViewModel()));
     Remove = new RelaySimpleCommand <ItemViewModel>((it) => _Items.Remove(it));
 }
Esempio n. 16
0
 public Nav()
 {
     DoNav = new RelaySimpleCommand(() => { Navigation?.NavigateAsync(this); });
 }
Esempio n. 17
0
 public AA1()
 {
     Exception = new Exception();
     Change    = new RelaySimpleCommand(() => { throw Exception; });
     GoTo1     = new RelaySimpleCommand(() => Navigation.NavigateAsync(new A2()));
 }
Esempio n. 18
0
 public A1()
 {
     Change = new RelaySimpleCommand(() => Navigation.NavigateAsync(new A1()));
     GoTo1  = new RelaySimpleCommand(() => Navigation.NavigateAsync(new A2()));
 }
Esempio n. 19
0
 public Person()
 {
     GoCouple = new RelaySimpleCommand(() => { Navigation?.NavigateAsync(Couple); });
 }
Esempio n. 20
0
 public CounterViewModel()
 {
     Count         = new RelaySimpleCommand(DoCount);
     BuildBigModel = new RelaySimpleCommand(DoBuildBigModel);
 }
Esempio n. 21
0
 public RelaySimpleCommandGenericTest()
 {
     _Action             = Substitute.For <Action <string> >();
     _RelaySimpleCommand = new RelaySimpleCommand <string>(_Action);
 }
Esempio n. 22
0
 public Nav()
 {
     DoNav = new RelaySimpleCommand(Navigate);
 }
Esempio n. 23
0
 public RelaySimpleCommandTest()
 {
     _Action             = Substitute.For <Action>();
     _RelaySimpleCommand = new RelaySimpleCommand(_Action);
 }
Esempio n. 24
0
 public Couple() : base()
 {
     GoOne = new RelaySimpleCommand(() => Goto(One));
     GoTwo = new RelaySimpleCommand(() => Goto(Two));
 }