public async Task ShouldRenameFilesAndPreserveDirectoryStructureIfTargetFilesExist() { TestFileContext.CreateFile("source/test.txt", "testing"); TestFileContext.CreateFile("source/sub/test.txt", "testing"); TestFileContext.CreateFile("target/sub/test.txt", "existing"); var results = await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("source"), Pattern = "**/*.txt", TargetDirectory = TestFileContext.GetAbsolutePath("target") }, new CopyOptions { PreserveDirectoryStructure = true, CreateTargetDirectories = true, IfTargetFileExists = FileExistsAction.Rename }, CancellationToken.None); Assert.Equal(2, results.Count); Assert.Equal(results.Select(r => r.Path), new[] { TestFileContext.GetAbsolutePath("target/test.txt"), TestFileContext.GetAbsolutePath("target/sub/test(1).txt") }); Assert.True(TestFileContext.FileExists("target/sub/test(1).txt"), "Output file should have been written"); }
public void ReadSample1File() { using var stream = new System.IO.FileStream("test.xlsx", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); var xl = new TestFileContext(stream); ReadSample1File_test(xl); }
public async Task ShouldOverwriteExistingFilesInSubDirectories() { var expectedFileContents = "testing " + DateTime.UtcNow.ToString("o"); TestFileContext.CreateFile("source/test.txt", "testing"); TestFileContext.CreateFile("source/sub/test.txt", expectedFileContents); TestFileContext.CreateFile("target/sub/test.txt", "existing"); var results = await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("source"), Pattern = "**/*.txt", TargetDirectory = TestFileContext.GetAbsolutePath("target") }, new CopyOptions { PreserveDirectoryStructure = true, CreateTargetDirectories = true, IfTargetFileExists = FileExistsAction.Overwrite }, CancellationToken.None); Assert.Equal(2, results.Count); Assert.Equal(results.Select(r => r.Path), new[] { TestFileContext.GetAbsolutePath("target/test.txt"), TestFileContext.GetAbsolutePath("target/sub/test.txt") }); Assert.True(TestFileContext.FileExists("target/sub/test.txt"), "Output file should have been written"); var resultFileContents = System.IO.File.ReadAllText(TestFileContext.GetAbsolutePath("target/sub/test.txt")); Assert.Equal(expectedFileContents, resultFileContents); }
public async Task ShouldCopyFilesFromSubDirectories() { TestFileContext.CreateFile("dir/sub/test1.txt", "testing"); TestFileContext.CreateFile("dir/sub/test2.txt", "testing"); TestFileContext.CreateFile("dir/sub/other1.xml", "testing"); TestFileContext.CreateFile("dir/sub/nestedSub/test3.txt", "testing"); TestFileContext.CreateFile("dir/sub/nestedSub/other2.xml", "testing"); var results = await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("dir"), Pattern = "**/*.txt", TargetDirectory = TestFileContext.GetAbsolutePath("out"), }, new CopyOptions { CreateTargetDirectories = true }, CancellationToken.None); Assert.Equal(3, results.Count); Assert.Equal(results.Select(r => Path.GetFileName(r.Path)), new[] { "test1.txt", "test2.txt", "test3.txt" }); Assert.True(TestFileContext.FileExists("out/test1.txt"), "Output file should have been written"); Assert.True(TestFileContext.FileExists("out/test2.txt"), "Output file should have been written"); Assert.True(TestFileContext.FileExists("out/test3.txt"), "Output file should have been written"); }
private void FireTestFinished(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput, int testIndex) { var jsTestCase = jsRunnerOutput as JsTestCase; jsTestCase.TestCase.InputTestFile = testFileContext.ReferencedFile.Path; AddLineNumber(testFileContext.ReferencedFile, testIndex, jsTestCase); callback.TestFinished(jsTestCase.TestCase); testFileContext.TestFileSummary.AddTestCase(jsTestCase.TestCase); }
private void FireErrorOutput(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput) { var error = jsRunnerOutput as JsError; error.Error.InputTestFile = testFileContext.ReferencedFile.Path; callback.FileError(error.Error); testFileContext.TestFileSummary.Errors.Add(error.Error); ChutzpahTracer.TraceError("Eror recieved from Phantom {0}", error.Error.Message); }
private static void PlayDeferredEvents(TestFileContext currentTestFileContext, List <Action <TestFileContext> > deferredEvents) { // Since we found a unique match we need to reply and log the events that came before this // using this file context foreach (var deferredEvent in deferredEvents) { deferredEvent(currentTestFileContext); } deferredEvents.Clear(); }
public void ReadAndWrite() { var xl = new TestFileContext("test.xlsx"); xl.SerializeToFile("test-out.xlsx"); xl.SerializeToStream(); xl.SerializeToExcelPackage(); var xl2 = new TestFileContext("test-out.xlsx"); Assert.AreEqual(xl.GetSheet <TestFileContext.Sheet1>().Count, xl2.GetSheet <TestFileContext.Sheet1>().Count); Assert.AreEqual(xl.GetSheet <Class1>().Count, xl2.GetSheet <Class1>().Count); }
public void FindFiles() { TestFileContext.CreateFiles("folder/foo/test.txt", "folder/foo/sub/test3.txt", "folder/foo/sub/test.txt", "folder/bar/sub/example2.json"); var results = File.Find(new FindInput() { Directory = TestFileContext.RootPath, Pattern = "**/*.xml" }, new FindOption()); Assert.Equal(2, results.Count); Assert.True(results.All(x => x.Extension.Equals(".xml"))); }
public async Task ReadFileContent() { var fileContent = "Well this is content with some extra nice ümlauts: ÄÖåå 你好!"; TestFileContext.CreateFile("Folder/test.txt", fileContent); var result = await File.Read(new ReadInput() { Path = Path.Combine(TestFileContext.RootPath, "folder/test.txt") }, new ReadOption() { }); Assert.Equal(fileContent, result.Content); }
private void FireLogOutput(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput) { var log = jsRunnerOutput as JsLog; // This is an internal log message if (log.Log.Message.StartsWith(internalLogPrefix)) { ChutzpahTracer.TraceInformation("Phantom Log - {0}", log.Log.Message.Substring(internalLogPrefix.Length).Trim()); return; } log.Log.InputTestFile = testFileContext.ReferencedFile.Path; callback.FileLog(log.Log); testFileContext.TestFileSummary.Logs.Add(log.Log); }
public async Task ShouldNotCopyFilesIfNoMatch() { TestFileContext.CreateFile("dir/sub/test.txt", "testing"); var results = await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("dir"), Pattern = "**/*.xml", TargetDirectory = TestFileContext.GetAbsolutePath("out") }, new CopyOptions { CreateTargetDirectories = true }, CancellationToken.None); Assert.Empty(results); }
public async Task FileMoveOverWrite() { const string contentForFileToBeOverwritten = "firstFile"; TestFileContext.CreateFile("folder/test.xml", contentForFileToBeOverwritten); var createdFile = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "folder/test.xml")); Assert.Equal(contentForFileToBeOverwritten, createdFile); var results = await File.Move( new MoveInput() { Directory = TestFileContext.RootPath, Pattern = "**/sub/*.xml", TargetDirectory = Path.Combine(TestFileContext.RootPath, "folder") }, new MoveOptions() { IfTargetFileExists = FileExistsAction.Overwrite }, CancellationToken.None); var overWrittenFIle = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "folder/test.xml")); Assert.NotEqual(contentForFileToBeOverwritten, overWrittenFIle); Assert.Equal(2, results.Count); var destinationFilesLength = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder")).Length; Assert.Equal(2, destinationFilesLength); var secondMoveShouldBeEmpty = await File.Move( new MoveInput() { Directory = TestFileContext.RootPath, Pattern = "**/sub/*.xml", TargetDirectory = Path.Combine(TestFileContext.RootPath, "folder") }, new MoveOptions() { IfTargetFileExists = FileExistsAction.Overwrite }, CancellationToken.None); Assert.Empty(secondMoveShouldBeEmpty); }
public async Task FileMoveCopy() { const string contentForOriginalFile = "firstFile"; TestFileContext.CreateFile("folder/test.xml", contentForOriginalFile); var results = await File.Move( new MoveInput() { Directory = TestFileContext.RootPath, Pattern = "**/sub/*.xml", TargetDirectory = Path.Combine(TestFileContext.RootPath, "folder") }, new MoveOptions() { IfTargetFileExists = FileExistsAction.Rename }, CancellationToken.None); Assert.Equal(2, results.Count); var originalFile = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "folder\\test.xml")); var copiedFile = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "folder\\test(1).xml")); Assert.Equal(contentForOriginalFile, originalFile); Assert.StartsWith("Automatically generated for testing on", copiedFile); var destinationFilesLength = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder")).Length; Assert.Equal(3, destinationFilesLength); var secondMoveShouldBeEmpty = await File.Move( new MoveInput() { Directory = TestFileContext.RootPath, Pattern = "**/sub/*.xml", TargetDirectory = Path.Combine(TestFileContext.RootPath, "folder") }, new MoveOptions() { IfTargetFileExists = FileExistsAction.Rename }, CancellationToken.None); Assert.Empty(secondMoveShouldBeEmpty); }
public async Task ShouldThrowErrorIfTargetDirectoryDoesNotExist() { TestFileContext.CreateFile("dir/sub/test.txt", "testing"); var error = await Assert.ThrowsAsync <DirectoryNotFoundException>(async() => await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("dir/sub"), Pattern = "test.txt", TargetDirectory = TestFileContext.GetAbsolutePath("out") }, new CopyOptions { CreateTargetDirectories = false }, CancellationToken.None)); Assert.Contains(TestFileContext.GetAbsolutePath("out"), error.Message); }
public async Task WriteFileOverWrite() { TestFileContext.CreateFile("test.txt", "old content"); var result = await File.Write( new WriteInput() { Content = "new content", Path = Path.Combine(TestFileContext.RootPath, "test.txt") }, new WriteOption() { WriteBehaviour = WriteBehaviour.Overwrite }); var fileContent = System.IO.File.ReadAllText(result.Path); Assert.Equal("new content", fileContent); }
public async Task WriteFileThrow() { TestFileContext.CreateFile("test.txt", "old content"); var ex = await Assert.ThrowsAsync <IOException>(async() => await File.Write( new WriteInput() { Content = "new content", Path = Path.Combine(TestFileContext.RootPath, "test.txt") }, new WriteOption() { WriteBehaviour = WriteBehaviour.Throw })); var fileContent = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "test.txt")); Assert.Equal("old content", fileContent); Assert.Equal($"File already exists: {Path.Combine(TestFileContext.RootPath, "test.txt")}", ex.Message); }
public async Task WriteFileBytesAppend() { var imageBytes = System.IO.File.ReadAllBytes(BinaryTestFilePath); TestFileContext.CreateBinaryFile("test.png", new byte[] { 137, 80, 78, 71, 13, 10, 26, 10 }); // empty png var result = await File.WriteBytes( new WriteBytesInput() { ContentBytes = imageBytes, Path = Path.Combine(TestFileContext.RootPath, "test.png") }, new WriteBytesOption() { WriteBehaviour = WriteBehaviour.Append }); var fileContentBytes = System.IO.File.ReadAllBytes(result.Path); Assert.Equal(8 + imageBytes.Length, fileContentBytes.Length); }
public async Task ShouldCopySingleFile() { TestFileContext.CreateFile("dir/sub/test.txt", "testing"); var results = await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("dir/sub"), Pattern = "test.txt", TargetDirectory = TestFileContext.GetAbsolutePath("out") }, new CopyOptions { CreateTargetDirectories = true }, CancellationToken.None); Assert.Single(results); var result = results[0]; Assert.Equal(TestFileContext.GetAbsolutePath("out/test.txt"), result.Path); Assert.Equal(TestFileContext.GetAbsolutePath("dir/sub/test.txt"), result.SourcePath); Assert.True(TestFileContext.FileExists("out/test.txt"), "Output file should have been written"); }
public async Task FileMoveThrowShouldThrowIfFIleExistsAtDestination() { const string contentForOriginalFile = "firstFile"; TestFileContext.CreateFile("folder/test.xml", contentForOriginalFile); var ex = await Assert.ThrowsAsync <IOException>(async() => await File.Move( new MoveInput() { Directory = TestFileContext.RootPath, Pattern = "**/sub/*.xml", TargetDirectory = Path.Combine(TestFileContext.RootPath, "folder") }, new MoveOptions() { IfTargetFileExists = FileExistsAction.Throw }, CancellationToken.None)); Assert.Equal($"File '{Path.Combine(TestFileContext.RootPath, "folder\\test.xml")}' already exists. No files moved.", ex.Message); var originalFile = System.IO.File.ReadAllText(Path.Combine(TestFileContext.RootPath, "folder\\test.xml")); Assert.Equal(contentForOriginalFile, originalFile); var destinationFilesLength = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder")); Assert.Single(destinationFilesLength); var sourceFolder1 = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder/foo/sub/")); Assert.Single(sourceFolder1); var sourceFolder2 = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder/bar/sub/")); Assert.Single(sourceFolder2); }
public async Task ShouldThrowAndRollbackIfTargetFilesExist() { TestFileContext.CreateFile("source/test.txt", "testing"); TestFileContext.CreateFile("source/sub/test.txt", "testing"); TestFileContext.CreateFile("target/sub/test.txt", "existing"); await Assert.ThrowsAsync <IOException>(async() => await File.Copy( new CopyInput { Directory = TestFileContext.GetAbsolutePath("source"), Pattern = "**/*.txt", TargetDirectory = TestFileContext.GetAbsolutePath("target") }, new CopyOptions { PreserveDirectoryStructure = true, CreateTargetDirectories = true, IfTargetFileExists = FileExistsAction.Throw }, CancellationToken.None)); Assert.False(TestFileContext.FileExists("target/test.txt"), "Output file should have been rolled back"); Assert.False(TestFileContext.FileExists("target/test(2).txt"), "Output file should have been rolled back"); }
private void FireCoverageObject(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput) { var jsCov = jsRunnerOutput as JsCoverage; testFileContext.TestFileSummary.CoverageObject = coverageEngine.DeserializeCoverageObject(jsCov.Object, testFileContext.TestContext); }
public void ReadSample1File_test(TestFileContext xl) { var sheet1 = xl.GetSheet <TestFileContext.Sheet1>(); var sheet2 = xl.GetSheet <Class1>(); Assert.AreEqual(2, sheet1.Count); var s1row = sheet1[0]; Assert.AreEqual(DateTime.Parse("7/1/2020"), s1row.Date); Assert.AreEqual(52, s1row.Quantity); Assert.AreEqual("Widgets", s1row.Description); Assert.AreEqual(45.99m, s1row.Amount); Assert.AreEqual(2391.48m, s1row.Total); Assert.AreEqual(null, s1row.Notes); s1row = sheet1[1]; Assert.AreEqual(DateTime.Parse("7/23/2020"), s1row.Date); Assert.AreEqual(22, s1row.Quantity); Assert.AreEqual("Bolts", s1row.Description); Assert.AreEqual(2.54m, s1row.Amount); Assert.AreEqual(55.88m, s1row.Total); Assert.AreEqual("Each bolt is a set of two", s1row.Notes); Assert.AreEqual(9, sheet2.Count); var s2row = sheet2[0]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1f, s2row.FloatColumn); Assert.AreEqual(1.0, s2row.DoubleColumn); Assert.AreEqual("test", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/2/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/test"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("f1dc7e7d-d63e-4279-8dfd-cecb6e26cda8"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[1]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(false, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/1/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[2]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/3/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[3]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/1/2020 2:30 PM"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.Parse("2:34:56"), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(null, s2row.NullableIntColumn); Assert.AreEqual(false, sheet2[4].BooleanColumn); Assert.AreEqual(true, sheet2[5].BooleanColumn); Assert.AreEqual(false, sheet2[6].BooleanColumn); Assert.AreEqual(true, sheet2[7].BooleanColumn); Assert.AreEqual(false, sheet2[8].BooleanColumn); }
public void ReadSample1File_2() { var xl = new TestFileContext("test.xlsx"); ReadSample1File_test(xl); }
public UnitTest() { TestFileContext.CreateFiles( "folder/foo/sub/test.xml", "folder/bar/sub/example.xml"); }
private IList <TestFileSummary> ReadFromStream(StreamReader stream, TestContext testContext, TestOptions testOptions, ITestMethodRunnerCallback callback, bool debugEnabled) { var codeCoverageEnabled = (!testContext.TestFileSettings.EnableCodeCoverage.HasValue && testOptions.CoverageOptions.Enabled) || (testContext.TestFileSettings.EnableCodeCoverage.HasValue && testContext.TestFileSettings.EnableCodeCoverage.Value); var testFileContexts = testContext.ReferencedFiles .Where(x => x.IsFileUnderTest) .Select(x => new TestFileContext(x, testContext, codeCoverageEnabled)) .ToList(); var testIndex = 0; string line; TestFileContext currentTestFileContext = null; if (testFileContexts.Count == 1) { currentTestFileContext = testFileContexts.First(); } var deferredEvents = new List <Action <TestFileContext> >(); while ((line = stream.ReadLine()) != null) { if (debugEnabled) { Console.WriteLine(line); } var match = prefixRegex.Match(line); if (!match.Success) { continue; } var type = match.Groups["type"].Value; var json = match.Groups["json"].Value; // Only update last event timestamp if it is an important event. // Log and error could happen even though no test progress is made if (!type.Equals("Log") && !type.Equals("Error")) { lastTestEvent = DateTime.Now; } try { switch (type) { case "FileStart": FireFileStarted(callback, testContext); break; case "CoverageObject": var jsCov = jsonSerializer.Deserialize <JsCoverage>(json); if (currentTestFileContext == null) { deferredEvents.Add((fileContext) => FireCoverageObject(callback, fileContext, jsCov)); } else { FireCoverageObject(callback, currentTestFileContext, jsCov); } break; case "FileDone": var jsFileDone = jsonSerializer.Deserialize <JsFileDone>(json); FireFileFinished(callback, testContext.InputTestFilesString, testFileContexts, jsFileDone); break; case "TestStart": var jsTestCaseStart = jsonSerializer.Deserialize <JsTestCase>(json); TestFileContext newContext = null; var testName = jsTestCaseStart.TestCase.TestName.Trim(); var moduleName = (jsTestCaseStart.TestCase.ModuleName ?? "").Trim(); var fileContexts = GetFileMatches(testName, testFileContexts); if (fileContexts.Count == 0 && currentTestFileContext == null) { // If there are no matches and not file context has been used yet // then just choose the first context newContext = testFileContexts[0]; } else if (fileContexts.Count == 0) { // If there is already a current context and no matches we just keep using that context // unless this test name has been used already in the current context. In that case // move to the next one that hasn't seen this file yet var testAlreadySeenInCurrentContext = currentTestFileContext.HasTestBeenSeen(moduleName, testName); if (testAlreadySeenInCurrentContext) { newContext = testFileContexts.FirstOrDefault(x => !x.HasTestBeenSeen(moduleName, testName)) ?? currentTestFileContext; } } else if (fileContexts.Count > 1) { // If we found the test has more than one file match // try to choose the best match, otherwise just choose the first one // If we have no file context yet take the first one if (currentTestFileContext == null) { newContext = fileContexts.First(); } else { // In this case we have an existing file context so we need to // 1. Check to see if this test has been seen already on that context // if so we need to try the next file context that matches it // 2. If it is not seen yet in the current context and the current context // is one of the matches then keep using it var testAlreadySeenInCurrentContext = currentTestFileContext.HasTestBeenSeen(moduleName, testName); var currentContextInFileMatches = fileContexts.Any(x => x == currentTestFileContext); if (!testAlreadySeenInCurrentContext && currentContextInFileMatches) { // Keep the current context newContext = currentTestFileContext; } else { // Either take first not used context OR the first one newContext = fileContexts.Where(x => !x.IsUsed).FirstOrDefault() ?? fileContexts.First(); } } } else if (fileContexts.Count == 1) { // We found a unique match newContext = fileContexts[0]; } if (newContext != null && newContext != currentTestFileContext) { currentTestFileContext = newContext; testIndex = 0; } currentTestFileContext.IsUsed = true; currentTestFileContext.MarkTestSeen(moduleName, testName); PlayDeferredEvents(currentTestFileContext, deferredEvents); jsTestCaseStart.TestCase.InputTestFile = currentTestFileContext.ReferencedFile.Path; callback.TestStarted(jsTestCaseStart.TestCase); break; case "TestDone": var jsTestCaseDone = jsonSerializer.Deserialize <JsTestCase>(json); var currentTestIndex = testIndex; FireTestFinished(callback, currentTestFileContext, jsTestCaseDone, currentTestIndex); testIndex++; break; case "Log": var log = jsonSerializer.Deserialize <JsLog>(json); if (currentTestFileContext != null) { FireLogOutput(callback, currentTestFileContext, log); } else { deferredEvents.Add((fileContext) => FireLogOutput(callback, fileContext, log)); } break; case "Error": var error = jsonSerializer.Deserialize <JsError>(json); if (currentTestFileContext != null) { FireErrorOutput(callback, currentTestFileContext, error); } else { deferredEvents.Add((fileContext) => FireErrorOutput(callback, fileContext, error)); } break; } } catch (SerializationException e) { // Ignore malformed json and move on ChutzpahTracer.TraceError(e, "Recieved malformed json from Phantom in this line: '{0}'", line); } } return(testFileContexts.Select(x => x.TestFileSummary).ToList()); }
public void ReadSample1File_3() { var xl = new TestFileContext(new ExcelPackage(new FileInfo("test.xlsx"))); ReadSample1File_test(xl); }
private static void PlayDeferredEvents(TestFileContext currentTestFileContext, List<Action<TestFileContext>> deferredEvents) { // Since we found a unique match we need to reply and log the events that came before this // using this file context foreach (var deferredEvent in deferredEvents) { deferredEvent(currentTestFileContext); } deferredEvents.Clear(); }
public void RenameFile() { var resultsOverWrite = File.Rename( new RenameInput() { Path = Path.Combine(TestFileContext.RootPath, "folder/foo/sub/test.xml"), NewFileName = "newTest.xml" }, new RenameOption() { RenameBehaviour = FileExistsAction.Overwrite }); Assert.Equal(Path.Combine(TestFileContext.RootPath, "folder\\foo\\sub\\newTest.xml"), resultsOverWrite.Path); var resultsCopy = File.Rename( new RenameInput() { Path = Path.Combine(TestFileContext.RootPath, "folder/foo/sub/newTest.xml"), NewFileName = "newTest.xml" }, new RenameOption() { RenameBehaviour = FileExistsAction.Rename }); Assert.Equal(Path.Combine(TestFileContext.RootPath, "folder\\foo\\sub\\newTest(1).xml"), resultsCopy.Path); var results = File.Rename( new RenameInput() { Path = Path.Combine(TestFileContext.RootPath, "folder/foo/sub/newTest(1).xml"), NewFileName = "newTest.xml" }, new RenameOption() { RenameBehaviour = FileExistsAction.Throw }); Assert.Equal(Path.Combine(TestFileContext.RootPath, "folder\\foo\\sub\\newTest.xml"), results.Path); var folderFiles = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder/foo/sub/")); Assert.Single(folderFiles); TestFileContext.CreateFile("folder/foo/sub/throwTest.xml", "temp"); var ex = Assert.Throws <IOException>(() => File.Rename( new RenameInput() { Path = Path.Combine(TestFileContext.RootPath, "folder/foo/sub/newTest.xml"), NewFileName = "throwTest.xml" }, new RenameOption() { RenameBehaviour = FileExistsAction.Throw })); Assert.Contains("throwTest.xml", ex.Message); folderFiles = Directory.GetFiles(Path.Combine(TestFileContext.RootPath, "folder/foo/sub/")); Assert.Equal(2, folderFiles.Length); }