public void TestUndoRedoCommand()
        {
            // Arrange
            var project = new Project();
            var context = new BlockCommandContext(project);
            ProjectBlockCollection blocks = project.Blocks;
            Block    block        = blocks[0];
            int      blockVersion = block.Version;
            BlockKey blockKey     = block.BlockKey;

            var command = new SetTextCommand(blockKey, "Testing 123");

            project.Commands.Do(command, context);

            project.Commands.Undo(context);

            // Act
            project.Commands.Redo(context);

            // Assert
            Assert.AreEqual(1, blocks.Count);
            Assert.AreEqual(
                new BlockPosition(blocks[0], "Testing 123".Length),
                project.Commands.LastPosition);

            const int index = 0;

            Assert.AreEqual("Testing 123", blocks[index].Text);
            Assert.AreEqual(blockVersion + 3, blocks[index].Version);
        }
Beispiel #2
0
        public static void Behavioral_CommandDemo2()
        {
            //var videoEditor = new VideoEditor();
            //videoEditor.SetText("demo2 video text");
            //videoEditor.SetContrast(0.7f);
            //var result = videoEditor.ToString();
            //Console.WriteLine(result);

            var videoEditor = new VideoEditor();
            var history     = new Command.Demo2.History();

            var setTextCommand = new SetTextCommand("Video Title", videoEditor, history);

            setTextCommand.Execute();
            Console.WriteLine("TEXT: " + videoEditor);

            var setContrast = new SetContrastCommand(1, videoEditor, history);

            setContrast.Execute();
            Console.WriteLine("CONTRAST: " + videoEditor);

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var addCustomerCommand = new AddCustomerCommand(new CustomerService());
            var button             = new Button(addCustomerCommand);

            button.Click();

            // Because we are representing each individual task using a command object,
            // we can combine these commands inside a composite object and re-execute them later on.
            var compositeCommand = new CompositeCommand();

            compositeCommand.Add(new ResizeCommand());
            compositeCommand.Add(new BlackAndWhiteCommand());

            compositeCommand.Execute();

            var history      = new Solution.UndoableCommands.History();
            var htmlDocument = new HtmlDocument();

            htmlDocument.Content = "Hello World!";

            var boldCommand = new BoldCommand(htmlDocument, history);

            boldCommand.Execute();

            Console.WriteLine(htmlDocument.Content);

            //boldCommand.Unexecute();
            var undoCommand = new Solution.UndoableCommands.UndoCommand(history);

            undoCommand.Execute();

            Console.WriteLine(htmlDocument.Content);

            Console.WriteLine("--- Exercise ---");

            var exeHistory  = new Exercise.End.History();
            var videoEditor = new VideoEditor();

            var setTextCommand = new SetTextCommand("Hello World!", videoEditor, exeHistory);

            setTextCommand.Execute();

            Console.WriteLine(videoEditor.Text);

            //setTextCommand.Undo();
            var exeUndoCommand = new Exercise.End.UndoCommand(exeHistory);

            exeUndoCommand.Execute();

            Console.WriteLine(videoEditor.Text);

            Console.ReadLine();
        }
Beispiel #4
0
        private bool SetTextOnAutomationIdentification(AutomationIdentifier controlIdentifier, string text, int ordinal, AutomationIdentifier parentIdentifier)
        {
            var command = new SetTextCommand
            {
                AutomationIdentifier = controlIdentifier,
                Text             = text,
                Ordinal          = ordinal,
                ParentIdentifier = parentIdentifier
            };

            var result        = SyncExecuteCommand(command);
            var successResult = result as SuccessResult;

            return(successResult != null);
        }
Beispiel #5
0
    public void ClientSocketHandlerDidReadMessage(AltClientSocketHandler handler, string message)
    {
        string[]          separator = new string[] { requestSeparatorString };
        string[]          pieces    = message.Split(separator, System.StringSplitOptions.None);
        AltUnityComponent altComponent;
        AltUnityObject    altUnityObject;
        string            methodParameters;

        UnityEngine.Vector2 size;
        PLayerPrefKeyType   option;
        Command             command = null;

        try
        {
            switch (pieces[0])
            {
            case "findAllObjects":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2];
                command          = new FindAllObjectsCommand(methodParameters);
                break;

            case "findObjectByName":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectByNameCommand(methodParameters);
                break;

            case "findObjectWhereNameContains":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectWhereNameContainsCommand(methodParameters);
                break;

            case "tapObject":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new TapCommand(altUnityObject);
                break;

            case "findObjectsByName":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectsByNameCommand(methodParameters);
                break;

            case "findObjectsWhereNameContains":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectsWhereNameContainsCommand(methodParameters);
                break;

            case "getCurrentScene":
                command = new GetCurrentSceneCommand();
                break;

            case "findObjectByComponent":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3] + requestSeparatorString + pieces[4];
                command          = new FindObjectByComponentCommand(methodParameters);
                break;

            case "findObjectsByComponent":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3] + requestSeparatorString + pieces[4];
                command          = new FindObjectsByComponentCommand(methodParameters);
                break;

            case "getObjectComponentProperty":
                command = new GetComponentPropertyCommand(pieces[1], pieces[2]);
                break;

            case "setObjectComponentProperty":
                command = new SetObjectComponentPropertyCommand(pieces[1], pieces[2], pieces[3]);
                break;

            case "callComponentMethodForObject":
                command = new CallComponentMethodForObjectCommand(pieces[1], pieces[2]);
                break;

            case "closeConnection":
                UnityEngine.Debug.Log("Socket connection closed!");
                _socketServer.StartListeningForConnections();
                break;

            case "clickEvent":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new ClickEventCommand(altUnityObject);
                break;

            case "tapScreen":
                command = new ClickOnScreenAtXyCommand(pieces[1], pieces[2]);
                break;

            case "dragObject":
                UnityEngine.Vector2 positionVector2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[2]);
                command        = new DragObjectCommand(positionVector2, altUnityObject);
                break;

            case "dropObject":
                UnityEngine.Vector2 positionDropVector2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[2]);
                command        = new DropObjectCommand(positionDropVector2, altUnityObject);
                break;

            case "pointerUpFromObject":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new PointerUpFromObjectCommand(altUnityObject);
                break;

            case "pointerDownFromObject":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new PointerDownFromObjectCommand(altUnityObject);
                break;

            case "pointerEnterObject":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new PointerEnterObjectCommand(altUnityObject);
                break;

            case "pointerExitObject":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new PointerExitObjectCommand(altUnityObject);
                break;

            case "tilt":
                UnityEngine.Vector3 vector3 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector3>(pieces[1]);
                command = new TiltCommand(vector3);
                break;

            case "movingTouch":
                UnityEngine.Vector2 start2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                UnityEngine.Vector2 end2   = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[2]);
                command = new SetMovingTouchCommand(start2, end2, pieces[3]);
                break;

            case "loadScene":
                command = new Assets.AltUnityTester.AltUnityServer.Commands.LoadSceneCommand(pieces[1]);
                break;

            case "setTimeScale":
                float timeScale = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[1]);
                command = new SetTimeScaleCommand(timeScale);
                break;

            case "getTimeScale":
                command = new GetTimeScaleCommand();
                break;

            case "deletePlayerPref":
                command = new DeletePlayerPrefCommand();
                break;

            case "deleteKeyPlayerPref":
                command = new DeleteKeyPlayerPrefCommand(pieces[1]);
                break;

            case "setKeyPlayerPref":
                option  = (PLayerPrefKeyType)System.Enum.Parse(typeof(PLayerPrefKeyType), pieces[3]);
                command = new SetKeyPlayerPrefCommand(option, pieces[1], pieces[2]);
                break;

            case "getKeyPlayerPref":
                option  = (PLayerPrefKeyType)System.Enum.Parse(typeof(PLayerPrefKeyType), pieces[2]);
                command = new GetKeyPlayerPrefCommand(option, pieces[1]);
                break;

            case "actionFinished":
                command = new ActionFinishedCommand();
                break;

            case "getAllComponents":
                command = new GetAllComponentsCommand(pieces[1]);
                break;

            case "getAllFields":
                altComponent = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityComponent>(pieces[2]);
                command      = new GetAllFieldsCommand(pieces[1], altComponent);
                break;

            case "getAllMethods":
                altComponent = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityComponent>(pieces[1]);
                command      = new GetAllMethodsCommand(altComponent);
                break;

            case "getAllScenes":
                command = new GetAllScenesCommand();
                break;

            case "getAllCameras":
                command = new GetAllCamerasCommand();
                break;

            case "getScreenshot":
                size    = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                command = new GetScreenshotCommand(size, handler);
                break;

            case "hightlightObjectScreenshot":
                var id = System.Convert.ToInt32(pieces[1]);
                size    = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[3]);
                command = new HighlightSelectedObjectCommand(id, pieces[2], size, handler);
                break;

            case "hightlightObjectFromCoordinatesScreenshot":
                var coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                size    = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[3]);
                command = new HightlightObjectFromCoordinatesCommand(coordinates, pieces[2], size, handler);
                break;

            case "pressKeyboardKey":
                var piece = pieces[1];
                UnityEngine.KeyCode keycode = (UnityEngine.KeyCode)System.Enum.Parse(typeof(UnityEngine.KeyCode), piece);
                float power    = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]);
                float duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[3]);
                command = new HoldButtonCommand(keycode, power, duration);
                break;

            case "moveMouse":
                UnityEngine.Vector2 location = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]);
                duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]);
                command  = new MoveMouseCommand(location, duration);
                break;

            case "scrollMouse":
                var scrollValue = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[1]);
                duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]);
                command  = new ScrollMouseCommand(scrollValue, duration);
                break;

            case "findObject":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectCommand(methodParameters);
                break;

            case "findObjects":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindObjectsCommand(methodParameters);
                break;

            case "findActiveObjectByName":
                methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3];
                command          = new FindActiveObjectsByNameCommand(methodParameters);
                break;

            case "enableLogging":
                var enableLogging = bool.Parse(pieces[1]);
                command = new EnableLoggingCommand(enableLogging);
                break;

            case "getText":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new GetTextCommand(altUnityObject);
                break;

            case "setText":
                altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]);
                command        = new SetTextCommand(altUnityObject, pieces[2]);
                break;

            case "getPNGScreenshot":
                command = new GetScreenshotPNGCommand(handler);
                break;


            default:
                command = new UnknowStringCommand();
                break;
            }
        }
        catch (Newtonsoft.Json.JsonException exception)
        {
            UnityEngine.Debug.Log(exception);
            handler.SendResponse(errorCouldNotParseJsonString);
        }
        if (command != null)
        {
            command.SendResponse(handler);
        }
    }