Пример #1
0
        public void Create_ExecuteActionWithoutParameter_CanExecuteFuncWithoutParameter()
        {
            // Arrange
            var wasExecuted = false;

            void Execute() => wasExecuted = true;

            var canExecuteToBeReturned = false;

            bool CanExecute() => canExecuteToBeReturned;

            // Act
            var relayCommand = RelayCommand.Create(Execute, CanExecute);

            canExecuteToBeReturned = true;
            var canExecuteResultTrue = relayCommand.CanExecute(null);

            canExecuteToBeReturned = false;
            var canExecuteResultFalse = relayCommand.CanExecute(null);

            relayCommand.Execute(null);

            // Assert
            Assert.That(canExecuteResultTrue, Is.True);
            Assert.That(canExecuteResultFalse, Is.False);
            Assert.That(wasExecuted, Is.True);
        }
Пример #2
0
        public MainViewModel(IEventBus eventBus, IVersionProvider versionProvider, IProjectService projectService,
                             INewProjectDialogViewModelFactory newProjectDialogViewModelFactory, IEnumerable <Tool> tools, ICompositeDocumentFactory compositeDocumentFactory)
        {
            _versionProvider = versionProvider;
            _projectService  = projectService;
            _newProjectDialogViewModelFactory = newProjectDialogViewModelFactory;
            _compositeDocumentFactory         = compositeDocumentFactory;

            foreach (var tool in tools)
            {
                ToolsViewModels.Add(tool.CreateViewModel());
            }

            _currentProjectName = CreateProperty <string>(nameof(CurrentProjectName));
            _applicationTitle   = CreateComputedProperty(nameof(ApplicationTitle), _currentProjectName, currentProjectName =>
            {
                var prefix = string.IsNullOrEmpty(currentProjectName) ? string.Empty : $"{CurrentProjectName} - ";
                return($"{prefix}Geisha Editor {ApplicationVersion}");
            });

            NewProjectCommand    = RelayCommand.Create(NewProject);
            OpenProjectCommand   = RelayCommand.Create(OpenProject);
            _closeProjectCommand = RelayCommand.Create(CloseProject, CanCloseProject);
            SaveCommand          = RelayCommand.Create(Save);
            ExitCommand          = RelayCommand.Create(Exit);

            _projectService.CurrentProjectChanged += ProjectServiceOnCurrentProjectChanged;

            eventBus.RegisterEventHandler <OpenFileEditorRequestedEvent>(OpenFileEditorRequestedEventHandler);
        }
Пример #3
0
        public void Create_ExecuteActionWithReferenceTypeParameter_CanExecuteFuncWithReferenceTypeParameter()
        {
            // Arrange
            object?actualExecuteParameter = null;

            void Execute(object?parameter) => actualExecuteParameter = parameter;

            object?actualCanExecuteParameter = null;
            var    canExecuteToBeReturned    = false;

            bool CanExecute(object?parameter)
            {
                actualCanExecuteParameter = parameter;
                return(canExecuteToBeReturned);
            }

            var expectedParameter = new object();

            // Act
            var relayCommand = RelayCommand.Create <object>(Execute, CanExecute);

            canExecuteToBeReturned = true;
            var canExecuteResultTrue = relayCommand.CanExecute(expectedParameter);

            canExecuteToBeReturned = false;
            var canExecuteResultFalse = relayCommand.CanExecute(expectedParameter);

            relayCommand.Execute(expectedParameter);

            // Assert
            Assert.That(canExecuteResultTrue, Is.True);
            Assert.That(canExecuteResultFalse, Is.False);
            Assert.That(actualCanExecuteParameter, Is.EqualTo(expectedParameter));
            Assert.That(actualExecuteParameter, Is.EqualTo(expectedParameter));
        }
Пример #4
0
        public ChannelWatcherBase(ITankBotLogger logger)
        {
            _logger = logger;

            StartWatcherCommand        = RelayCommand.Create(StartWatcher);
            StopWatcherCommand         = RelayCommand.Create(StopWatcher);
            StopWatcherCommand.Enabled = false;
        }
Пример #5
0
        public SoccerBotBase()
        {
            ForwardCommand   = RelayCommand.Create(SendCommand, Commands.Forward);
            StopCommand      = RelayCommand.Create(SendCommand, Commands.Stop);
            BackwardsCommand = RelayCommand.Create(SendCommand, Commands.Backwards);
            LeftCommand      = RelayCommand.Create(SendCommand, Commands.Left);
            RightCommand     = RelayCommand.Create(SendCommand, Commands.Right);
            ResetCommand     = RelayCommand.Create(SendCommand, Commands.Reset);

            FirmwareVersion = "??";
        }
Пример #6
0
        public ToolViewModel(string title, IView view, ViewModel viewModel, bool isVisible)
        {
            _title     = CreateProperty(nameof(Title), title);
            _isVisible = CreateProperty(nameof(IsVisible), isVisible);

            View             = view;
            View.DataContext = viewModel;

            ShowCommand  = RelayCommand.Create(() => IsVisible = true);
            CloseCommand = RelayCommand.Create(() => IsVisible = false);
        }
Пример #7
0
        public FileViewModel(IProjectFile file, IEventBus eventBus, ICreateTextureAssetCommandFactory createTextureAssetCommandFactory,
                             ICreateSpriteAssetCommandFactory createSpriteAssetCommandFactory, ICreateSoundAssetCommandFactory createSoundAssetCommandFactory) : base(file.Name)
        {
            _file     = file;
            _eventBus = eventBus;
            _createTextureAssetCommandFactory = createTextureAssetCommandFactory;
            _createSpriteAssetCommandFactory  = createSpriteAssetCommandFactory;
            _createSoundAssetCommandFactory   = createSoundAssetCommandFactory;

            DoubleClickCommand = RelayCommand.Create(OnDoubleClick);
            CreateContextMenuActions();
        }
Пример #8
0
        public TankBotBase()
        {
            ForwardCommand   = RelayCommand.Create(SendCommand, Commands.Forward);
            StopCommand      = RelayCommand.Create(SendCommand, Commands.Stop);
            BackwardsCommand = RelayCommand.Create(SendCommand, Commands.Backwards);
            LeftCommand      = RelayCommand.Create(SendCommand, Commands.Left);
            RightCommand     = RelayCommand.Create(SendCommand, Commands.Right);
            ResetCommand     = RelayCommand.Create(SendCommand, Commands.Reset);

            _sensorRefreshTimer = new Timer(_sensorRefreshTimer_Tick, null, Timeout.Infinite, Timeout.Infinite);

            FirmwareVersion = UNKOWN_VERSION;
        }
Пример #9
0
        public TankBotBase()
        {
            ForwardCommand   = RelayCommand.Create(SendCommand, Commands.Forward);
            StopCommand      = RelayCommand.Create(SendCommand, Commands.Stop);
            BackwardsCommand = RelayCommand.Create(SendCommand, Commands.Backwards);
            LeftCommand      = RelayCommand.Create(SendCommand, Commands.Left);
            RightCommand     = RelayCommand.Create(SendCommand, Commands.Right);
            ResetCommand     = RelayCommand.Create(SendCommand, Commands.Reset);

            _sensorRefreshTimer = Services.TimerFactory.Create(TimeSpan.FromMilliseconds(500));

            FirmwareVersion = UNKOWN_VERSION;
        }
Пример #10
0
 public AppWindow()
 {
     MinimizeCommand    = RelayCommand.Create((p) => WindowState = WindowState.Minimized);
     ChangeStateCommand = RelayCommand.Create(RunChangeStateCommand);
     CloseCommand       = RelayCommand.Create((p) => Close());
     /* see comments in this method */
     SetMaxHeight();
     /* see comments in this method */
     SystemParameters.StaticPropertyChanged += SystemParametersStaticPropertyChanged;
     Loaded           += (s, e) => OnLoaded(s, e);
     UseLayoutRounding = true;
     RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
 }
Пример #11
0
        public AddContextMenuItem(
            IEventBus eventBus,
            IProject?project,
            IProjectFolder?folder,
            IAddSceneDialogViewModelFactory addSceneDialogViewModelFactory) : base("Add")
        {
            _eventBus = eventBus;
            _project  = project;
            _folder   = folder;
            _addSceneDialogViewModelFactory = addSceneDialogViewModelFactory;

            Items.Add(new ContextMenuItem("New Folder", RelayCommand.Create(NewFolder)));
            Items.Add(new ContextMenuItem("Scene", RelayCommand.Create(Scene)));
        }
Пример #12
0
        public void RaiseCanExecuteChanged_ShouldRaiseCanExecuteChangedEvent()
        {
            // Arrange
            var wasCanExecuteChangedRaised = false;

            var relayCommand = RelayCommand.Create(() => { });

            relayCommand.CanExecuteChanged += (sender, args) => wasCanExecuteChangedRaised = true;

            // Act
            relayCommand.RaiseCanExecuteChanged();

            // Assert
            Assert.That(wasCanExecuteChangedRaised, Is.True);
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageWindow"/> class
 /// </summary>
 private MessageWindow(MessageWindowType type, string message, Window owner, bool autoOwner)
 {
     MessageWindowType = type;
     ResizeMode        = ResizeMode.NoResize;
     SizeToContent     = SizeToContent.Height;
     Topmost           = true;
     Owner             = owner;
     if (owner == null && autoOwner)
     {
         Owner = Application.Current.MainWindow;
     }
     WindowStartupLocation = Owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
     Message          = message;
     ButtonYesCommand = RelayCommand.Create((p) => Close(true));
     ButtonNoCommand  = RelayCommand.Create((p) => Close(false));
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppWindow"/> class.
 /// </summary>
 public AppWindow()
 {
     MinimizeCommand    = RelayCommand.Create((p) => WindowState = WindowState.Minimized);
     ChangeStateCommand = RelayCommand.Create(RunChangeStateCommand);
     CloseCommand       = RelayCommand.Create((p) => Close());
     /* see comments in this method */
     SetMaxHeight();
     /* see comments in this method */
     SystemParameters.StaticPropertyChanged += SystemParametersStaticPropertyChanged;
     Loaded           += (s, e) => OnLoaded(s, e);
     UseLayoutRounding = true;
     //RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
     // Default for the following is: Auto, Ideal, Auto
     TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);
     TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
     TextOptions.SetTextHintingMode(this, TextHintingMode.Fixed);
 }
Пример #15
0
        public mBlockSoccerBot(IChannel channel, ITankBotLogger logger, string pin = "9999") : this()
        {
            _pin     = pin;
            _logger  = logger;
            _channel = channel;
            _channel.MessageReceived += _channel_MessageReceived;
            Name = "mSoccerBot";

            _timer = new Timer((state) => { RequestVersion(); }, null, 0, 5000);

            ModeACommand          = RelayCommand.Create(SendModeA);
            ModeBCommand          = RelayCommand.Create(SendModeB);
            ModeCCommand          = RelayCommand.Create(SendModeC);
            SendLEDMessageCommand = RelayCommand.Create(SendLEDMessage);

            _start = DateTime.Now;
        }
Пример #16
0
        public SceneRootViewModel(SceneModel sceneModel, IEventBus eventBus, IEntityPropertiesEditorViewModelFactory entityPropertiesEditorViewModelFactory)
        {
            _sceneModel = sceneModel;
            _eventBus   = eventBus;
            _entityPropertiesEditorViewModelFactory = entityPropertiesEditorViewModelFactory;

            Name = "Scene";

            foreach (var entityModel in _sceneModel.RootEntities)
            {
                Items.Add(new EntityViewModel(entityModel, _eventBus, _entityPropertiesEditorViewModelFactory));
            }

            ContextMenuItems.Add(new ContextMenuItem("Add entity", RelayCommand.Create(AddEntity)));

            _sceneModel.EntityAdded += SceneModelOnEntityAdded;
        }
Пример #17
0
        private MainWindowViewModel()
        {
            DisplayName = "Restless Toolkit Demo";
            Pages       = new ObservableCollection <ViewModelBase>();

            Commands.Add("ToggleAllowTabReorder", RelayCommand.Create(p => AllowTabReorder = !AllowTabReorder));
            Commands.Add("ToggleKeepContentOnTabSwitch", RelayCommand.Create(p => KeepContentOnTabSwitch = !KeepContentOnTabSwitch));
            Commands.Add("ToggleSeattle", p => IsSeattleChecked = !IsSeattleChecked);
            Commands.Add("ToggleNewYork", p => IsNewYorkChecked = !IsNewYorkChecked);
            DisplayUnloadTabCommand      = RelayCommand.Create(p => Create <DemoViewModel>());
            ToggleBorderThicknessCommand = RelayCommand.Create(RunToggleBorderThicknessCommand);

            TabBorderThickness = new Thickness(1.0);
            AllowTabReorder    = true;
            IsSeattleChecked   = true;
            InitializePages();
        }
Пример #18
0
        public void Create_ExecuteActionWithoutParameter()
        {
            // Arrange
            var wasExecuted = false;

            void Execute() => wasExecuted = true;

            // Act
            var relayCommand     = RelayCommand.Create(Execute);
            var canExecuteResult = relayCommand.CanExecute(null);

            relayCommand.Execute(null);

            // Assert
            Assert.That(canExecuteResult, Is.True);
            Assert.That(wasExecuted, Is.True);
        }
Пример #19
0
        public EntityViewModel(EntityModel entityModel, IEventBus eventBus, IEntityPropertiesEditorViewModelFactory entityPropertiesEditorViewModelFactory)
        {
            _entityModel = entityModel;
            _eventBus    = eventBus;
            _entityPropertiesEditorViewModelFactory = entityPropertiesEditorViewModelFactory;

            Name = _entityModel.Name;

            foreach (var model in _entityModel.Children)
            {
                Items.Add(new EntityViewModel(model, _eventBus, _entityPropertiesEditorViewModelFactory));
            }

            ContextMenuItems.Add(new ContextMenuItem("Add child entity", RelayCommand.Create(AddChildEntity)));

            _entityModel.EntityAdded += EntityModelOnEntityAdded;
            _entityModel.NameChanged += EntityModelOnNameChanged;
        }
Пример #20
0
        public void Create_ExecuteActionWithValueTypeParameter()
        {
            // Arrange
            int?actualParameter = null;

            void Execute(int?parameter) => actualParameter = parameter;

            const int expectedParameter = 1;

            // Act
            var relayCommand     = RelayCommand.Create <int>(Execute);
            var canExecuteResult = relayCommand.CanExecute(expectedParameter);

            relayCommand.Execute(expectedParameter);

            // Assert
            Assert.That(canExecuteResult, Is.True);
            Assert.That(actualParameter, Is.EqualTo(expectedParameter));
        }
Пример #21
0
        public void Create_ExecuteActionWithReferenceTypeParameter()
        {
            // Arrange
            object?actualParameter = null;

            void Execute(object?parameter) => actualParameter = parameter;

            var expectedParameter = new object();

            // Act
            var relayCommand     = RelayCommand.Create <object>(Execute);
            var canExecuteResult = relayCommand.CanExecute(expectedParameter);

            relayCommand.Execute(expectedParameter);

            // Assert
            Assert.That(canExecuteResult, Is.True);
            Assert.That(actualParameter, Is.EqualTo(expectedParameter));
        }
Пример #22
0
        public EntityPropertiesEditorViewModel(EntityModel entityModel, IComponentPropertiesEditorViewModelFactory componentPropertiesEditorViewModelFactory)
        {
            _entityModel = entityModel;
            _componentPropertiesEditorViewModelFactory = componentPropertiesEditorViewModelFactory;
            _name = CreateProperty(nameof(Name), _entityModel.Name);

            Components = new ObservableCollection <ComponentPropertiesEditorViewModel>(_entityModel.Components.Select(c =>
                                                                                                                      _componentPropertiesEditorViewModelFactory.Create(c)));

            AddTransform3DComponentCommand       = RelayCommand.Create(AddTransform3DComponent);
            AddEllipseRendererComponentCommand   = RelayCommand.Create(AddEllipseRendererComponent);
            AddRectangleRendererComponentCommand = RelayCommand.Create(AddRectangleRendererComponent);
            AddTextRendererComponentCommand      = RelayCommand.Create(AddTextRendererComponent);
            AddCircleColliderComponentCommand    = RelayCommand.Create(AddCircleColliderComponent);
            AddRectangleColliderComponentCommand = RelayCommand.Create(AddRectangleColliderComponent);

            _name.Subscribe(name => _entityModel.Name = name);

            _entityModel.ComponentAdded += EntityModelOnComponentAdded;
        }
Пример #23
0
 public MainViewModel(Models.Pool pool)
 {
     RefreshCommand = RelayCommand.Create(Refresh);
     _poolService   = new Services.PoolService();
     Pool           = pool;
 }
Пример #24
0
        /************************************************************************/

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the<see cref="WindowViewModel"/> class.
        /// </summary>
        protected WindowViewModel()
        {
            CloseWindowCommand             = RelayCommand.Create((p) => WindowOwner.Close());
            ToggleWindowStateCommand       = RelayCommand.Create(RunChangeWindowStateCommand);
            SetWindowStateMinimizedCommand = RelayCommand.Create((p) => WindowOwner.WindowState = WindowState.Minimized);
        }