Beispiel #1
0
        public void TestProcessCommand_OnProcessError()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);

            /* GIVEN */
            managerMock.
            Setup(manager => manager.Process(It.IsAny <IEnumerable <DirectoryPath> >()))?
            .Throws(new InvalidOperationException());

            var command = new ProcessCommand(managerMock.Object, outputMock.Object);
            var options = new ProcessOptions
            {
                IsVerbose  = false,
                ConfigPath = Assembly.GetExecutingAssembly().Location,
                InputFile  = "C:/"
            };

            /* WHEN */
            var returnCode = command.Execute(options);

            /* THEN */

            // We test if the command failed and returned code -1.
            Assert.AreEqual(failCode, returnCode);

            managerMock.Verify(manager => manager.Process(It.IsAny <IEnumerable <DirectoryPath> >()), Times.Once);
            outputMock.Verify(output => output.PrintError(It.IsAny <InvalidOperationException>()), Times.Once);
        }
        public void RunProcessCommandReturnsFailure()
        {
            var command = new ProcessCommand(null)
            {
                Process = "CMD.EXE", Arguments = "/c BADCOMMAND"
            };
            object actual = command.Execute();

            Assert.AreEqual(1, actual);
        }
        public void RunProcessCommandNoArgsTest()
        {
            var command = new ProcessCommand(null)
            {
                Process = "NOTEPAD.EXE"
            };
            object actual = command.Execute();

            Assert.AreEqual(0, actual);
        }
        public void RunProcessCommandEmptyArgsTest()
        {
            var command = new ProcessCommand(null)
            {
                Process = "NOTEPAD.EXE", Arguments = string.Empty
            };
            object actual = command.Execute();

            Assert.AreEqual(0, actual);
        }
Beispiel #5
0
            public static void Handle(byte[] packet, Socket clientSocket)
            {
                ushort packetLength = BitConverter.ToUInt16(packet, 0);

                byte[] data = new byte[packetLength];
                Array.Copy(packet, 2, data, 0, packetLength);
                string commandName = Encoding.Default.GetString(data);

                byte[] res = ProcessCommand.Execute(commandName); // a reason why ProcessCommand is an inner class
                clientSocket.Send(res);
            }
        public void RunProcessCommandTest()
        {
            string path       = GetTempPath("FileCopy", true);
            string sourceFile = CreateTempFile(path, "SourceFile.tst");
            string targetFile = CreateTempFile(path, "TargetFile.tst");

            var command = new ProcessCommand(null)
            {
                Process = "CMD.EXE", Arguments = string.Format(@"/c COPY {0} {1}", sourceFile, targetFile)
            };
            object actual = command.Execute();

            Assert.AreEqual(0, actual);
        }
Beispiel #7
0
        public void TestProcessCommand_NullOptions()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);

            /* GIVEN */
            var command = new ProcessCommand(managerMock.Object, outputMock.Object);

            /* WHEN */
            var returnCode = command.Execute(null);

            /* THEN */

            // We test if the command was unsuccessful and returned code -1.
            Assert.AreEqual(failCode, returnCode);

            managerMock.Verify(manager => manager.Process(It.IsAny <IEnumerable <DirectoryPath> >()), Times.Never);
        }
Beispiel #8
0
        public void Execute()
        {
            var processCommand = new ProcessCommand();

            var version     = packageSO.package.version;
            var packagePath = AssetDatabase.GetAssetPath(packageSO).Replace("/package.json", string.Empty);

            int length = commands.Length;

            for (int i = 0; i < length; i++)
            {
                var gitCommand = commands[i];

                EditorUtility.DisplayProgressBar(/*this.name + */ "UPM Update  " + gitCommand.Name, gitCommand.Command, (float)i / commands.Length);

                if (gitCommand.State == false)
                {
                    continue;
                }

                string cmd;
                if (packageSO != null)
                {
                    cmd = gitCommand.Command.Replace("#version#", version).Replace("#PackagePath#", packagePath);
                }
                else
                {
                    cmd = gitCommand.Command;
                }

                processCommand.Cmd = cmd;
                processCommand.Execute();

                Debug.Log(processCommand.Log);
            }

            EditorUtility.ClearProgressBar();
        }
Beispiel #9
0
        public void TestProcessCommand_IsVerbosePropagation()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);

            /* GIVEN */
            outputMock.SetupSet(output => output.IsVerbose = true);

            var command = new ProcessCommand(managerMock.Object, outputMock.Object);
            var options = new ProcessOptions
            {
                IsVerbose  = true,
                ConfigPath = "C:/",
                InputFile  = "C:/"
            };

            /* WHEN */
            command.Execute(options);

            /* THEN */
            outputMock.VerifySet(output => output.IsVerbose = true);
        }
Beispiel #10
0
        public void TestProcessCommand_Successful()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);

            /* GIVEN */
            var command = new ProcessCommand(managerMock.Object, outputMock.Object);
            var options = new ProcessOptions
            {
                IsVerbose  = false,
                ConfigPath = Assembly.GetExecutingAssembly().Location,
                InputFile  = "C:/"
            };

            /* WHEN */
            var returnCode = command.Execute(options);

            /* THEN */

            // We test if the command was successful and returned code 0.
            Assert.AreEqual(successCode, returnCode);
            managerMock.Verify(manager => manager.Process(It.IsAny <IEnumerable <DirectoryPath> >()), Times.Once);
        }