public void ReplaceAssemblyInfoPropertiesTests_WhenChangingAllPropertiesInWorkflowShouldUpdateAssemblyInfoWithSameValues() { const string searchPatternShell = @"[\[<]+.*{0}.*\(\x22{1}\x22\)[\]>]+"; string[] filePaths = new[] { "ReplaceTestAssemblyInfo.cs", "ReplaceTestAssemblyInfo.vb", "ReplaceTestAssemblyInfo.cpp", "ReplaceTestAssemblyInfo.fs" }; const bool forceCreate = true; IList<Tuple<string, string>> assemblyProperties = new ReadOnlyCollectionBuilder<Tuple<string, string>> { new Tuple<string, string>("AssemblyTitle", "Assembly Title"), new Tuple<string, string>("AssemblyDescription", "Assembly Description"), new Tuple<string, string>("AssemblyConfiguration", "Assembly Configuration"), new Tuple<string, string>("AssemblyCompany", "Assembly Company"), new Tuple<string, string>("AssemblyProduct", "Assembly Product"), new Tuple<string, string>("AssemblyCopyright", "Assembly Copyright"), new Tuple<string, string>("AssemblyTrademark", "Assembly Trademark"), new Tuple<string, string>("AssemblyCulture", "Assembly Culture"), new Tuple<string, string>("AssemblyInformationalVersion", "Assembly Informational Version"), }; foreach (var file in filePaths) { // Create an instance of our test workflow var workflow = new Tests.TestReplaceAssemblyInfoPropertiesWorkflow(); // Create the workflow run-time environment var workflowInvoker = new WorkflowInvoker(workflow); var testFilename = string.Format("AllPropertiesTestAssemblyInfo{0}", Path.GetExtension(file)); File.Copy(file, testFilename); var extension = " " + Path.GetExtension(testFilename).Remove(0, 1); // Set the workflow arguments workflow.FilePath = testFilename; workflow.ForceCreate = forceCreate; workflow.BuildDate = DateTime.Now; workflow.AssemblyTitleReplacementPattern = assemblyProperties[0].Item2 + extension; workflow.AssemblyDescriptionReplacementPattern = assemblyProperties[1].Item2 + extension; workflow.AssemblyConfigurationReplacementPattern = assemblyProperties[2].Item2 + extension; workflow.AssemblyCompanyReplacementPattern = assemblyProperties[3].Item2 + extension; workflow.AssemblyProductReplacementPattern = assemblyProperties[4].Item2 + extension; workflow.AssemblyCopyrightReplacementPattern = assemblyProperties[5].Item2 + extension; workflow.AssemblyTrademarkReplacementPattern = assemblyProperties[6].Item2 + extension; workflow.AssemblyCultureReplacementPattern = assemblyProperties[7].Item2 + extension; workflow.AssemblyInformationalVersionReplacementPattern = assemblyProperties[8].Item2 + extension; workflow.BuildDetail = new InArgument<IBuildDetail>(env => new BuildDetailStub(99)); // Invoke the workflow and capture the outputs workflowInvoker.Invoke(); // Verify using RegEx var fileData = File.ReadAllText(testFilename); foreach (var propertyTuple in assemblyProperties) { var regexPattern = string.Format(searchPatternShell, propertyTuple.Item1, propertyTuple.Item2 + extension); var regex = new Regex(regexPattern); Assert.IsTrue(regex.IsMatch(fileData), string.Format("Test Failed: File: {0} - Property: {1} - Value: {2}", testFilename, propertyTuple.Item1, propertyTuple.Item2 + extension)); } } }
public void ReplaceAssemblyInfoPropertiesTests_WhenWorkingWithFsFileShouldRealignOrInsertDoStatementAtEnd() { string[] filePaths = new[] { "ReplaceTestAssemblyInfo.cs", "ReplaceTestAssemblyInfo.vb", "ReplaceTestAssemblyInfo.cpp", "ReplaceTestAssemblyInfo.fs" }; foreach (var file in filePaths) { // Create an instance of our test workflow var workflow = new Tests.TestReplaceAssemblyInfoPropertiesWorkflow(); ProjectTypes projectType = VersioningHelper.GetProjectTypeFromFileName(file); // Create the workflow run-time environment var workflowInvoker = new WorkflowInvoker(workflow); var testFilename = string.Format("TestingDoInclusionAssemblyInfo{0}", Path.GetExtension(file)); File.Copy(file, testFilename); // Set the workflow arguments workflow.FilePath = testFilename; workflow.ForceCreate = true; workflow.BuildDate = DateTime.Now; workflow.AssemblyTitleReplacementPattern = string.Empty; workflow.AssemblyDescriptionReplacementPattern = string.Empty; workflow.AssemblyConfigurationReplacementPattern = string.Empty; workflow.AssemblyCompanyReplacementPattern = string.Empty; workflow.AssemblyProductReplacementPattern = string.Empty; workflow.AssemblyCopyrightReplacementPattern = string.Empty; workflow.AssemblyTrademarkReplacementPattern = string.Empty; workflow.AssemblyCultureReplacementPattern = string.Empty; workflow.AssemblyInformationalVersionReplacementPattern = "$TPROJ : $REQBY : $BNAME : $UTIME : $LDATE : $LTIME : $SDATE : $STIME : $BNUM : $YYYY : $YY : $MM : $M : $DD : $D : $J : $B"; workflow.BuildDetail = new InArgument<IBuildDetail>(env => new BuildDetailStub(99)); // Invoke the workflow and capture the outputs workflowInvoker.Invoke(); // Verify using RegEx var fileData = File.ReadAllText(testFilename); var regex = new Regex(@".*(\(\s*\)|do\s*\(\s*\))"); if (projectType == ProjectTypes.Fs) { Assert.IsTrue(regex.IsMatch(fileData)); } else { Assert.IsFalse(regex.IsMatch(fileData)); } } }