Example #1
0
    public void VerifyCreatedCode_NoNamespaceConflict()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();

        var config = new TestEffectiveConfiguration();

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake.System");

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.System.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    public void VerifyCreatedCode_NoNamespaceConflict()
    {
        var semanticVersion = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();

        var config = new TestEffectiveConfiguration();

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake.System");
        assemblyInfoText.ShouldMatchApproved();

        var compilation = CSharpCompilation.Create("Fake.System.dll")
            .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
            .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
            .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());
        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    public void VerifyCreatedCode()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder
        {
            CachedVersion = new CachedVersion
            {
                SemanticVersion   = semanticVersion,
                MasterReleaseDate = DateTimeOffset.Parse("2014-03-01 00:00:01Z"),
            }
        };
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText();

        Approvals.Verify(assemblyInfoText);
        var syntaxTree  = SyntaxTree.ParseText(assemblyInfoText);
        var references  = new[] { new MetadataFileReference(typeof(object).Assembly.Location) };
        var compilation = Compilation.Create("Greeter.dll", new CompilationOptions(OutputKind.NetModule), new[] { syntaxTree }, references);
        var emitResult  = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Info)));
    }
Example #4
0
        public IEnumerable <AssemblyInfo> Schedule(string assemblyPath, bool force = false)
        {
            var typeInfoList     = GetTypeInfoList(assemblyPath);
            var assemblyInfoList = new List <AssemblyInfo>();
            var chunkList        = new List <Chunk>();

            AssemblyInfoBuilder.Build(assemblyPath, _methodLimit, _options.UseHtml, typeInfoList, out chunkList, out assemblyInfoList);

            // If the scheduling didn't actually produce multiple chunks then send back an unchunked
            // representation.
            if (assemblyInfoList.Count == 1 && !force)
            {
                Logger.Log($"Assembly schedule produced a single chunk {assemblyPath}");
                return(new[] { CreateAssemblyInfo(assemblyPath) });
            }

            Logger.Log($"Assembly Schedule: {Path.GetFileName(assemblyPath)}");
            foreach (var chunk in chunkList)
            {
                var methodCount = chunk.TypeInfoList.Sum(x => x.MethodCount);
                var delta       = methodCount - _methodLimit;
                Logger.Log($"  Chunk: {chunk.Id} method count {methodCount} delta {delta}");
                foreach (var typeInfo in chunk.TypeInfoList)
                {
                    Logger.Log($"    {typeInfo.FullName} {typeInfo.MethodCount}");
                }
            }

            return(assemblyInfoList);
        }
 public void VerifyCreatedCode()
 {
     var semanticVersion = new SemanticVersion
     {
         Major = 1,
         Minor = 2,
         Patch = 3,
         PreReleaseTag = "unstable4",
         BuildMetaData = new SemanticVersionBuildMetaData(5,
             "feature1",
             new ReleaseDate
             {
                 OriginalCommitSha = "originalCommitSha",
                 OriginalDate = DateTimeOffset.Parse("2014-03-01 00:00:01Z"),
                 CommitSha = "commitSha",
                 Date = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
             })
     };
     var assemblyInfoBuilder = new AssemblyInfoBuilder
         {
             SemanticVersion = semanticVersion
         };
     var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText();
     Approvals.Verify(assemblyInfoText);
     var syntaxTree = SyntaxTree.ParseText(assemblyInfoText);
     var references = new[] {new MetadataFileReference(typeof(object).Assembly.Location), };
     var compilation = Compilation.Create("Greeter.dll", new CompilationOptions(OutputKind.NetModule), new[] { syntaxTree }, references);
     var emitResult = compilation.Emit(new MemoryStream());
     Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Info)));
 }
Example #6
0
        public IEnumerable <AssemblyInfo> Schedule(string assemblyPath, bool force = false)
        {
            if (_options.Sequential)
            {
                return(new[] { CreateAssemblyInfo(assemblyPath) });
            }

            var typeInfoList     = GetTypeInfoList(assemblyPath);
            var assemblyInfoList = new List <AssemblyInfo>();
            var partitionList    = new List <Partition>();

            AssemblyInfoBuilder.Build(assemblyPath, _methodLimit, _options.IncludeHtml, typeInfoList, out partitionList, out assemblyInfoList);

            // If the scheduling didn't actually produce multiple partition then send back an unpartitioned
            // representation.
            if (assemblyInfoList.Count == 1 && !force)
            {
                Logger.Log($"Assembly schedule produced a single partition {assemblyPath}");
                return(new[] { CreateAssemblyInfo(assemblyPath) });
            }

            Logger.Log($"Assembly Schedule: {Path.GetFileName(assemblyPath)}");
            foreach (var partition in partitionList)
            {
                var methodCount = partition.TypeInfoList.Sum(x => x.MethodCount);
                var delta       = methodCount - _methodLimit;
                Logger.Log($"  Partition: {partition.Id} method count {methodCount} delta {delta}");
                foreach (var typeInfo in partition.TypeInfoList)
                {
                    Logger.Log($"    {typeInfo.FullName} {typeInfo.MethodCount}");
                }
            }

            return(assemblyInfoList);
        }
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 2,
            Minor         = 3,
            Patch         = 4,
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "master",
                                                             new ReleaseDate
            {
                OriginalCommitSha = "originalCommitSha",
                OriginalDate      = DateTimeOffset.Parse("2014-03-01 00:00:01Z"),
                CommitSha         = "commitSha",
                Date = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
            }),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder
        {
            SemanticVersion          = semanticVersion,
            AssemblyVersioningScheme = avs,
        };

        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText();

        Approvals.Verify(assemblyInfoText);
        var syntaxTree  = SyntaxTree.ParseText(assemblyInfoText);
        var references  = new[] { new MetadataFileReference(typeof(object).Assembly.Location), };
        var compilation = Compilation.Create("Greeter.dll", new CompilationOptions(OutputKind.NetModule), new[] { syntaxTree }, references);
        var emitResult  = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Info)));
    }
    public void VerifyCreatedCode()
    {
        var semanticVersion = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder
        {
            CachedVersion = new CachedVersion
            {
                SemanticVersion = semanticVersion
            }
        };
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(new TestEffectiveConfiguration());
        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
            .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
            .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
            .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());
        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    public void VerifyCreatedCode()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();
        var versionVariables    = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
        var assemblyInfoText    = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables);

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));


        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
Example #10
0
        public ImmutableArray <PartitionInfo> Schedule(string assemblyPath, bool force = false)
        {
            if (_options.Sequential)
            {
                return(ImmutableArray.Create(new PartitionInfo(assemblyPath)));
            }

            var typeInfoList = GetTypeInfoList(assemblyPath);

            AssemblyInfoBuilder.Build(assemblyPath, _methodLimit, typeInfoList, out var partitionList);

            // If the scheduling didn't actually produce multiple partition then send back an unpartitioned
            // representation.
            if (partitionList.Length == 1 && !force)
            {
                Logger.Log($"Assembly schedule produced a single partition {assemblyPath}");
                return(ImmutableArray.Create(new PartitionInfo(assemblyPath)));
            }

            Logger.Log($"Assembly Schedule: {Path.GetFileName(assemblyPath)}");
            foreach (var partition in partitionList)
            {
                var methodCount = partition.TypeInfoList.Sum(x => x.MethodCount);
                var delta       = methodCount - _methodLimit;
                Logger.Log($"  Partition: {partition.AssemblyPartitionId} method count {methodCount} delta {delta}");
                foreach (var typeInfo in partition.TypeInfoList)
                {
                    Logger.Log($"    {typeInfo.FullName} {typeInfo.MethodCount}");
                }
            }

            return(partitionList);
        }
Example #11
0
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs, string assemblyInformationalFormat = null)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 2,
            Minor         = 3,
            Patch         = 4,
            PreReleaseTag = "beta.5",
            BuildMetaData = new SemanticVersionBuildMetaData(6,
                                                             "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();


        var config = new TestEffectiveConfiguration(assemblyVersioningScheme: avs, assemblyInformationalFormat: assemblyInformationalFormat);

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake");

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    public void GetAssemblyInfoBuilder_Empty_ThrowsWarningException()
    {
        var taskItems = Substitute.For <IEnumerable <ITaskItem> >();
        var exception = Assert.Throws <GitTools.WarningException>(() => AssemblyInfoBuilder.GetAssemblyInfoBuilder(taskItems));

        exception.Message.ShouldBe("Unable to determine which AssemblyBuilder required to generate GitVersion assembly information");
    }
Example #13
0
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 2,
            Minor         = 3,
            Patch         = 4,
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder
        {
            CachedVersion = new CachedVersion
            {
                SemanticVersion   = semanticVersion,
                MasterReleaseDate = DateTimeOffset.Parse("2014-03-01 00:00:01Z")
            },
        };

        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(new Config {
            AssemblyVersioningScheme = avs
        });

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    public void VerifyCreatedCode()
    {
        var semanticVersion = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();
        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake");
        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
            .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
            .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
            .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        using (var stream = new MemoryStream())
        {
            var emitResult = compilation.Emit(stream);

            Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));

            stream.Seek(0, SeekOrigin.Begin);
            var assembly = Assembly.Load(stream.ToArray());
            VerifyGitVersionInformationAttribute(assembly, versionVariables);
        }
    }
Example #15
0
            internal static void Build(string assemblyPath, int methodLimit, bool useHtml, List <TypeInfo> typeInfoList, out List <Chunk> chunkList, out List <AssemblyInfo> assemblyInfoList)
            {
                var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit, useHtml);

                builder.Build(typeInfoList);
                chunkList        = builder._chunkList;
                assemblyInfoList = builder._assemblyInfoList;
            }
        public void WithAssemblyInformationalVersion_WithVersion_BuildsCorrectAssemblyInfo()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder.WithAssemblyInformationalVersion("4.3.2.1 Beta 4");
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"4.3.2.1 Beta 4\")]", assemblyInfo);
        }
        public void WithAssemblyInformationalVersion_WithSpecialChars_BuildsCorrectAssemblyInfo()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder.WithAssemblyInformationalVersion("4.3.2.1 code-named \"Maverick\"");
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"4.3.2.1 code-named \\\"Maverick\\\"\")]", assemblyInfo);
        }
Example #18
0
            internal static void Build(string assemblyPath, int methodLimit, List <TypeInfo> typeInfoList, out List <Partition> partitionList, out List <AssemblyPartitionInfo> assemblyInfoList)
            {
                var hasEventListenerGuard = typeInfoList.Any(x => x.FullName == EventListenerGuardFullName);
                var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit, hasEventListenerGuard);

                builder.Build(typeInfoList);
                partitionList    = builder._partitionList;
                assemblyInfoList = builder._assemblyInfoList;
            }
        public void WithAssemblyVersion_CanBeCalledMoreThanOnce()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder
                .WithAssemblyVersion(new Version(4, 3, 2, 1))
                .WithAssemblyVersion(new Version(3, 0, 0, 0));
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.Reflection.AssemblyVersionAttribute(\"3.0.0.0\")]", assemblyInfo);
        }
        public void WithAssemblyInformationalVersion_CanBeCalledMoreThanOnce()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder
                .WithAssemblyInformationalVersion("4.3.2.1 code-named \"Maverick\"")
                .WithAssemblyInformationalVersion("3.0 code-named \"Maverick\"");
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"3.0 code-named \\\"Maverick\\\"\")]", assemblyInfo);
        }
    public void GetAssemblyInfoBuilder_ShouldReturnAppropriateAssemblyInfoBuilder(string fileName, Type assemblyInfoBuilderType)
    {
        var taskItem = Substitute.For <ITaskItem>();

        taskItem.ItemSpec.Returns(fileName);

        var assemblyInfoBuilder = AssemblyInfoBuilder.GetAssemblyInfoBuilder(new[] { taskItem });

        assemblyInfoBuilder.ShouldNotBeNull();
        assemblyInfoBuilder.ShouldBeOfType(assemblyInfoBuilderType);
    }
Example #22
0
        public IEnumerable <AssemblyPartitionInfo> Schedule(string assemblyPath, bool force = false)
        {
            var typeInfoList     = GetTypeInfoList(assemblyPath);
            var assemblyInfoList = new List <AssemblyPartitionInfo>();
            var partitionList    = new List <Partition>();

            AssemblyInfoBuilder.Build(assemblyPath, _methodLimit, typeInfoList, out partitionList, out assemblyInfoList);

            // If the scheduling didn't actually produce multiple partition then send back an unpartitioned
            // representation.
            if (assemblyInfoList.Count == 1 && !force)
            {
                // Logger.Log($"Assembly schedule produced a single partition {assemblyPath}");
                return(new[] { CreateAssemblyInfo(assemblyPath) });
            }

            return(assemblyInfoList);
        }
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs)
    {
        var semanticVersion = new SemanticVersion
        {
            Major = 2,
            Minor = 3,
            Patch = 4,
            PreReleaseTag = "beta.5",
            BuildMetaData = new SemanticVersionBuildMetaData(6,
                "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();
        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, avs, VersioningMode.ContinuousDelivery, "ci", false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables);
        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
        .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
        .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
        .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());
        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs)
    {
        var semanticVersion = new SemanticVersion
        {
            Major = 2,
            Minor = 3,
            Patch = 4,
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                "master","commitSha",DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder
        {
            CachedVersion = new CachedVersion
            {
                SemanticVersion = semanticVersion,
                MasterReleaseDate = DateTimeOffset.Parse("2014-03-01 00:00:01Z")
            },
        };

        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(new Config { AssemblyVersioningScheme = avs });
        Approvals.Verify(assemblyInfoText);
        var syntaxTree = SyntaxTree.ParseText(assemblyInfoText);
        var references = new[] { new MetadataFileReference(typeof(object).Assembly.Location)};
        var compilation = Compilation.Create("Greeter.dll", new CompilationOptions(OutputKind.NetModule), new[] { syntaxTree }, references);
        var emitResult = compilation.Emit(new MemoryStream());
        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Info)));
    }
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns>
        /// <see langword="true"/> if the task was executed successfully; otherwise, <see langword="false"/>.
        /// </returns>
        public override bool Execute()
        {
            CodeDomProvider provider = CodeDomProvider.CreateProvider(Language);
            AssemblyInfoBuilder generator = new AssemblyInfoBuilder(CodeDomProvider.CreateProvider(Language));

            if (CLSCompliant)
            {
                Log.LogMessage("Adding CLSCompliantAttribute.");
                generator.WithCLSCompliant(true);
            }

            if (!string.IsNullOrWhiteSpace(AssemblyVersion))
            {
                Log.LogMessage("Adding AssemblyVersionAttribute ({0}).", AssemblyVersion);
                generator.WithAssemblyVersion(new Version(AssemblyVersion));
            }

            if (!string.IsNullOrWhiteSpace(AssemblyFileVersion))
            {
                Log.LogMessage("Adding AssemblyFileVersionAttribute ({0}).", AssemblyFileVersion);
                generator.WithAssemblyFileVersion(new Version(AssemblyFileVersion));
            }

            if (!string.IsNullOrWhiteSpace(AssemblyInformationalVersion))
            {
                Log.LogMessage("Adding AssemblyInformationalVersionAttribute ({0}).", AssemblyInformationalVersion);
                generator.WithAssemblyInformationalVersion(AssemblyInformationalVersion);
            }

            generator.Save(FileName);
            Log.LogMessage("AssemblyInfo file saved to '{0}'.", FileName);

            return true;
        }
    public void GetAssemblyInfoBuilder_Null_ThrowsArgumentNullException()
    {
        var exception = Assert.Throws <ArgumentNullException>(() => AssemblyInfoBuilder.GetAssemblyInfoBuilder(null));

        exception.ParamName.ShouldBe("compileFiles");
    }
Example #27
0
 internal static void Build(string assemblyPath, int methodLimit, bool useHtml, List<TypeInfo> typeInfoList, out List<Chunk> chunkList, out List<AssemblyInfo> assemblyInfoList)
 {
     var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit, useHtml);
     builder.Build(typeInfoList);
     chunkList = builder._chunkList;
     assemblyInfoList = builder._assemblyInfoList;
 }
Example #28
0
 internal static void Build(string assemblyPath, int methodLimit, bool useHtml, List<TypeInfo> typeInfoList, out List<Partition> partitionList, out List<AssemblyInfo> assemblyInfoList)
 {
     var hasEventListenerGuard = typeInfoList.Any(x => x.FullName == EventListenerGuardFullName);
     var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit, useHtml, hasEventListenerGuard);
     builder.Build(typeInfoList);
     partitionList = builder._partitionList;
     assemblyInfoList = builder._assemblyInfoList;
 }
        public void WithCLSCompliant_CanBeCalledMoreThanOnce()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder
                .WithCLSCompliant(true)
                .WithCLSCompliant(false);
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.CLSCompliantAttribute(false)]", assemblyInfo);
        }
        public void WithCLSCompliant_WithTrue_BuildsCorrectAssemblyInfo()
        {
            var builder = new AssemblyInfoBuilder(new CSharpCodeProvider());
            builder.WithCLSCompliant(true);
            var assemblyInfo = builder.Build();

            Assert.Contains("[assembly: System.CLSCompliantAttribute(true)]", assemblyInfo);
        }