コード例 #1
0
        public static void ParseFileContent_ReturnsExpectedResult()
        {
            var content = Helpers.ReadResourceFile("AssemblyInfo.cs.txt");

            var result = AssemblyInfoParser.ParseFileContent(content).ToArray();

            Assert.That(result, Is.Not.Null);

            Assert.Multiple(
                () =>
            {
                Assert.That(result.Length, Is.EqualTo(7));

                Assert.That(
                    result.FirstOrDefault(
                        x => x.Key.Equals(
                            "System.Reflection.AssemblyFileVersionAttribute",
                            StringComparison.CurrentCultureIgnoreCase))
                    .Value,
                    Is.EqualTo("1.2.3.4"));
                Assert.That(
                    result.FirstOrDefault(
                        x => x.Key.Equals(
                            "System.Reflection.AssemblyVersionAttribute",
                            StringComparison.CurrentCultureIgnoreCase))
                    .Value,
                    Is.EqualTo("4.3.2.1"));
            }
                );
        }
コード例 #2
0
        public AssemblyInfoParseResult Parse()
        {
            if (CreateAssemblyInfo && Path != null)
            {
                CreateAssemblyInfoOnDisk(Path);
            }
            var parser = new AssemblyInfoParser(FileSystem, Environment);

            return(parser.Parse(Path));
        }
コード例 #3
0
        public void DeserializeTest()
        {
            var parser       = new AssemblyInfoParser();
            var properties   = parser.ReadProperties(InputText);
            var deserializer = new AssemblyInfoDeserializer <AssemblyInfo>();
            var info         = deserializer.Deserialize(properties);

            Assert.AreEqual("AssemblyInfoCmdlet", info.AssemblyTitle);
            Assert.AreEqual("", info.AssemblyDescription);
            Assert.AreEqual("", info.AssemblyConfiguration);
            Assert.AreEqual("", info.AssemblyCompany);
            Assert.AreEqual("AssemblyInfoCmdlet", info.AssemblyProduct);
            Assert.AreEqual("Copyright ©  2016", info.AssemblyCopyright);
            Assert.AreEqual("", info.AssemblyTrademark);
            Assert.AreEqual("", info.AssemblyCulture);
            Assert.AreEqual(false, info.ComVisible);
            Assert.AreEqual(Guid.Parse("601ad923-baa2-4eef-9f24-bc655a24bd6c"), info.Guid);
            Assert.AreEqual("1.0.0.0", info.AssemblyVersion);
            Assert.AreEqual("1.0.0.0", info.AssemblyFileVersion);
        }
コード例 #4
0
        public void PatchAllAssemblyInfo(VersionResult versionInfo, string copyrightText)
        {
            var parser        = new AssemblyInfoParser(_fileSystem, _environment);
            var creator       = new AssemblyInfoCreator(_fileSystem, _environment, _log);
            var assemblyFiles = _globber.GetFiles("./**/AssemblyInfo.cs");

            foreach (var file in assemblyFiles)
            {
                _log.Verbose($"Possibly file to patch:{file}");
                if (file.ToString().Contains("packages/"))
                {
                    continue;
                }
                var assemblyInfo = parser.Parse(file);

                string rootVersion = versionInfo.RootVersion;
                //on AppVeyor, if it is a PullRequest and "pull_requests: do_not_increment_build_number" is true, it will make up a build like 1.0.2-fisiek
                //It does this because it requires unique version numbers.
                //So, what is in RootVersion has this 'prerelease' tag of 'fisiek' or whatever on it.  This is not valid when versioning assembiles!
                //we of course are not going to publish prereleases to nuget, so just make up any version for this.

                //if do_not_increment_build_number is false, then the version does NOT contain the extra tag and it does not matter.
                //of course we do not know if this is true or false.  So we will just look...
                if (IsPullRequest && rootVersion.Contains("-"))
                {
                    rootVersion = "1.0.1";
                }

                _log.Information($"Creating File Version:{rootVersion} Info Version:{versionInfo.FullVersion} for {file} ");

                creator.Create(file, new AssemblyInfoSettings
                {
                    Product              = assemblyInfo.Product,
                    Version              = rootVersion,
                    FileVersion          = rootVersion,
                    InformationalVersion = versionInfo.FullVersion,
                    Copyright            = string.Format(copyrightText, DateTime.Now.Year)
                });
            }
        }
コード例 #5
0
        private void ProcessAssemblyInfo(Project projectMetadata, SourceInformation projectDirectory)
        {
            _logger.Trace("Entering");

            var propertiesInfo = Tools.GetChildDirectoryInformation(
                new SourceInformation(projectDirectory),
                "properties");
            // ReSharper disable once StringLiteralTypo
            var assemblyInfo = Tools.GetChildFileInformation(propertiesInfo, "assemblyinfo.cs");

            var sourceTool = GetSourceTool();

            var sw      = Stopwatch.StartNew();
            var content = sourceTool.GetItemContent(assemblyInfo);

            sw.Stop();
            _logger.Trace($"GetItemContent took {sw.Elapsed}");

            if (content != null)
            {
                projectMetadata.AssemblyInformation = AssemblyInfoParser.ParseFileContent(content).ToList();
            }
        }
コード例 #6
0
        public AssemblyInfoParseResult Parse(FilePath filePath)
        {
            var parser = new AssemblyInfoParser(FileSystem, Environment);

            return(parser.Parse(filePath));
        }
コード例 #7
0
        public void ParseTest()
        {
            var parser           = new AssemblyInfoParser();
            var actualProperties = parser.ReadProperties(InputText);

            Assert.IsNotNull(actualProperties);
            Assert.AreEqual(12, actualProperties.Length);

            var expectedProperties = new Dictionary <string, PropertyValue[]> {
                ["AssemblyTitle"] = new PropertyValue[] { new PropertyValue {
                                                              Type = PropertyValueType.String, Value = "AssemblyInfoCmdlet"
                                                          } },
                ["AssemblyDescription"] = new PropertyValue[] { new PropertyValue {
                                                                    Type = PropertyValueType.String, Value = ""
                                                                } },
                ["AssemblyConfiguration"] = new PropertyValue[] { new PropertyValue {
                                                                      Type = PropertyValueType.String, Value = ""
                                                                  } },
                ["AssemblyCompany"] = new PropertyValue[] { new PropertyValue {
                                                                Type = PropertyValueType.String, Value = ""
                                                            } },
                ["AssemblyProduct"] = new PropertyValue[] { new PropertyValue {
                                                                Type = PropertyValueType.String, Value = "AssemblyInfoCmdlet"
                                                            } },
                ["AssemblyCopyright"] = new PropertyValue[] { new PropertyValue {
                                                                  Type = PropertyValueType.String, Value = "Copyright ©  2016"
                                                              } },
                ["AssemblyTrademark"] = new PropertyValue[] { new PropertyValue {
                                                                  Type = PropertyValueType.String, Value = ""
                                                              } },
                ["AssemblyCulture"] = new PropertyValue[] { new PropertyValue {
                                                                Type = PropertyValueType.String, Value = ""
                                                            } },
                ["ComVisible"] = new PropertyValue[] { new PropertyValue {
                                                           Type = PropertyValueType.Unknown, Value = "false"
                                                       } },
                ["Guid"] = new PropertyValue[] { new PropertyValue {
                                                     Type = PropertyValueType.String, Value = "601ad923-baa2-4eef-9f24-bc655a24bd6c"
                                                 } },
                ["AssemblyVersion"] = new PropertyValue[] { new PropertyValue {
                                                                Type = PropertyValueType.String, Value = "1.0.0.0"
                                                            } },
                ["AssemblyFileVersion"] = new PropertyValue[] { new PropertyValue {
                                                                    Type = PropertyValueType.String, Value = "1.0.0.0"
                                                                } },
            };

            Assert.IsTrue(Enumerable.SequenceEqual(
                              expectedProperties.Keys.OrderBy(x => x),
                              actualProperties.Select(x => x.Name).OrderBy(x => x)));
            foreach (var property in actualProperties)
            {
                var expectedValues = expectedProperties[property.Name];
                var actualValues   = property.Values;
                Assert.IsNotNull(expectedValues);
                Assert.IsNotNull(actualValues);
                Assert.AreEqual(expectedValues.Length, actualValues.Length);

                Assert.IsTrue(Enumerable.SequenceEqual(
                                  expectedValues.Select(x => x.Type),
                                  actualValues.Select(x => x.Type)));

                Assert.IsTrue(Enumerable.SequenceEqual(
                                  expectedValues.Select(x => x.Value),
                                  actualValues.Select(x => x.Value)),
                              string.Format("Expected: {0}, Actual: {1}",
                                            string.Join(", ", expectedValues.Select(x => x.Value)),
                                            string.Join(", ", actualValues.Select(x => x.Value)))
                              );
            }
        }
コード例 #8
0
 public static void ParseFileContent_Throws(string input)
 {
     Assert.Throws <ArgumentException>(() => AssemblyInfoParser.ParseFileContent(input));
 }