Esempio n. 1
0
 public void ExecuteCommandTest_Fail()
 {
     using (var tc = new Toolchain(Guid.NewGuid()))
     {
         Assert.ThrowsException <Exception>(() =>
         {
             tc.Invoke(new[]
             {
                 new CommandLineInfo()
                 {
                     FileName  = "cmd.exe",
                     Arguments = "/c 1.cmd"
                 }
             });
         });
     }
 }
Esempio n. 2
0
        public ActionResult Invoke([FromBody] BaseRequest request)
        {
            try
            {
                switch (request)
                {
                case InvokeRequest invoke:
                    return(Ok(Toolchain.Invoke(invoke)));

                default:
                    return(BadRequest($"Unsupported request type: {request.GetType()}"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                return(BadRequest(ex.ToString()));
            }
        }
Esempio n. 3
0
        public void ExecuteCommandTest_Success()
        {
            using (var tc = new Toolchain(Guid.NewGuid()))
            {
                var fs = new FSSnapshot();
                fs.Files.Add(new FSTextFile()
                {
                    Name    = "1.cmd",
                    Content = "copy 1.txt 2.txt"
                });

                fs.Files.Add(new FSTextFile()
                {
                    Name    = "1.txt",
                    Content = "content"
                });

                tc.SaveSnapshot(fs);
                tc.SetupRules(new[] { new ModifiedFilesRule() });

                tc.Invoke(new[]
                {
                    new CommandLineInfo()
                    {
                        FileName  = "cmd.exe",
                        Arguments = "/c 1.cmd"
                    }
                });

                var result = tc.LoadSnapshot(new ExtensionClasses().Text("txt"));
                Assert.AreEqual(1, result.Files.Count);

                var file = (FSTextFile)result.Files[0];
                Assert.AreEqual("2.txt", file.Name);
                Assert.AreEqual("content", file.Content);
            }
        }