public void It_resolves_desktop_apps_when_configuration_is_Release()
        {
            var configuration = "Release";

            var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"));
            var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable")
                .WithLockFiles();

            var buildCommand = new BuildCommand(
                Path.Combine(testInstance.TestRoot, "project.json"),
                configuration: configuration)
                    .ExecuteWithCapturedOutput()
                    .Should()
                    .Pass();

            var context = ProjectContext.Create(testInstance.TestRoot, s_desktopTestFramework);

            var factory = new ProjectDependenciesCommandFactory(
                s_desktopTestFramework,
                configuration,
                null,
                null,
                testInstance.TestRoot);

            var command = factory.Create("dotnet-desktop-and-portable", null);

            command.CommandName.Should().Contain(Path.Combine(testInstance.TestRoot, "bin", configuration));
            Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
        }
Example #2
0
File: DthTests.cs Project: krwq/cli
        public DthTests()
        {
            _loggerFactory = new LoggerFactory();

            var testVerbose = Environment.GetEnvironmentVariable("DOTNET_TEST_VERBOSE");
            if (testVerbose == "2")
            {
                _loggerFactory.AddConsole(LogLevel.Trace);
            }
            else if (testVerbose == "1")
            {
                _loggerFactory.AddConsole(LogLevel.Information);
            }
            else if (testVerbose == "0")
            {
                _loggerFactory.AddConsole(LogLevel.Warning);
            }
            else
            {
                _loggerFactory.AddConsole(LogLevel.Error);
            }

            _testAssetsManager = new TestAssetsManager(
                Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "DthTestProjects", "src"));
        }
Example #3
0
        protected static TestAssetsManager GetTestGroupTestAssetsManager(string testGroup)
        {
            string assetsRoot = Path.Combine(RepoRoot, "TestAssets", testGroup);
            var testAssetsMgr = new TestAssetsManager(assetsRoot);

            return testAssetsMgr;
        }
Example #4
0
        public TestSetupFixture()
        {
            _buildRelativePath = Path.Combine("bin", Config, Framework, _Runtime);
            var testAssetsMgr = new TestAssetsManager(_desktopProjectsRoot);
            _testInstance = testAssetsMgr.CreateTestInstance("BindingRedirectSample")
                                         .WithLockFiles();

            Setup(AppWithConfig, ref _appWithConfigProjectRoot, ref _appWithConfigBuildDir, ref _appWithConfigPublishDir);
            Setup(AppWithoutConfig, ref _appWithoutConfigProjectRoot, ref _appWithoutConfigBuildDir, ref _appWithoutConfigPublishDir);

            AppWithConfigBuildOutput = Path.Combine(_appWithConfigBuildDir, AppWithConfig + ".exe");
            AppWithConfigPublishOutput = Path.Combine(_appWithConfigPublishDir, AppWithConfig + ".exe");
            AppWithoutConfigBuildOutput = Path.Combine(_appWithoutConfigBuildDir, AppWithoutConfig + ".exe");
            AppWithoutConfigPublishOutput = Path.Combine(_appWithoutConfigPublishDir, AppWithoutConfig + ".exe");
        }
Example #5
0
        public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
        {
            var assets = new TestAssetsManager(Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer"));
            var projectPath = assets.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
            Assert.True(Directory.Exists(projectPath));

            using (var server = new DthTestServer(_loggerFactory))
            using (var client = new DthTestClient(server))
            {
                var testProject = Path.Combine(projectPath, "home", "src", "MainProject");

                client.Initialize(testProject);

                client.DrainTillFirst("ProjectInformation")
                      .RetrievePayloadAs<JObject>()
                      .RetrievePropertyAs<JArray>("ProjectSearchPaths")
                      .AssertJArrayCount(2);

                client.DrainTillFirst("DependencyDiagnostics")
                      .RetrievePayloadAs<JObject>()
                      .AssertProperty<JArray>("Errors", array => array.Count == 0)
                      .AssertProperty<JArray>("Warnings", array => array.Count == 0);

                client.DrainTillFirst("Dependencies")
                      .RetrieveDependency("Newtonsoft.Json")
                      .AssertProperty("Type", "Project")
                      .AssertProperty("Resolved", true)
                      .AssertProperty<JArray>("Errors", array => array.Count == 0, _ => "Dependency shouldn't contain any error.");

                // Overwrite the global.json to remove search path to ext
                File.WriteAllText(
                    Path.Combine(projectPath, "home", GlobalSettings.FileName),
                    JsonConvert.SerializeObject(new { project = new string[] { "src" } }));

                client.SendPayLoad(testProject, "RefreshDependencies");

                client.DrainTillFirst("ProjectInformation")
                      .RetrievePayloadAs<JObject>()
                      .RetrievePropertyAs<JArray>("ProjectSearchPaths")
                      .AssertJArrayCount(1)
                      .AssertJArrayElement(0, Path.Combine(projectPath, "home", "src"));

                client.DrainTillFirst("DependencyDiagnostics")
                      .RetrieveDependencyDiagnosticsCollection()
                      .RetrieveDependencyDiagnosticsErrorAt<JObject>(0)
                      .AssertProperty("ErrorCode", "NU1010");

                client.DrainTillFirst("Dependencies")
                      .RetrieveDependency("Newtonsoft.Json")
                      .AssertProperty("Type", "")
                      .AssertProperty("Resolved", false)
                      .RetrievePropertyAs<JArray>("Errors")
                      .AssertJArrayCount(1)
                      .RetrieveArraryElementAs<JObject>(0)
                      .AssertProperty("ErrorCode", "NU1010");
            }
        }
Example #6
0
File: DthTests.cs Project: krwq/cli
        public void RemoveMSBuildDependencyFromProjectJson()
        {
            // Remove a msbuild project dependency from project.json and then request refreshing dependency before
            // restore.

            var tam = new TestAssetsManager(
                Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects"));

            // var appName = "EmptyNetCoreApp";
            var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot;
            projectPath = Path.Combine(projectPath, "src", "MainApp");

            using (var server = new DthTestServer(_loggerFactory))
            using (var client = new DthTestClient(server, _loggerFactory))
            {
                client.Initialize(projectPath);

                client.DrainAllMessages()
                      .AssertDoesNotContain(MessageTypes.Error)
                      .RetrieveSingleMessage(MessageTypes.Dependencies)
                      .RetrieveDependency("MainApp")
                      .RetrievePropertyAs<JArray>("Dependencies")
                      .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary1")
                      .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary2")
                      .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary3");

                var projectFilePath = Path.Combine(projectPath, Project.FileName);
                var projectJson = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(projectFilePath));

                // Remove ClassLibrary2 and ClassLibrary3 dependency
                var dependencies = projectJson["frameworks"]["net46"]["dependencies"] as JObject;
                dependencies.Remove("ClassLibrary2");
                dependencies.Remove("ClassLibrary3");

                File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson));

                client.SendPayLoad(projectPath, MessageTypes.RefreshDependencies);

                var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies);
                afterDependencies.RetrieveDependency("MainApp")
                                 .RetrievePropertyAs<JArray>("Dependencies")
                                 .AssertJArrayNotContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary2")
                                 .AssertJArrayNotContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary3");

                afterDependencies.RetrieveDependency("ClassLibrary2");
                afterDependencies.RetrieveDependency("ClassLibrary3");
            }
        }
Example #7
0
File: DthTests.cs Project: krwq/cli
        public void AddMSBuildReferenceBeforeRestore()
        {
            var tam = new TestAssetsManager(
                Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects"));

            // var appName = "EmptyNetCoreApp";
            var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot;
            projectPath = Path.Combine(projectPath, "src", "MainApp");

            var projectFilePath = Path.Combine(projectPath, Project.FileName);
            var projectJson = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(projectFilePath));

            ((JObject)projectJson["frameworks"]["net46"]["dependencies"])
                .Add("ClassLibrary4", JToken.FromObject(new { target = "project" }));

            File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson));

            using (var server = new DthTestServer(_loggerFactory))
            using (var client = new DthTestClient(server, _loggerFactory))
            {
                client.Initialize(projectPath);
                var messages = client.DrainAllMessages();
                messages.AssertDoesNotContain(MessageTypes.Error);
                // PrintAllMessages(new[] { messages.RetrieveSingleMessage(MessageTypes.Dependencies) });
                messages.RetrieveSingleMessage(MessageTypes.Dependencies)
                        .RetrieveDependency("ClassLibrary4")
                        .AssertProperty<object>(
                            "Version",
                            v => !string.IsNullOrEmpty(v.ToString()),
                            v => $"Version string shouldn't be empty. Value [{v.ToString()}]");
            }
        }
Example #8
0
File: DthTests.cs Project: krwq/cli
        public void InvalidGlobalJson()
        {
            var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer");
            var assetsManager = new TestAssetsManager(testAssetsPath);
            var testSource = assetsManager.CreateTestInstance("IncorrectGlobalJson");

            using (var server = new DthTestServer(_loggerFactory))
            using (var client = new DthTestClient(server, _loggerFactory))
            {
                client.Initialize(Path.Combine(testSource.TestRoot, "src", "Project1"));

                var messages = client.DrainAllMessages();
                messages.ContainsMessage(MessageTypes.Error)
                        .Single().Payload.AsJObject()
                        .AssertProperty<string>("Path", v => v.Contains("InvalidGlobalJson"));
            }
        }
Example #9
0
File: DthTests.cs Project: krwq/cli
        public void InvalidProjectJson()
        {
            var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer");
            var assetsManager = new TestAssetsManager(testAssetsPath);
            var testSource = assetsManager.CreateTestInstance("IncorrectProjectJson").TestRoot;

            using (var server = new DthTestServer(_loggerFactory))
            using (var client = new DthTestClient(server, _loggerFactory))
            {
                client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyLibrary"));
                client.Initialize(testSource);

                // Error for invalid project.json
                var messages = client.DrainAllMessages();
                messages.Single(msg => msg.MessageType == MessageTypes.Error)
                        .Payload.AsJObject()
                        .AssertProperty<string>("Path", v => v.Contains("IncorrectProjectJson"));

                // Successfully initialize the other project
                messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation)
                        .Payload.AsJObject()
                        .AssertProperty<string>("Name", v => string.Equals(v, "EmptyLibrary", StringComparison.Ordinal));

                // Successfully initialize another project afterwards
                client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp"));
                messages = client.DrainAllMessages();
                messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation)
                        .Payload.AsJObject()
                        .AssertProperty<string>("Name", v => string.Equals(v, "EmptyConsoleApp", StringComparison.Ordinal));
            }
        }
        public void It_resolves_tools_whose_package_name_is_different_than_dll_name()
        {
            var configuration = "Debug";

            var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "TestProjects"));
            var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyWithOutputName")
                .WithLockFiles();

            var buildCommand = new BuildCommand(
                Path.Combine(testInstance.TestRoot, "project.json"),
                configuration: configuration)
                    .ExecuteWithCapturedOutput()
                    .Should()
                    .Pass();

            var context = ProjectContext.Create(testInstance.TestRoot, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            var factory = new ProjectDependenciesCommandFactory(
                FrameworkConstants.CommonFrameworks.NetCoreApp10,
                configuration,
                null,
                null,
                testInstance.TestRoot);

            var command = factory.Create("dotnet-tool-with-output-name", null);

            command.CommandArgs.Should().Contain(
                Path.Combine("ToolWithOutputName", "1.0.0", "lib", "netcoreapp1.0", "dotnet-tool-with-output-name.dll"));
        }
Example #11
0
 public DthTests()
 {
     _testAssetsManager = new TestAssetsManager(
         Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "DthTestProjects", "src"));
 }
 public PublishDesktopTests()
 {
     _testAssetsManager = GetTestGroupTestAssetsManager("DesktopTestProjects");
 }