Esempio n. 1
0
        public void BuildSucceedsForNonApplicationPackage()
        {
            var project = ProjectUtilities.GetProject(@"{ }", @"foo", @"c:\foo\project.json");
            var builder = new InstallBuilder(project, null, null);

            Assert.True(builder.Build(@"c:\foo"));
        }
Esempio n. 2
0
        public void AuthorsAreSet()
        {
            var project = ProjectUtilities.GetProject(@"{ ""authors"": [""Bob"", ""Dean""] }", @"foo", @"C:\Foo\Project.json");

            Assert.Equal("Bob", project.Authors[0]);
            Assert.Equal("Dean", project.Authors[1]);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the containing project of the file (The IVsHierarchy) if available.
        /// </summary>
        /// <returns>The IVsHierarchyItem for the current document.</returns>
        private IVsHierarchy GetHierarchyItem()
        {
            var solution = this.serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

            if (solution == null || this.Document == null)
            {
                return(null);
            }

            var project = ProjectUtilities.GetProject(this.Document);

            if (project == null)
            {
                return(null);
            }

            IVsHierarchy hierarchyItem;
            var          result = solution.GetProjectOfUniqueName(project.UniqueName, out hierarchyItem);

            if (result == VSConstants.S_OK)
            {
                return(hierarchyItem);
            }

            return(null);
        }
Esempio n. 4
0
        public void EmptyTagsListWhenNotSpecified()
        {
            var project = ProjectUtilities.GetProject(@" { }", "foo", @"c:\foo\project.json");

            Assert.NotNull(project.Tags);
            Assert.Equal(0, project.Tags.Count());
        }
Esempio n. 5
0
        public void ProjectWithCommandsIsApplicationPackage()
        {
            var project = ProjectUtilities.GetProject(@"{ ""commands"" : { ""demo"":""demo"" } }", @"foo", @"c:\foo\project.json");
            var builder = new InstallBuilder(project, null, null);

            Assert.True(builder.IsApplicationPackage);
        }
Esempio n. 6
0
        public void ScriptsSetIsSet()
        {
            var projectContent = @"
{
    ""scripts"": {
        ""GroupA"": ""GroupA first command"",
        ""GroupB"": [
            ""GroupeB first command"",
            ""GroupeB second command"",
            ""GroupeB third command""
        ]
    }
}";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.NotNull(project.Scripts);
            Assert.Equal(2, project.Scripts.Count);

            var scriptGroupA = project.Scripts["GroupA"];

            Assert.Equal(1, scriptGroupA.Count());
            Assert.Equal("GroupA first command", scriptGroupA.First());

            var scriptGroupB = project.Scripts["GroupB"];

            Assert.Equal(3, scriptGroupB.Count());
            Assert.Equal("GroupeB first command", scriptGroupB.ElementAt(0));
            Assert.Equal("GroupeB second command", scriptGroupB.ElementAt(1));
            Assert.Equal("GroupeB third command", scriptGroupB.ElementAt(2));
        }
Esempio n. 7
0
        public void CommonBooleanPropertiesAreSet(string jsonPropertyName,
                                                  string jsonPropertyValue,
                                                  string objectPropertyName,
                                                  bool expectResult)
        {
            var propertyInfo = typeof(Project).GetTypeInfo().GetDeclaredProperty(objectPropertyName);

            Assert.NotNull(propertyInfo);

            string projectContent;

            if (jsonPropertyValue != null)
            {
                projectContent = string.Format("{{ \"{0}\": {1} }}", jsonPropertyName, jsonPropertyValue);
            }
            else
            {
                projectContent = @"{}";
            }

            var project = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            var propertyValue = (bool)propertyInfo.GetValue(project);

            Assert.Equal(expectResult, propertyValue);
        }
Esempio n. 8
0
        public void CompilerServicesIsNullByDefault()
        {
            var projectContent = @"{}";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.Null(project.CompilerServices);
        }
Esempio n. 9
0
        public void CompilerOptionsAreSetPerConfiguration()
        {
            var project = ProjectUtilities.GetProject(@"
{
    ""frameworks"" : {
        ""net45"":  {
            ""compilationOptions"": { ""allowUnsafe"": true, ""define"": [""X"", ""y""], ""platform"": ""x86"", ""warningsAsErrors"": true, ""optimize"": true, ""debugSymbols"": ""none"" }
        },
        ""k10"": {
            ""compilationOptions"": { ""warningsAsErrors"": true, ""debugSymbols"": ""pdbOnly"" }
        }
    }
}",
                                                      "foo",
                                                      @"c:\foo\project.json");

            var net45Options = project.GetCompilationSettings("net45");
            var k10Options   = project.GetCompilationSettings("k10");

            Assert.True(net45Options.CompilationOptions.AllowUnsafe);
            Assert.Equal(new[] { "DEBUG", "TRACE", "X", "y", "NET45" }, net45Options.Defines);
            Assert.Equal(Platform.X86, net45Options.CompilationOptions.Platform);
            Assert.Equal(ReportDiagnostic.Error, net45Options.CompilationOptions.GeneralDiagnosticOption);
            Assert.Equal(OptimizationLevel.Release, net45Options.CompilationOptions.OptimizationLevel);

            Assert.Equal(new[] { "DEBUG", "TRACE", "K10" }, k10Options.Defines);
            Assert.Equal(ReportDiagnostic.Error, k10Options.CompilationOptions.GeneralDiagnosticOption);
        }
Esempio n. 10
0
        public void ResolveNewNamedResxResources()
        {
            var expected = new[]
            {
                "testproject.OwnResources.resources",
                "testproject.subfolder.nestedresource.resources",
                "thisIs.New.Resource.resources"
            };
            var rootDir           = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var testProjectFolder = Path.Combine(rootDir, "misc", "ResourcesTestProjects", "testproject");

            Project project = ProjectUtilities.GetProject(@"
{
    ""namedResource"": {
        ""thisIs.New.Resource"": ""../someresources/OtherResources.resx""
    }
}",
                                                          "testproject",
                                                          Path.Combine(testProjectFolder, "project.json"));

            var resolver          = new ResxResourceProvider();
            var embeddedResources = resolver.GetResources(project).Select(resource => resource.Name).ToArray();

            Assert.Equal(expected, embeddedResources);
        }
Esempio n. 11
0
        public void OwnersAreSet()
        {
            var project = ProjectUtilities.GetProject(@"{ ""owners"": [""Alice"", ""Chi""] }", @"foo", @"C:\Foo\Project.json");

            Assert.Equal("Alice", project.Owners[0]);
            Assert.Equal("Chi", project.Owners[1]);
        }
Esempio n. 12
0
        public void NoCommandsIsNonApplicationPackage()
        {
            var project = ProjectUtilities.GetProject(@"{ }", @"foo", @"c:\foo\project.json");
            var builder = new InstallBuilder(project, null, null);

            Assert.False(builder.IsApplicationPackage);
        }
Esempio n. 13
0
        public void NameIsIgnoredIsSpecified()
        {
            // Arrange & Act
            var project = ProjectUtilities.GetProject(@"{ ""name"": ""hello"" }", @"foo", @"c:\foo\project.json");

            // Assert
            Assert.Equal("foo", project.Name);
        }
Esempio n. 14
0
        public void ScriptsSetIsEmptyByDefault()
        {
            var projectContent = @"{}";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.NotNull(project.Scripts);
            Assert.Equal(0, project.Scripts.Count);
        }
Esempio n. 15
0
        protected override ProjectFilesCollection CreateFilesCollection(string jsonContent, string projectDir)
        {
            var project = ProjectUtilities.GetProject(
                jsonContent,
                "testproject",
                Path.Combine(Root.DirPath, PathHelper.NormalizeSeparator(projectDir), "project.json"));

            return(project.Files);
        }
Esempio n. 16
0
        public void CompilerServicesDefaultValues()
        {
            var projectContent = @"{""compiler"": {} }";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.NotNull(project.CompilerServices);
            Assert.Equal("C#", project.CompilerServices.Name);
            Assert.Null(project.CompilerServices.ProjectCompiler.AssemblyName);
            Assert.Null(project.CompilerServices.ProjectCompiler.TypeName);
        }
Esempio n. 17
0
        public void ProjectUrlIsSet()
        {
            var project = ProjectUtilities.GetProject(@"
{
    ""projectUrl"": ""https://github.com/aspnet/KRuntime""
}",
                                                      "foo",
                                                      @"c:\foo\project.json");

            Assert.Equal("https://github.com/aspnet/KRuntime", project.ProjectUrl);
        }
Esempio n. 18
0
        public void CompilerOptionsAreNotNullIfNotSpecified()
        {
            var project = ProjectUtilities.GetProject(@"
{}",
                                                      "foo",
                                                      @"c:\foo\project.json");

            var compilerOptions = project.GetCompilerOptions();

            Assert.NotNull(compilerOptions);
            Assert.Null(compilerOptions.Defines);
        }
Esempio n. 19
0
        public void CompilerOptionsAreSetPerConfiguration()
        {
            var project = ProjectUtilities.GetProject(@"
{
    ""frameworks"" : {
        ""net45"":  {
            ""compilationOptions"": { ""allowUnsafe"": true, ""define"": [""X"", ""y""], ""platform"": ""x86"", ""warningsAsErrors"": true }
        },
        ""dnx451"": {
        },
        ""dnxcore50"": {
            ""compilationOptions"": { ""define"": [""X""], ""warningsAsErrors"": true }
        },
        ""k10"": {
            ""compilationOptions"": { ""warningsAsErrors"": true }
        }
    }
}",
                                                      "foo",
                                                      @"c:\foo\project.json");

            var compilerOptions = project.GetCompilerOptions();

            Assert.NotNull(compilerOptions);
            var net45Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("net45"));

            Assert.NotNull(net45Options);
            Assert.True(net45Options.AllowUnsafe.Value);
            Assert.Equal(new[] { "X", "y", "NET45" }, net45Options.Defines);
            Assert.True(net45Options.WarningsAsErrors.Value);
            Assert.Equal("x86", net45Options.Platform);

            var dnx451Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("dnx451"));

            Assert.NotNull(dnx451Options);
            Assert.Equal(new[] { "DNX451" }, dnx451Options.Defines);
            Assert.Null(dnx451Options.AllowUnsafe);

            var aspnetCore50Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("dnxcore50"));

            Assert.NotNull(aspnetCore50Options);
            Assert.Equal(new[] { "X", "DNXCORE50" }, aspnetCore50Options.Defines);
            Assert.True(aspnetCore50Options.WarningsAsErrors.Value);

            var k10Options = project.GetCompilerOptions(FrameworkNameHelper.ParseFrameworkName("k10"));

            Assert.NotNull(k10Options);
            Assert.Null(k10Options.AllowUnsafe);
            Assert.Equal(new[] { "K10" }, k10Options.Defines);
            Assert.True(k10Options.WarningsAsErrors.Value);
            Assert.Null(k10Options.Platform);
        }
Esempio n. 20
0
        public void ChangingLanguageVersionIsEffective()
        {
            var project = ProjectUtilities.GetProject(
                @"{
    ""compilationOptions"": { ""languageVersion"" : ""CSharp3"" }
}",
                "foo",
                @"c\foo\project.json");

            var settings = project.GetCompilationSettings("net45");

            Assert.Equal(LanguageVersion.CSharp3, settings.LanguageVersion);
        }
Esempio n. 21
0
        public void GetCompilerOptionsIgnoresTargetFrameworkAndConfigurationIfNull()
        {
            // Arrange
            var project = ProjectUtilities.GetProject(_projectContent, "TestProj", "project.json");

            // Act
            var options = project.GetCompilerOptions(targetFramework: null, configurationName: null);

            // Assert
            Assert.Equal(new[] { "GLOBAL" }, options.Defines);
            Assert.Equal(true, options.WarningsAsErrors);
            Assert.Null(options.AllowUnsafe);
            Assert.Null(options.Platform);
        }
Esempio n. 22
0
        public void CommonStringPropertiesAreSet(string jsonPropertyName, string objectPropertyName)
        {
            var propertyInfo = typeof(Project).GetTypeInfo().GetDeclaredProperty(objectPropertyName);

            Assert.NotNull(propertyInfo);

            var expectValue    = string.Format("this is a fake {0} at {1}", jsonPropertyName, DateTime.Now.Ticks);
            var projectContent = string.Format("{{ \"{0}\": \"{1}\" }}", jsonPropertyName, expectValue);
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            var propertyValue = (string)propertyInfo.GetValue(project);

            Assert.Equal(expectValue, propertyValue);
        }
Esempio n. 23
0
        public void CommandsAreSet()
        {
            var project = ProjectUtilities.GetProject(@"
{
    ""commands"": { ""web"": ""Microsoft.AspNet.Hosting something"" }
}",
                                                      "foo",
                                                      @"c:\foo\project.json");

            Assert.Equal(1, project.Commands.Count);
            Assert.True(project.Commands.ContainsKey("web"));
            Assert.Equal("Microsoft.AspNet.Hosting something", project.Commands["web"]);
            Assert.True(project.Commands.ContainsKey("Web"));
        }
Esempio n. 24
0
        public void GetCompilerOptionsGeneratesTFMDefineForShortName(string tfm, string define)
        {
            // Arrange
            var projectContent  = @"{ ""frameworks"": { """ + tfm + @""": {} } }";
            var project         = ProjectUtilities.GetProject(projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName(tfm);

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: "Debug");

            // Assert
            var expectedDefines = define == null ? new[] { "DEBUG", "TRACE" } : new[] { "DEBUG", "TRACE", define };

            Assert.Equal(expectedDefines, options.Defines);
        }
Esempio n. 25
0
        public void GetCompilerOptionsCombinesConfigurationAndTargetFrameworkfNotNull()
        {
            // Arrange
            var project         = ProjectUtilities.GetProject(_projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName("dnxcore50");

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: "Debug");

            // Assert
            Assert.Equal(new[] { "GLOBAL", "TEST_DEBUG", "XYZ", "TEST_ASPNETCORE", "DNXCORE50" }, options.Defines);
            Assert.Equal(true, options.WarningsAsErrors);
            Assert.Equal(true, options.AllowUnsafe);
            Assert.Equal("x86", options.Platform);
        }
Esempio n. 26
0
        public void CommandsSetIsSet()
        {
            var projectContent = @"
{
    ""commands"": {
        ""cmd1"": ""cmd1value"",
        ""cmd2"": ""cmd2value"",
        ""cmd3"": ""cmd3value""
    }
}";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.NotNull(project.Commands);
            Assert.Equal(3, project.Commands.Count);
        }
Esempio n. 27
0
        public void TagsAreSet()
        {
            var project = ProjectUtilities.GetProject(@"
{
    ""tags"": [""awesome"", ""fantastic"", ""aspnet""]
}",
                                                      "foo",
                                                      @"c:\foo\project.json");
            var tags = new ReadOnlyHashSet <string>(project.Tags);

            Assert.Equal(3, tags.Count);
            Assert.True(tags.Contains("awesome"));
            Assert.True(tags.Contains("fantastic"));
            Assert.True(tags.Contains("aspnet"));
        }
Esempio n. 28
0
        public void GetCompilerOptionsCombinesTargetFrameworkIfNotNull()
        {
            // Arrange
            var project         = ProjectUtilities.GetProject(_projectContent, "TestProj", "project.json");
            var targetFramework = FrameworkNameHelper.ParseFrameworkName("dnx451");

            // Act
            var options = project.GetCompilerOptions(targetFramework, configurationName: null);

            // Assert
            Assert.Equal(new[] { "GLOBAL", "TEST_DNX451", "DNX451" }, options.Defines);
            Assert.Equal(true, options.WarningsAsErrors);
            Assert.Null(options.AllowUnsafe);
            Assert.Equal("x86", options.Platform);
        }
Esempio n. 29
0
        public void DefaultDefines(string shortName, string define)
        {
            var project = ProjectUtilities.GetProject(
                @"{

}",
                "foo",
                @"c\foo\project.json");

            var settings = project.GetCompilationSettings(shortName);

            Assert.NotNull(settings);
            Assert.NotNull(settings.Defines);
            Assert.Equal(define.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                         settings.Defines);
        }
Esempio n. 30
0
        public void CompilerServicesValuesAreSet()
        {
            var projectContent = @"
{
    ""compiler"": {
        ""name"": ""Zulu#"",
        ""compilerAssembly"": ""Zulu.Compiler.dll"",
        ""compilerType"": ""Zulu.Compilation.Compiler""
    }
}";
            var project        = ProjectUtilities.GetProject(projectContent, @"foo", @"C:\Foo\Project.json");

            Assert.NotNull(project.CompilerServices);
            Assert.Equal("Zulu#", project.CompilerServices.Name);
            Assert.Equal("Zulu.Compiler.dll", project.CompilerServices.ProjectCompiler.AssemblyName);
            Assert.Equal("Zulu.Compilation.Compiler", project.CompilerServices.ProjectCompiler.TypeName);
        }