public void AssemblyInfo_ThrowsFileNotFoundException_OnUnknownFile()
        {
            // arrange
            File.Copy("AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs", TestFilePrefix + ".vb" } }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);
        }
        public void AssemblyInfo_UpdatesAssemblyTrademark_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyVersion", "$(current).$(current).0.0" },
                { "AssemblyFileVersion", "$(current).$(current).$(increment).0" },
                { "AssemblyTrademark", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyTrademark(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
        }
        public void AssemblyInfo_ThrowsFormatException_OnInvalidToken()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyVersion", "$(invalid).3.0.0" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);
        }
        public void AssemblyInfo_EmptyAssemblyInformationalVersions_WhenExecuteInvokedOnFileWithoutAssemblyInformationalVersion()
        {
            // arrange
            File.Copy(@"AssemblyInfo (4).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyInformationalVersion", "$(fileversion)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var versions = actual["AssemblyInformationalVersions"] as IEnumerable<string>;
            Assert.AreEqual(1, versions.Count());
            Assert.AreEqual(string.Empty, versions.ElementAt(0));
        }
        public void AssemblyInfo_FillAssemblyInformationalVersions_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + "1.cs", true);
            File.Copy(@"AssemblyInfo (3).cs", TestFilePrefix + "2.cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + "1.cs", TestFilePrefix + "2.cs" } },
                { "AssemblyVersion", "$(current).$(current).0.0" },
                { "AssemblyFileVersion", "$(current).$(current).$(increment).0" },
                { "AssemblyInformationalVersion", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var versions = actual["AssemblyInformationalVersions"] as IEnumerable<string>;
            Assert.AreEqual(2, versions.Count());
            Assert.AreEqual(string.Format("Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}", DateTime.Today), versions.ElementAt(0));
            Assert.AreEqual(string.Format("Value 1.1.0.0/1.1.4.0 at {0:yyyyMMdd}", DateTime.Today), versions.ElementAt(1));
        }
        public void AssemblyInfo_ComputesMaxAssemblyInformationalVersion_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (3).cs", TestFilePrefix + "2.cs", true);
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + "1.cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + "1.cs", TestFilePrefix + "2.cs" } },
                { "AssemblyVersion", "$(current).$(current).0.0" },
                { "AssemblyFileVersion", "$(current).$(current).$(increment).0" },
                { "AssemblyInformationalVersion", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            Assert.AreEqual(string.Format("Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}", DateTime.Today), actual["MaxAssemblyInformationalVersion"].ToString());
        }
        public void AssemblyInfo_FillAssemblyFileVersions_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + "1.cs", true);
            File.Copy(@"AssemblyInfo (3).cs", TestFilePrefix + "2.cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + "1.cs", TestFilePrefix + "2.cs" } },
                { "AssemblyFileVersion", "$(current).$(increment).$(current).$(current)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var versions = actual["AssemblyFileVersions"] as IEnumerable<Version>;
            Assert.AreEqual(2, versions.Count());
            Assert.AreEqual("1.3.3.4", versions.ElementAt(0).ToString());
            Assert.AreEqual("1.2.3.4", versions.ElementAt(1).ToString());
        }
        public void AssemblyInfo_UpdatesAssemblyFileVersion_WhenExecuteInvokedWithWildcard2()
        {
            // arrange
            File.Copy(@"AssemblyInfo (6).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyFileVersion", "$(current).$(increment).$(increment).0" },
                { "AssemblyInformationalVersion", "$(fileversion)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyFileVersion(\"2.4.2.*\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyInformationalVersion(\"2.4.2.0\")]", StringComparison.Ordinal));
            Assert.AreEqual("2.4.2.0", actual["MaxAssemblyFileVersion"].ToString());

            var versions = actual["AssemblyFileVersions"] as IEnumerable<Version>;
            Assert.AreEqual(1, versions.Count());
            Assert.AreEqual("2.4.2.0", versions.ElementAt(0).ToString());
        }
        public void AssemblyInfo_UpdatesAssemblyFileVersion_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyFileVersion", "$(current).$(increment).$(date:yyyy).1234" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyFileVersion(\"1.3.{0:yyyy}.1234\")]", DateTime.Today), StringComparison.Ordinal));
        }
        public void AssemblyInfo_ComputesMaxAssemblyFileVersion_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + "1.cs", true);
            File.Copy(@"AssemblyInfo (3).cs", TestFilePrefix + "2.cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + "1.cs", TestFilePrefix + "2.cs" } },
                { "AssemblyFileVersion", "$(current).$(increment).$(current).$(current)" }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            Assert.AreEqual("1.3.3.4", actual["MaxAssemblyFileVersion"].ToString());
        }
        public void AssemblyInfo_NoUpdates_WhenExecuteInvokedWithDefaultValues()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyCompany(\"AssemblyCompanyValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyConfiguration(\"AssemblyConfigurationValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyCopyright(\"AssemblyCopyrightValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyCulture(\"AssemblyCultureValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyDescription(\"AssemblyDescriptionValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyProduct(\"AssemblyProductValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyTitle(\"AssemblyTitleValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyTrademark(\"AssemblyTrademarkValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyDelaySign(true)]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyKeyFile(\"AssemblyKeyFileValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyKeyName(\"AssemblyKeyNameValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyVersion(\"1.2.0.0\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyFileVersion(\"1.2.3.4\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyInformationalVersion(\"AssemblyInformationalVersionValue\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: CLSCompliant(true)]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: Guid(\"B0EAC358-5AB5-45DE-9975-E1D8D8030944\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: ComVisible(true)]", StringComparison.Ordinal));
        }
        public void AssemblyInfo_UpdatesAttributes_WhenExecuteInvokedOnCSharpFileWithLongAttributeNames()
        {
            // arrange
            File.Copy(@"AssemblyInfo (7).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var expectedGuid = System.Guid.NewGuid();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyVersion", "$(current).$(current).0.0" },
                { "AssemblyFileVersion", "$(current).$(current).$(increment).0" },
                { "AssemblyInformationalVersion", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyCompany", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyConfiguration", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyCopyright", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyDescription", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyProduct", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyTitle", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyTrademark", "Value $(version)/$(fileversion) at $(date:yyyyMMdd)" },
                { "AssemblyCulture", "NewCulture" },
                { "AssemblyDelaySign", false },
                { "Guid", expectedGuid },
                { "AssemblyKeyFile", "NewKeyFile" },
                { "AssemblyKeyName", "NewKeyName" },
                { "CLSCompliant", false },
                { "ComVisible", false },
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");

            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyVersionAttribute(\"1.2.0.0\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyFileVersionAttribute(\"1.2.4.0\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyInformationalVersionAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyCompanyAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyConfigurationAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyCopyrightAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyDescriptionAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyProductAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyTitleAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf(string.Format("[assembly: AssemblyTrademarkAttribute(\"Value 1.2.0.0/1.2.4.0 at {0:yyyyMMdd}\")]", DateTime.Today), StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyCultureAttribute(\"NewCulture\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyDelaySignAttribute(false)]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: GuidAttribute(\"" + expectedGuid.ToString() + "\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyKeyFileAttribute(\"NewKeyFile\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: AssemblyKeyNameAttribute(\"NewKeyName\")]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: CLSCompliantAttribute(false)]", StringComparison.Ordinal));
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: ComVisibleAttribute(false)]", StringComparison.Ordinal));
        }
        public void AssemblyInfo_UpdatesComVisible_WhenExecuteInvokedOnFSharpFile()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).fs", TestFilePrefix + ".fs", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".fs" } },
                { "ComVisible", false }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".fs");
            Assert.AreNotEqual(-1, text.IndexOf("[<assembly: ComVisible(false)>]", StringComparison.Ordinal));
        }
        public void AssemblyInfo_UpdatesGuid_WhenExecuteInvoked()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).cs", TestFilePrefix + ".cs", true);

            var target = new AssemblyInfo();
            var expected = System.Guid.NewGuid();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".cs" } },
                { "AssemblyVersion", "$(current).$(current).0.0" },
                { "AssemblyFileVersion", "$(current).$(current).$(increment).0" },
                { "Guid", expected }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".cs");
            Assert.AreNotEqual(-1, text.IndexOf("[assembly: Guid(\"" + expected.ToString() + "\")]", StringComparison.Ordinal));
        }
        public void AssemblyInfo_UpdatesAssemblyDelaySign_WhenExecuteInvokedOnVBFile()
        {
            // arrange
            File.Copy(@"AssemblyInfo (1).vb", TestFilePrefix + ".vb", true);

            var target = new AssemblyInfo();
            var parameters = new Dictionary<string, object>
            {
                { "Files", new[] { TestFilePrefix + ".vb" } },
                { "AssemblyDelaySign", false }
            };

            var invoker = new WorkflowInvoker(target);

            // act
            var actual = invoker.Invoke(parameters);

            // assert
            var text = File.ReadAllText(TestFilePrefix + ".vb");
            Assert.AreNotEqual(-1, text.IndexOf("<Assembly: AssemblyDelaySign(False)>", StringComparison.Ordinal));
        }