public void AppendText()
 {
     using (var tempFile = new TemporaryTextFile(BODY_TEXT)) {
         Assert.Equal(BODY_TEXT, tempFile.Body);
         tempFile.AppendText(ADDITIONAL_TEXT);
         Assert.Equal(BODY_TEXT + ADDITIONAL_TEXT, tempFile.Body);
     }
 }
 public void CarriageReturnLineFeed()
 {
     using (var tempFile = new TemporaryTextFile(BODY_TEXT)) {
         Assert.Equal(BODY_TEXT, tempFile.Body);
         tempFile.AppendText(ALT_ADDITIONAL_TEXT);
         Assert.Equal(BODY_TEXT + ALT_ADDITIONAL_TEXT, tempFile.Body);
     }
 }
        public void CustomExtension()
        {
            const string extension = "foo";

            using (var tempFile = new TemporaryTextFile(BODY_TEXT, extension)) {
                Assert.Equal($".{extension}", tempFile.FileInfo.Extension);
            }
        }
        public void CustomExtensionWithDot()
        {
            const string extension = ".foo";

            using (var tempFile = new TemporaryTextFile(BODY_TEXT, extension)) {
                Assert.Equal(extension, tempFile.FileInfo.Extension);
            }
        }
Example #5
0
 public void VerifyCompletionListForLoadMembers()
 {
     using var temporaryTextFile = new TemporaryTextFile(
               "c.csx",
               "int x = 2; class Complex { public int goo() { return 4; } }");
     temporaryTextFile.Create();
     VisualStudio.InteractiveWindow.SubmitText(string.Format("#load \"{0}\"", temporaryTextFile.FullName));
     VisualStudio.InteractiveWindow.InvokeCompletionList();
     VisualStudio.InteractiveWindow.Verify.CompletionItemsExist("x", "Complex");
     VisualStudio.SendKeys.Send(VirtualKey.Escape);
 }
        public void FileCreationDeletion()
        {
            string tempFilePath;

            using (var tempFile = new TemporaryTextFile(BODY_TEXT)) {
                tempFilePath = tempFile.FilePath;
                Assert.True(File.Exists(tempFilePath));
                Assert.Equal(BODY_TEXT, tempFile.Body);
            }
            Assert.False(File.Exists(tempFilePath));
        }
 public void VerifyHashLoadDirective()
 {
     using (var temporaryTextFile = new TemporaryTextFile(
                "directivesScenario6.csx",
                "System.Console.WriteLine(2);"))
     {
         temporaryTextFile.Create();
         VisualStudio.InteractiveWindow.SubmitText(string.Format("#load \"{0}\"", temporaryTextFile.FullName));
         VisualStudio.InteractiveWindow.WaitForLastReplOutput("2");
         VisualStudio.InteractiveWindow.SubmitText("#load text");
         VisualStudio.InteractiveWindow.WaitForLastReplOutput("CS7010: Quoted file name expected");
     }
 }
Example #8
0
 public void VerifyCompletionListForLoadMembers()
 {
     using (var temporaryTextFile = new TemporaryTextFile(
                "c.csx",
                "int x = 2; class Complex { public int foo() { return 4; } }"))
     {
         temporaryTextFile.Create();
         SubmitText(string.Format("#load \"{0}\"", temporaryTextFile.FullName));
         InvokeCompletionList();
         VerifyCompletionItemExists("x", "Complex");
         SendKeys(VirtualKey.Escape);
     }
 }
        private void Test(Action <string, TemporaryTextFile> setup, Action <GitRepo> tests)
        {
            const string textFileBody = "foo";

            using (var directory = new TemporaryDirectory()) {
                var directoryPath = directory.DirectoryPath;
                using (var file = new TemporaryTextFile(textFileBody, "txt", directoryPath)) {
                    setup(directoryPath, file);
                    var tools = new TestTools(Singletons.Tools, _output.WriteLine);
                    var repo  = new GitRepo(directory.DirectoryInfo, tools);
                    tests(repo);
                }
            }
        }
        public void VerifyLocalDeclarationInCsxFileWithTheSameNameHidesImportedMembersFromHashR()
        {
            VisualStudio.InteractiveWindow.SubmitText("#r \"System.Numerics\"");
            VisualStudio.InteractiveWindow.SubmitText("using System.Numerics;");
            using (var temporaryTextFile = new TemporaryTextFile(
                       "directivesScenario4.csx",
                       "class Complex { public int goo() { return 4; } }"))
            {
                temporaryTextFile.Create();
                VisualStudio.InteractiveWindow.SubmitText(string.Format("#load \"{0}\"", temporaryTextFile.FullName));
                VisualStudio.InteractiveWindow.SubmitText(@"var comp = new Complex();
comp.goo()");
                VisualStudio.InteractiveWindow.WaitForLastReplOutput("4");
            }
        }
        public void SpecificPath()
        {
            DirectoryInfo directoryInfo = null;

            try {
                var tempPath = Path.GetTempPath();
                directoryInfo = Directory.CreateDirectory(Path.Combine(tempPath, Guid.NewGuid().ToString()));
                var path = directoryInfo.FullName;

                using (var tempFile = new TemporaryTextFile(BODY_TEXT, "tmp", path)) {
                    Assert.NotNull(tempFile.FileInfo.Directory);
                    Assert.Equal(path, tempFile.FileInfo.Directory.FullName);
                }
            }
            finally {
                directoryInfo?.Delete();
            }
        }
Example #12
0
        public void ExecSubProcessCommand_Timeout()
        {
            //
            // Hack batch file command to wait 3 seconds.
            // There's no simple wait or sleep command for use in a Windows batch file but we can take advantage of the -n
            // switch to the ping command which will ping a specified number of times with one ping per second.
            //
            const string batFileContents = "ping 127.0.0.1 -n 3";

            using (var tempBatFile = new TemporaryTextFile(batFileContents, "bat")) {
                var filePath = tempBatFile.FilePath;
                var fileDir  = tempBatFile.FileInfo.DirectoryName;
                var timeout  = new TimeSpan(0, 0, 1); // 1 second timeout
                var tools    = Singletons.Tools;
                Assert.Throws <TimeoutException>(
                    () => tools.ExecSubProcessCommand("cmd.exe", $"/c {filePath}", fileDir, out var x, out var y, timeout)
                    );
            }
        }
Example #13
0
        public void ExecSubProcessCommand()
        {
            const string batFileContents =
                @"@echo off
echo This goes to stdout 2>&1
echo %cd% 2>&1
echo This goes to stderr 1>&2";

            using (var tempBatFile = new TemporaryTextFile(batFileContents, "bat")) {
                var filePath = tempBatFile.FilePath;
                var fileDir  = tempBatFile.FileInfo.DirectoryName;
                var timeout  = new TimeSpan(0, 0, 1); // 1 second timeout
                var tools    = Singletons.Tools;
                tools.ExecSubProcessCommand("cmd.exe", $"/c {filePath}", fileDir, out var stdout, out var stderr, timeout);
                var expectedStdout = $"This goes to stdout \r\n{fileDir} \r\n";
                var expectedStderr = $"This goes to stderr \r\n";
                Assert.Equal(expectedStdout, stdout);
                Assert.Equal(expectedStderr, stderr);
            }
        }
 public void DefaultExtension()
 {
     using (var tempFile = new TemporaryTextFile(BODY_TEXT)) {
         Assert.Equal(".tmp", tempFile.FileInfo.Extension);
     }
 }