public void ItReturnsACommandSpecWhenToolIsInAProjectRef() { MSBuildTestProjectInstance = TestAssets.Get("TestAppWithProjDepTool") .CreateInstance() .WithSourceFiles() .WithNuGetConfig(RepoDirectoriesProvider.TestPackages); new BuildCommand() .WithProjectDirectory(MSBuildTestProjectInstance.Root) .WithConfiguration(_configuration) .Execute() .Should().Pass(); var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver(); var commandResolverArguments = new CommandResolverArguments() { CommandName = "dotnet-portable", Configuration = _configuration, ProjectDirectory = MSBuildTestProjectInstance.Root.FullName, Framework = NuGetFrameworks.NetCoreApp30 }; var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); var commandFile = Path.GetFileNameWithoutExtension(result.Path); commandFile.Should().Be("dotnet"); result.Args.Should().Contain(commandResolverArguments.CommandName); }
private static FilePath MakeHelloWorldExecutableDll(string instanceName = null) { const string testAppName = "TestAppSimple"; const string emptySpaceToTestSpaceInPath = " "; const string directoryNamePostFix = "Test"; if (instanceName == null) { instanceName = testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix; } TestAssetInstance testInstance = TestAssets.Get(testAppName) .CreateInstance(instanceName) .WithRestoreFiles() .WithBuildFiles(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; FileInfo outputDll = testInstance.Root.GetDirectory("bin", configuration) .EnumerateDirectories() .Single() .GetFile($"{testAppName}.dll"); return(new FilePath(outputDll.FullName)); }
public void ItPassesDepsfileArgToHostWhenReturningACommandSpecForMSBuildProject() { MSBuildTestProjectInstance = TestAssets.Get("TestAppWithProjDepTool") .CreateInstance() .WithSourceFiles() .WithNuGetConfig(RepoDirectoriesProvider.TestPackages); new BuildCommand() .WithProjectDirectory(MSBuildTestProjectInstance.Root) .WithConfiguration(_configuration) .Execute() .Should().Pass(); var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver(); var commandResolverArguments = new CommandResolverArguments() { CommandName = "dotnet-portable", Configuration = _configuration, ProjectDirectory = MSBuildTestProjectInstance.Root.FullName, Framework = NuGetFrameworks.NetCoreApp30 }; var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); result.Args.Should().Contain("--depsfile"); }
public static TestAssetInstance WithRepoGlobalPackages(this TestAssetInstance testAssetInstance) { return(testAssetInstance.WithProjectChanges(project => { var ns = project.Root.Name.Namespace; project.Root.Element(ns + "PropertyGroup") .Add(new XElement(ns + "RestorePackagesPath", RepoDirectoriesProvider.TestGlobalPackagesFolder)); })); }
public TestSetupFixture() { _testInstance = TestAssets.Get("DesktopTestProjects", "BindingRedirectSample") .CreateInstance() .WithSourceFiles() .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages); _appWithConfigProjectRoot = Setup(AppWithConfig); _appWithoutConfigProjectRoot = Setup(AppWithoutConfig); }
public GivenThatICareAboutVBApps() { _testInstance = TestAssets.Get("VBTestApp") .CreateInstance() .WithSourceFiles(); new RestoreCommand() .WithWorkingDirectory(_testInstance.Root) .Execute() .Should().Pass(); }
public static TestAssetInstance WithNuGetConfigAndExternalRestoreSources( this TestAssetInstance testAssetInstance, string nugetCache) { var externalRestoreSourcesForTests = Path.Combine( new RepoDirectoriesProvider().TestArtifactsFolder, "ExternalRestoreSourcesForTestsContainer.txt"); var externalRestoreSources = File.Exists(externalRestoreSourcesForTests) ? File.ReadAllText(externalRestoreSourcesForTests) : string.Empty; return(testAssetInstance.WithNuGetConfig(nugetCache, externalRestoreSources)); }
private string SetupTestPackages() { var directory = TestAssets.CreateTestDirectory( testProjectName: string.Empty, callingMethod: "TestPackages", identifier: string.Empty); string testPackagesDirectory = Path.Combine(directory.FullName, "testPackages"); if (!Directory.Exists(testPackagesDirectory)) { new DirectoryInfo(testPackagesDirectory).Create(); } var testPackageNames = new[] { "dotnet-portable", "dotnet-prefercliruntime" }; foreach (var testPackageName in testPackageNames) { var assetInfo = TestAssets.Get(TestAssetKinds.TestPackages, testPackageName); var testProjectDirectory = new DirectoryInfo(Path.Combine(directory.FullName, testPackageName)); if (!testProjectDirectory.Exists) { testProjectDirectory.Create(); } var testInstance = new TestAssetInstance(assetInfo, testProjectDirectory) .WithSourceFiles() .WithRestoreFiles(); new PackCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); string nupkgFilePathInOutput = Directory.GetFiles(Path.Combine(testProjectDirectory.FullName, "bin", "Debug"), "*.nupkg") .Single(); string nupkgFile = Path.Combine(testPackagesDirectory, Path.GetFileName(nupkgFilePathInOutput)); File.Copy(nupkgFilePathInOutput, nupkgFile); } return(testPackagesDirectory); }
private string UseNuGetConfigWithFallbackFolder(TestAssetInstance testInstance, string fallbackFolder) { var nugetConfig = testInstance.Root.GetFile("NuGet.Config").FullName; File.WriteAllText( nugetConfig, $@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""MachineWide"" value=""{fallbackFolder}""/> </fallbackPackageFolders> </configuration> "); return(nugetConfig); }
public void BuildSingleProject(TestAssetInstance instance) { foreach (var iteration in Benchmark.Iterations) { var buildCommand = new BuildCommand() .WithProjectDirectory(instance.Root); using (iteration.StartMeasurement()) { buildCommand.Execute() .Should().Pass(); } TouchSource(instance.Root); } }
private static FilePath MakeHelloWorldExecutableDll() { const string testAppName = "TestAppSimple"; const string emptySpaceToTestSpaceInPath = " "; TestAssetInstance testInstance = TestAssets.Get(testAppName) .CreateInstance(testAppName + emptySpaceToTestSpaceInPath + "test") .UseCurrentRuntimeFrameworkVersion() .WithRestoreFiles() .WithBuildFiles(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; FileInfo outputDll = testInstance.Root.GetDirectory("bin", configuration) .GetDirectories().Single() .GetFile($"{testAppName}.dll"); return(new FilePath(outputDll.FullName)); }
public void ItReturnsNullWhenCommandNameDoesNotExistInProjectDependenciesForMSBuildProject() { MSBuildTestProjectInstance = TestAssets.Get("TestAppWithProjDepTool") .CreateInstance() .WithSourceFiles() .WithRestoreFiles(); var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver(); var commandResolverArguments = new CommandResolverArguments() { CommandName = "nonexistent-command", CommandArguments = null, ProjectDirectory = MSBuildTestProjectInstance.Root.FullName, Framework = NuGetFrameworks.NetCoreApp30 }; var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments); result.Should().BeNull(); }
public static TestAssetInstance WithVersionVariables(this TestAssetInstance testAssetInstance) { var assemblyMetadata = typeof(TestAssetInstanceExtensions).Assembly .GetCustomAttributes(typeof(AssemblyMetadataAttribute)) .Cast <AssemblyMetadataAttribute>() .ToDictionary(a => a.Key, a => a.Value); return(testAssetInstance.WithProjectChanges(project => { var ns = project.Root.Name.Namespace; foreach (var valueToReplace in new[] { "MSTestVersion", "MicrosoftNETTestSdkPackageVersion" }) { var packageReferencesToUpdate = project.Root.Descendants(ns + "PackageReference") .Where(pr => pr.Attribute("Version").Value.Equals($"$({valueToReplace})", StringComparison.OrdinalIgnoreCase)); foreach (var packageReference in packageReferencesToUpdate) { packageReference.Attribute("Version").Value = assemblyMetadata[valueToReplace]; } } })); }