public static void WritesXmlV1ToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For <ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, XmlV1 = xmlTaskItem }; xunit.Execute(); new XmlDocument().Load(tempFile); // File should exist as legal XML } finally { File.Delete(tempFile); } }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); string actual = Directory.GetCurrentDirectory(); string expected = tempFolder; if (actual[actual.Length - 1] != Path.DirectorySeparatorChar) { actual += Path.DirectorySeparatorChar; } if (expected[expected.Length - 1] != Path.DirectorySeparatorChar) { expected += Path.DirectorySeparatorChar; } Assert.Equal(expected, actual); }
public static void WritesHtmlToDisk() { var tempFile = Path.GetTempFileName(); File.Delete(tempFile); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var htmlTaskItem = Substitute.For <ITaskItem>(); htmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Html = htmlTaskItem }; xunit.Execute(); Assert.True(File.Exists(tempFile)); } finally { File.Delete(tempFile); } }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); xunit.BuildEngine.Received().LogMessageEvent(Arg.Is<BuildMessageEventArgs>(bmea => ValidateWelcomeBanner(bmea))); }
public static void ReturnsTrueWhenExitCodeIsZeroAndFailCountIsZero() { var xunit = new Testable_xunit(exitCode: 0); var result = xunit.Execute(); Assert.True(result); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); xunit.BuildEngine.Received().LogMessageEvent(Arg.Is <BuildMessageEventArgs>(bmea => ValidateWelcomeBanner(bmea))); }
public static void ReturnsFalseWhenExitCodeIsNonZero() { var xunit = new Testable_xunit(exitCode: 1); var result = xunit.Execute(); Assert.False(result); }
public void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); Assert.Equal(tempFolder, Directory.GetCurrentDirectory()); }
public static void DoesNotChangeCurrentDirectoryWhenWorkingFolderIsNull() { var currentFolder = Directory.GetCurrentDirectory(); var xunit = new Testable_xunit(); xunit.Execute(); Assert.Equal(currentFolder, Directory.GetCurrentDirectory()); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var eventArgs = Assert.IsType<BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal(string.Format("xUnit.net MSBuild Runner ({0}-bit .NET {1})", IntPtr.Size * 8, Environment.Version), eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); Assert.Equal(tempFolder, Directory.GetCurrentDirectory()); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var eventArgs = Assert.IsType <BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal(string.Format("xUnit.net MSBuild Runner ({0}-bit .NET {1})", IntPtr.Size * 8, Environment.Version), eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var versionAttribute = typeof(xunit).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); var eventArgs = Assert.IsType <BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal($"xUnit.net v3 MSBuild Runner v{versionAttribute!.InformationalVersion} ({IntPtr.Size * 8}-bit {RuntimeInformation.FrameworkDescription})", eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public void CallsExecuteAssemblyOnceForEachAssembly() { var visitor = new XmlTestExecutionVisitor(null, null); visitor.Finished.Set(); var assm1 = new TaskItem(@"C:\Full\Path\1"); var assm2 = new TaskItem(@"C:\Full\Path\2", new Dictionary<string, string> { { "ConfigFile", @"C:\Config\File" } }); var xunit = new Testable_xunit { CreateVisitor_Result = visitor }; xunit.Assemblies = new ITaskItem[] { assm1, assm2 }; xunit.Execute(); Assert.Collection(xunit.ExecuteAssembly_Calls, call => Assert.Equal(@"C:\Full\Path\1, (null)", call), call => Assert.Equal(@"C:\Full\Path\2, C:\Config\File", call) ); }
public static void ReturnsFalseWhenFailCountIsNonZero() { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task } }; var result = xunit.Execute(); Assert.False(result); }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP") ?? Environment.GetEnvironmentVariable("TMP") ?? Environment.GetEnvironmentVariable("TMPDIR") ?? "/tmp"; tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used // For macOS compatibility, switch to the folder and then get it, because the temp folder // is usually under /var/folders/... which is softlinked to /private/var/folders var originalDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(tempFolder); tempFolder = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(originalDirectory); var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); var actual = Directory.GetCurrentDirectory(); var expected = tempFolder; if (actual[actual.Length - 1] != Path.DirectorySeparatorChar) { actual += Path.DirectorySeparatorChar; } if (expected[expected.Length - 1] != Path.DirectorySeparatorChar) { expected += Path.DirectorySeparatorChar; } Assert.Equal(expected, actual); }
public static void CallsExecuteAssemblyOnceForEachAssembly() { var visitor = new XmlTestExecutionVisitor(null, null); visitor.Finished.Set(); var assm1 = new TaskItem(@"C:\Full\Path\1"); var assm2 = new TaskItem(@"C:\Full\Path\2", new Dictionary <string, string> { { "ConfigFile", @"C:\Config\File" } }); var xunit = new Testable_xunit { CreateVisitor_Result = visitor }; xunit.Assemblies = new ITaskItem[] { assm1, assm2 }; xunit.Execute(); Assert.Collection(xunit.ExecuteAssembly_Calls, call => Assert.Equal(@"C:\Full\Path\1, (null)", call), call => Assert.Equal(@"C:\Full\Path\2, C:\Config\File", call) ); }
public void StopsExecutingAssemblyWhenCanceled() { var assembly = new TaskItem(@"C:\Full\Path\1"); var xunit = new Testable_xunit { Assemblies = new ITaskItem[] { assembly } }; xunit.Cancel(); xunit.Execute(); Assert.Empty(xunit.ExecuteAssembly_Calls); }
public void WritesXmlToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new MSBuildVisitor(null, null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For<ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Xml = xmlTaskItem }; xunit.Execute(); Assert.DoesNotThrow(() => new XmlDocument().Load(tempFile)); } finally { File.Delete(tempFile); } }
public static void ReturnsFalseWhenFailCountIsNonZero() { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task } }; xunit.DiscoveryTestCases.Add(Mocks.TestCase()); var result = xunit.Execute(); Assert.False(result); }
public static void WritesXmlV1ToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For<ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, XmlV1 = xmlTaskItem }; xunit.Execute(); new XmlDocument().Load(tempFile); // File should exist as legal XML } finally { File.Delete(tempFile); } }
public static void WritesHtmlToDisk() { var tempFile = Path.GetTempFileName(); File.Delete(tempFile); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var htmlTaskItem = Substitute.For<ITaskItem>(); htmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Html = htmlTaskItem }; xunit.Execute(); Assert.True(File.Exists(tempFile)); } finally { File.Delete(tempFile); } }