Esempio n. 1
0
        public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory(identifier: "new3").Path;

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute($"new3 console");

            DateTime expectedState = Directory.GetLastWriteTime(rootPath);

            var result = new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .ExecuteWithCapturedOutput($"new3 console");

            DateTime actualState = Directory.GetLastWriteTime(rootPath);

            Assert.Equal(expectedState, actualState);

            result.Should().Fail();
        }
Esempio n. 2
0
        public void TestsFromAGivenContainerShouldRunWithExpectedOutput()
        {
            // Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
            string       testAppName  = "VSTestDotNetCoreProject";
            TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);

            string testProjectDirectory = testInstance.TestRoot;

            // Restore project VSTestDotNetCoreProject
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Build project VSTestDotNetCoreProject
            new BuildCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Prepare args to send vstest
            string configuration   = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
            string testAdapterPath = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0");
            string outputDll       = Path.Combine(testAdapterPath, $"{testAppName}.dll");
            string argsForVstest   = string.Concat("\"", outputDll, "\"");

            // Call vstest
            CommandResult result = new VSTestCommand().ExecuteWithCapturedOutput(argsForVstest);

            // Verify
            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
        }
Esempio n. 3
0
        public void WhenGivenAValidPathItReadsAnSlnFile()
        {
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance("TestAppWithSln", callingMethod: "p").Path;

            var solutionFullPath = Path.Combine(solutionDirectory, "TestAppWithSln.sln");

            var slnFile = SlnFile.Read(solutionFullPath);

            slnFile.FormatVersion.Should().Be("12.00");
            slnFile.ProductDescription.Should().Be("Visual Studio 14");
            slnFile.VisualStudioVersion.Should().Be("14.0.25420.1");
            slnFile.MinimumVisualStudioVersion.Should().Be("10.0.40219.1");
            slnFile.BaseDirectory.Should().Be(solutionDirectory);
            slnFile.FullPath.Should().Be(solutionFullPath);

            slnFile.Projects.Count.Should().Be(1);
            var project = slnFile.Projects[0];

            project.Id.Should().Be("{0138CB8F-4AA9-4029-A21E-C07C30F425BA}");
            project.TypeGuid.Should().Be("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}");
            project.Name.Should().Be("TestAppWithSln");
            project.FilePath.Should().Be("TestAppWithSln.xproj");
        }
Esempio n. 4
0
        public TestCommand Setup(ITestOutputHelper log, TestAssetsManager testAssets, [CallerMemberName] string testName = null)
        {
            TestDirectory = testAssets.CreateTestDirectory(testName).Path;
            var testNuGetHome         = Path.Combine(TestDirectory, "nuget_home");
            var cliTestFallbackFolder = Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder");
            var profiled = Path.Combine(TestDirectory, "profile.d");
            var pathsd   = Path.Combine(TestDirectory, "paths.d");

            var command = new DotnetCommand(log)
                          .WithWorkingDirectory(TestDirectory)
                          .WithEnvironmentVariable("HOME", testNuGetHome)
                          .WithEnvironmentVariable("USERPROFILE", testNuGetHome)
                          .WithEnvironmentVariable("APPDATA", testNuGetHome)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER", cliTestFallbackFolder)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_LINUX_PROFILED_PATH", profiled)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_OSX_PATHSD_PATH", pathsd)
                          .WithEnvironmentVariable("SkipInvalidConfigurations", "true")
                          .WithEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName, "");

            NugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
            DotDotnetFolder     = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet"));

            return(command);
        }
        public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;
            var rootDir  = new DirectoryInfo(rootPath);

            string dir  = "pkgs";
            string args = $"--packages {dir}";

            new NewCommand()
            .WithWorkingDirectory(rootPath)
            .Execute()
            .Should()
            .Pass();

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute(args)
            .Should()
            .Pass();

            new PublishCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should().Pass();

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            var outputProgram = rootDir
                                .GetDirectory("bin", configuration, "netcoreapp2.0", "publish", $"{rootDir.Name}.dll")
                                .FullName;

            new TestCommand(outputProgram)
            .ExecuteWithCapturedOutput()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
Esempio n. 6
0
        public void RuntimeOptions_are_copied_from_projectJson_to_runtimeconfig_template_json_file()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").WithLockFiles();
            var projectDir   = testInstance.Path;
            var projectPath  = Path.Combine(testInstance.Path, "project.json");

            var project           = JObject.Parse(File.ReadAllText(projectPath));
            var rawRuntimeOptions = (JObject)project.GetValue("runtimeOptions");

            var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            var testSettings = new MigrationSettings(projectDir, projectDir, "1.0.0", default(ProjectRootElement));
            var testInputs   = new MigrationRuleInputs(new[] { projectContext }, null, null, null);

            new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);

            var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);

            File.Exists(migratedRuntimeOptionsPath).Should().BeTrue();

            var migratedRuntimeOptionsContent = JObject.Parse(File.ReadAllText(migratedRuntimeOptionsPath));

            JToken.DeepEquals(rawRuntimeOptions, migratedRuntimeOptionsContent).Should().BeTrue();
        }
Esempio n. 7
0
        public void ItCanRunAMSBuildProject()
        {
            var testAppName  = "MSBuildTestApp";
            var testInstance = TestAssetsManager
                               .CreateTestInstance(testAppName);

            var testProjectDirectory = testInstance.TestRoot;

            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute("/p:SkipInvalidConfigurations=true")
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should().Pass();

            new RunCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .ExecuteWithCapturedOutput()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World!");
        }
Esempio n. 8
0
        public void TFM_specific_Project_dependencies_are_migrated_to_ProjectReference_under_condition_ItemGroup()
        {
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance("TestAppWithLibraryUnderTFM", callingMethod: "p").Path;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Count().Should().Be(1);

            var projectReference = projectReferences.First();

            projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
            projectReference.Parent.Condition.Should().Be(" '$(TargetFramework)' == 'netcoreapp1.0' ");
        }
        public void ProjectDependenciesAreMigratedToProjectReference()
        {
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance("TestAppWithLibrary", callingMethod: "p").Path;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Count().Should().Be(1);

            var projectReference = projectReferences.First();

            projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
            projectReference.Parent.Condition.Should().BeEmpty();
        }
        private ProjectRootElement MigrateProject(
            string solution,
            string project,
            NuGetFramework targetFramework)
        {
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance(solution, callingMethod: "p").Path;

            var appDirectory = Path.Combine(solutionDirectory, project);

            var projectContext = ProjectContext.Create(appDirectory, targetFramework);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var s = mockProj.Items.Select(p => $"ItemType = {p.ItemType}, Include = {p.Include}");

            Console.WriteLine(string.Join(Environment.NewLine, s));

            return(mockProj);
        }
        public void It_migrates_project_with_output_name()
        {
            string projectName        = "AppWithOutputAssemblyName";
            string expectedOutputName = "MyApp";

            var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, callingMethod: $"It_migrates_{projectName}")
                                   .WithLockFiles()
                                   .Path;

            string expectedCsprojPath = Path.Combine(projectDirectory, $"{projectName}.csproj");

            if (File.Exists(expectedCsprojPath))
            {
                File.Delete(expectedCsprojPath);
            }

            CleanBinObj(projectDirectory);
            MigrateProject(projectDirectory);
            File.Exists(expectedCsprojPath).Should().BeTrue();
            Restore(projectDirectory, projectName);
            BuildMSBuild(projectDirectory, projectName);
            Directory.EnumerateFiles(Path.Combine(projectDirectory, "bin"), $"{expectedOutputName}.pdb", SearchOption.AllDirectories)
            .Count().Should().Be(1);
        }
Esempio n. 12
0
        public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks()
        {
            var testAppName  = "MSBuildAppWithMultipleFrameworks";
            var testInstance = TestAssetsManager
                               .CreateTestInstance(testAppName);

            var testProjectDirectory = testInstance.TestRoot;

            new Restore3Command()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute("/p:SkipInvalidConfigurations=true")
            .Should()
            .Pass();

            // use --no-build so this test can run on all platforms.
            // the test app targets net451, which can't be built on non-Windows
            new Run3Command()
            .WithWorkingDirectory(testProjectDirectory)
            .ExecuteWithCapturedOutput("--no-build")
            .Should()
            .Fail()
            .And
            .HaveStdErrContaining("--framework");
        }
        public void It_returns_a_CommandSpec_with_DOTNET_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
                               .WithLockFiles();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("dotnet");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
Esempio n. 14
0
        public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName()
        {
            var testInstance = TestAssetsManager
                               .CreateTestInstance("AppWithDirectDepWithOutputName")
                               .WithBuildArtifacts()
                               .WithLockFiles();

            var          appDirectory = testInstance.Path;
            const string framework    = ".NETCoreApp,Version=v1.0";

            new BuildCommand(Path.Combine(appDirectory, "project.json"))
            .Execute()
            .Should()
            .Pass();

            CommandResult result = new DependencyToolInvokerCommand {
                WorkingDirectory = appDirectory
            }
            .ExecuteWithCapturedOutput("tool-with-output-name", framework, string.Empty);

            result.Should().HaveStdOutContaining("Tool with output name!");
            result.Should().NotHaveStdErr();
            result.Should().Pass();
        }
 public void Init(ITestOutputHelper log, TestAssetsManager testAssetsManager)
 {
     Log = log;
     TestAssetsManager = testAssetsManager;
 }
Esempio n. 16
0
 public NoDepsAppTests(ITestOutputHelper logger)
 {
     _testAssetsManager = new TestAssetsManager(_output);
     _output            = logger;
 }
Esempio n. 17
0
 private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
 {
     return(new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path));
 }
 public GivenThatWeWantToPublishAHelloWorldProject()
 {
     _testAssetsManager = TestAssetsManager.TestProjectsAssetsManager;
 }
Esempio n. 19
0
 public DotNetWatcherTests(ITestOutputHelper logger)
 {
     _testAssetsManager = new TestAssetsManager(logger);
     _logger            = logger;
 }
Esempio n. 20
0
 protected TestInstance CreateTestInstance(string testProjectName, [CallerMemberName] string callingMethod = "")
 {
     return(TestAssetsManager.CreateTestInstance(Path.Combine("PerformanceTestProjects", testProjectName), callingMethod)
            .WithLockFiles());
 }
Esempio n. 21
0
 public static string ConstructNuGetPackageReferencePath(TestProject dependencyProject, string identifier, [CallerMemberName] string callingMethod = null)
 {
     return(TestAssetsManager.GetTestDestinationDirectoryPath(dependencyProject.Name, callingMethod, identifier));
 }
Esempio n. 22
0
 public BrowserLaunchTests(ITestOutputHelper logger)
 {
     _testAssetsManager = new TestAssetsManager(logger);
     _logger            = logger;
 }
Esempio n. 23
0
 public ProjectJsonBuilder(TestAssetsManager testAssetsManager)
 {
     _testAssetsManager = testAssetsManager;
 }
Esempio n. 24
0
 public DthTests()
 {
     _testAssetsManager = new TestAssetsManager(
         Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "DthTestProjects", "src"));
 }
Esempio n. 25
0
 private void CreateTestInstance()
 {
     _testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
                     .WithLockFiles();
     TestProjectRoot = _testInstance.TestRoot;
 }
Esempio n. 26
0
 public FileWatcherTests(ITestOutputHelper output)
 {
     _output           = output;
     _testAssetManager = new TestAssetsManager(output);
 }
Esempio n. 27
0
 public MsBuildFileSetFactoryTest(ITestOutputHelper output)
 {
     _reporter   = new TestReporter(output);
     _testAssets = new TestAssetsManager(output);
 }
Esempio n. 28
0
 public GlobbingAppTests(ITestOutputHelper logger)
 {
     _testAssetsManager = new TestAssetsManager(logger);
     _logger            = logger;
 }
        internal static void TestSatelliteResources(
            ITestOutputHelper log,
            TestAssetsManager testAssetsManager,
            Action <XDocument> projectChanges       = null,
            Action <BuildCommand> setup             = null,
            [CallerMemberName] string callingMethod = null)
        {
            var testAsset = testAssetsManager
                            .CopyTestAsset("AllResourcesInSatellite", callingMethod)
                            .WithSource();

            if (projectChanges != null)
            {
                testAsset = testAsset.WithProjectChanges(projectChanges);
            }

            testAsset = testAsset.Restore(log);

            var buildCommand = new BuildCommand(log, testAsset.TestRoot);

            if (setup != null)
            {
                setup(buildCommand);
            }

            buildCommand
            .Execute()
            .Should()
            .Pass();

            foreach (var targetFramework in new[] { "net46", "netcoreapp1.1" })
            {
                if (targetFramework == "net46" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    continue;
                }

                var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);

                var outputFiles = new List <string>
                {
                    "AllResourcesInSatellite.pdb",
                    "en/AllResourcesInSatellite.resources.dll"
                };

                Command command;
                if (targetFramework == "net46")
                {
                    outputFiles.Add("AllResourcesInSatellite.exe");
                    command = Command.Create(Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"), Array.Empty <string>());
                }
                else
                {
                    outputFiles.Add("AllResourcesInSatellite.dll");
                    outputFiles.Add("AllResourcesInSatellite.deps.json");
                    outputFiles.Add("AllResourcesInSatellite.runtimeconfig.json");
                    outputFiles.Add("AllResourcesInSatellite.runtimeconfig.dev.json");
                    command = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll") });
                }

                outputDirectory.Should().OnlyHaveFiles(outputFiles);

                command
                .CaptureStdOut()
                .Execute()
                .Should()
                .Pass()
                .And
                .HaveStdOutContaining("Hello World from en satellite assembly");
            }
        }
Esempio n. 30
0
 public ProgramTests(ITestOutputHelper output)
 {
     _testAssetsManager = new TestAssetsManager(output);
     _output            = output;
 }