Browse Source

Add assembly info writing tests. Add Assembly Flags reading support.

pull/624/head
olegbevz 11 years ago
parent
commit
00b34016c2
  1. 3
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs
  2. 228
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs
  3. 21
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoViewModel.cs
  4. 18
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionToStringConverter.cs
  5. 295
      src/Main/Base/Test/ProjectOptions/AssemblyInfoProviderTests.cs

3
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs

@ -20,6 +20,9 @@ using System; @@ -20,6 +20,9 @@ using System;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
/// <summary>
/// Assembly info parameters model
/// </summary>
public class AssemblyInfo
{
public string Title { get; set; }

228
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs

@ -17,18 +17,53 @@ @@ -17,18 +17,53 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using ICSharpCode.NRefactory.CSharp;
using Attribute = ICSharpCode.NRefactory.CSharp.Attribute;
using CSharpParser = ICSharpCode.NRefactory.CSharp.CSharpParser;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
/// <summary>
/// Class for reading and writing assembly info file
/// </summary>
public class AssemblyInfoProvider
{
public AssemblyInfo Read(Stream stream)
#region Constants
private const string Attribute = "Attribute";
private const string AssemblyTitle = "AssemblyTitle";
private const string AssemblyDescription = "AssemblyDescription";
private const string AssemblyCompany = "AssemblyCompany";
private const string AssemblyProduct = "AssemblyProduct";
private const string AssemblyCopyright = "AssemblyCopyright";
private const string AssemblyTrademark = "AssemblyTrademark";
private const string AssemblyDefaultAlias = "AssemblyDefaultAlias";
private const string AssemblyVersion = "AssemblyVersion";
private const string AssemblyFileVersion = "AssemblyFileVersion";
private const string AssemblyInformationalVersion = "AssemblyInformationalVersion";
private const string Guid = "Guid";
private const string NeutralResourcesLanguage = "NeutralResourcesLanguage";
private const string ComVisible = "ComVisible";
private const string ClsCompliant = "CLSCompliant";
private const string AssemblyFlags = "AssemblyFlags";
#endregion
public AssemblyInfo ReadAssemblyInfo(string assemblyInfoFileName)
{
using (var fileStream = new FileStream(assemblyInfoFileName, FileMode.Open, FileAccess.Read))
{
return ReadAssemblyInfo(fileStream);
}
}
public AssemblyInfo ReadAssemblyInfo(Stream stream)
{
var syntaxTree = ReadSyntaxTree(stream);
@ -48,52 +83,65 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -48,52 +83,65 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
switch (attributeType.Identifier)
{
case "AssemblyTitle":
case AssemblyTitle:
case AssemblyTitle + Attribute:
assemblyInfo.Title = GetAttributeValue<string>(attribute);
break;
case "AssemblyDescription":
case AssemblyDescription:
case AssemblyDescription + Attribute:
assemblyInfo.Description = GetAttributeValue<string>(attribute);
break;
case "AssemblyConfigurtation":
break;
case "AssemblyCompany":
case AssemblyCompany:
case AssemblyCompany + Attribute:
assemblyInfo.Company = GetAttributeValue<string>(attribute);
break;
case "AssemblyProduct":
case AssemblyProduct:
case AssemblyProduct + Attribute:
assemblyInfo.Product = GetAttributeValue<string>(attribute);
break;
case "AssemblyCopyright":
case AssemblyCopyright:
case AssemblyCopyright + Attribute:
assemblyInfo.Copyright = GetAttributeValue<string>(attribute);
break;
case "AssemblyTrademark":
case AssemblyTrademark:
case AssemblyTrademark + Attribute:
assemblyInfo.Trademark = GetAttributeValue<string>(attribute);
break;
case "AssemblyDefaultAlias":
case AssemblyDefaultAlias:
case AssemblyDefaultAlias + Attribute:
assemblyInfo.DefaultAlias = GetAttributeValue<string>(attribute);
break;
case "AssemblyVersion":
case AssemblyVersion:
case AssemblyVersion + Attribute:
assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute);
break;
case "AssemblyFileVersion":
case AssemblyFileVersion:
case AssemblyFileVersion + Attribute:
assemblyInfo.AssemblyFileVersion = GetAttributeValueAsVersion(attribute);
break;
case "AssemblyInformationalVersion":
case AssemblyInformationalVersion:
case AssemblyInformationalVersion + Attribute:
assemblyInfo.InformationalVersion = GetAttributeValueAsVersion(attribute);
break;
case "Guid":
case Guid:
case Guid + Attribute:
assemblyInfo.Guid = GetAttributeValueAsGuid(attribute);
break;
case "NeutralResourcesLanguage":
case NeutralResourcesLanguage:
case NeutralResourcesLanguage + Attribute:
assemblyInfo.NeutralLanguage = GetAttributeValue<string>(attribute);
break;
case "ComVisible":
case ComVisible:
case ComVisible + Attribute:
assemblyInfo.ComVisible = GetAttributeValue<bool>(attribute);
break;
case "CLSCompliant":
case ClsCompliant:
case ClsCompliant + Attribute:
assemblyInfo.ClsCompliant = GetAttributeValue<bool>(attribute);
break;
case "AssemblyFlags":
var assemblyFlags = (AssemblyNameFlags)GetAttributeValue<int>(attribute, (int)AssemblyNameFlags.PublicKey);
case AssemblyFlags:
case AssemblyFlags + Attribute:
var assemblyFlags = GetAssemblyFlagsFromAttribute(attribute);
assemblyInfo.JitOptimization = !assemblyFlags.HasFlag(AssemblyNameFlags.EnableJITcompileOptimizer);
assemblyInfo.JitTracking = assemblyFlags.HasFlag(AssemblyNameFlags.EnableJITcompileTracking);
break;
@ -104,32 +152,40 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -104,32 +152,40 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
return assemblyInfo;
}
public void Write(AssemblyInfo assemblyInfo, string fileName)
public void MergeAssemblyInfo(AssemblyInfo assemblyInfo, string fileName)
{
SyntaxTree syntaxTree;
var content = string.Empty;
using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
syntaxTree = ReadSyntaxTree(fileStream);
content = MergeAssemblyInfo(assemblyInfo, fileStream);
}
if (!string.IsNullOrEmpty(content))
File.WriteAllText(fileName, content);
}
public string MergeAssemblyInfo(AssemblyInfo assemblyInfo, Stream inputStream)
{
var syntaxTree = ReadSyntaxTree(inputStream);
if (syntaxTree == null)
throw new Exception("Can't read assembly info syntax tree.");
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyTitle", assemblyInfo.Title);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyDescription", assemblyInfo.Description);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyCompany", assemblyInfo.Company);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyProduct", assemblyInfo.Product);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyCopyright", assemblyInfo.Copyright);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyTrademark", assemblyInfo.Trademark);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyDefaultAlias", assemblyInfo.DefaultAlias);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyVersion", assemblyInfo.AssemblyVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyFileVersion", assemblyInfo.AssemblyFileVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyInformationalVersion", assemblyInfo.InformationalVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "Guid", assemblyInfo.Guid, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "NeutralResourcesLanguage", assemblyInfo.NeutralLanguage);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "ComVisible", assemblyInfo.ComVisible, false);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "CLSCompliant", assemblyInfo.ClsCompliant, false);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyTitle, assemblyInfo.Title);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyDescription, assemblyInfo.Description);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyCompany, assemblyInfo.Company);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyProduct, assemblyInfo.Product);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyCopyright, assemblyInfo.Copyright);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyTrademark, assemblyInfo.Trademark);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyDefaultAlias, assemblyInfo.DefaultAlias);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyVersion, assemblyInfo.AssemblyVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyFileVersion, assemblyInfo.AssemblyFileVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyInformationalVersion, assemblyInfo.InformationalVersion, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, Guid, assemblyInfo.Guid, null, true);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, NeutralResourcesLanguage, assemblyInfo.NeutralLanguage);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, ComVisible, assemblyInfo.ComVisible, false);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, ClsCompliant, assemblyInfo.ClsCompliant, false);
AssemblyNameFlags assemblyFlags = AssemblyNameFlags.PublicKey;
if (!assemblyInfo.JitOptimization)
@ -137,12 +193,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -137,12 +193,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
if (assemblyInfo.JitTracking)
assemblyFlags = assemblyFlags | AssemblyNameFlags.EnableJITcompileTracking;
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, "AssemblyFlags", (int)assemblyFlags, (int)AssemblyNameFlags.PublicKey);
SetAttributeValueOrAddAttributeIfNotDefault(syntaxTree, AssemblyFlags, (int)assemblyFlags, (int)AssemblyNameFlags.PublicKey);
using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
{
WriteSyntaxTree(syntaxTree, fileStream);
}
return syntaxTree.ToString();
}
private SyntaxTree ReadSyntaxTree(Stream stream)
@ -155,17 +208,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -155,17 +208,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
}
}
private void WriteSyntaxTree(SyntaxTree syntaxTree, Stream stream)
{
var content = syntaxTree.ToString();
using (var streamWriter = new StreamWriter(stream))
{
streamWriter.Write(content);
streamWriter.Flush();
}
}
private T GetAttributeValue<T>(Attribute attribute, T defaultValue = default(T))
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
@ -184,7 +226,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -184,7 +226,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
if (!string.IsNullOrEmpty(guidString))
{
Guid guid;
if (Guid.TryParse(guidString, out guid))
if (System.Guid.TryParse(guidString, out guid))
{
return guid;
}
@ -211,7 +253,75 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -211,7 +253,75 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
return null;
}
private void SetAttributeValueOrAddAttributeIfNotDefault(SyntaxTree syntaxTree, string attributeName, object value, object defaultValue = null, bool transformValueToString = false)
private AssemblyNameFlags GetAssemblyFlagsFromAttribute(Attribute attribute)
{
if (attribute.Arguments.Count == 1)
return GetAssemblyFlagsFromExpression(attribute.Arguments.ElementAt(0));
return AssemblyNameFlags.PublicKey;
}
private AssemblyNameFlags GetAssemblyFlagsFromExpression(Expression expression)
{
if (expression == null)
return AssemblyNameFlags.PublicKey;
var primitiveExpression = expression as PrimitiveExpression;
if (primitiveExpression != null && primitiveExpression.Value is int)
return (AssemblyNameFlags)(int)primitiveExpression.Value;
var memberReferenceExpression = expression as MemberReferenceExpression;
if (memberReferenceExpression != null)
{
AssemblyNameFlags assemblyFlags;
if (Enum.TryParse(memberReferenceExpression.MemberName, out assemblyFlags))
{
return assemblyFlags;
}
}
var binaryExpression = expression as BinaryOperatorExpression;
if (binaryExpression != null && binaryExpression.Operator == BinaryOperatorType.BitwiseOr)
return GetAssemblyFlagsFromExpression(binaryExpression.Left) |
GetAssemblyFlagsFromExpression(binaryExpression.Right);
return AssemblyNameFlags.PublicKey;
}
//private Expression GetAssemblyFlagsExpression(AssemblyNameFlags assemblyFlags)
//{
// var flagNames = new List<string>();
// var flagValues = Enum.
// assemblyFlags.h
//}
private void SetAttributeValueOrAddAttributeIfNotDefault(
SyntaxTree syntaxTree,
string attributeName,
object value,
object defaultValue = null,
bool transformValueToString = false)
{
if (value == null)
return;
var attributeValue = transformValueToString ? value.ToString() : value;
SetAttributeValueOrAddAttributeIfNotDefault(
syntaxTree,
attributeName,
value,
defaultValue,
new PrimitiveExpression(attributeValue));
}
private void SetAttributeValueOrAddAttributeIfNotDefault(
SyntaxTree syntaxTree,
string attributeName,
object value,
object defaultValue,
Expression valueExpression)
{
if (value == null)
return;
@ -219,17 +329,15 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -219,17 +329,15 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
var attribute = syntaxTree.Children.OfType<AttributeSection>().SelectMany(x => x.Attributes)
.FirstOrDefault(x => x.Type is SimpleType && ((SimpleType)x.Type).Identifier == attributeName);
var attributeValue = transformValueToString ? value.ToString() : value;
if (attribute != null)
{
attribute.Arguments.Clear();
attribute.Arguments.Add(new PrimitiveExpression(attributeValue));
attribute.Arguments.Add(valueExpression);
}
else if (value != null && !value.Equals(defaultValue))
else if (!value.Equals(defaultValue))
{
attribute = new Attribute() { Type = new SimpleType(attributeName) };
attribute.Arguments.Add(new PrimitiveExpression(attributeValue));
attribute = new Attribute { Type = new SimpleType(attributeName) };
attribute.Arguments.Add(valueExpression);
var attributeSection = new AttributeSection(attribute) { AttributeTarget = "assembly" };
syntaxTree.AddChild(attributeSection, new NRefactory.Role<AttributeSection>("Member"));

21
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoViewModel.cs

@ -1,3 +1,21 @@ @@ -1,3 +1,21 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Globalization;
@ -8,6 +26,9 @@ using ICSharpCode.SharpDevelop.Widgets; @@ -8,6 +26,9 @@ using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
/// <summary>
/// View model for assembly info
/// </summary>
public class AssemblyInfoViewModel : ViewModelBase
{
private const string NONE_LANGUAGE_CODE = "NONE";

18
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionToStringConverter.cs

@ -1,3 +1,21 @@ @@ -1,3 +1,21 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows;
using System.Windows.Data;

295
src/Main/Base/Test/ProjectOptions/AssemblyInfoProviderTests.cs

@ -24,38 +24,13 @@ using System; @@ -24,38 +24,13 @@ using System;
namespace ICSharpCode.SharpDevelop.ProjectOptions
{
/// <summary>
/// Tests for assembly info reading and writing
/// </summary>
[TestFixture]
public class AssemblyInfoProviderTests
{
[TestCase]
public void ReadEmptyAssemblyInfoTest()
{
var assemblyInfoFile = string.Empty;
var assemblyInfo = ReadAssemblyInfo(assemblyInfoFile);
Assert.IsNull(assemblyInfo.Title);
Assert.IsNull(assemblyInfo.Description);
Assert.IsNull(assemblyInfo.Company);
Assert.IsNull(assemblyInfo.Product);
Assert.IsNull(assemblyInfo.Copyright);
Assert.IsNull(assemblyInfo.Trademark);
Assert.IsNull(assemblyInfo.DefaultAlias);
Assert.IsNull(assemblyInfo.AssemblyVersion);
Assert.IsNull(assemblyInfo.AssemblyFileVersion);
Assert.IsNull(assemblyInfo.InformationalVersion);
Assert.IsNull(assemblyInfo.Guid);
Assert.IsNull(assemblyInfo.NeutralLanguage);
Assert.IsFalse(assemblyInfo.ComVisible);
Assert.IsFalse(assemblyInfo.ClsCompliant);
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
}
[TestCase]
public void ReadNotEmptyAssemblyInfoTest()
{
var assemblyInfoFile =
private const string AssemblyInfoSample1 =
@"using System;
using System.Reflection;
using System.Runtime.InteropServices;
@ -70,7 +45,6 @@ using System.Runtime.InteropServices; @@ -70,7 +45,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright (""Copyright 2014"")]
[assembly: AssemblyTrademark (""Trademark"")]
[assembly: AssemblyDefaultAlias (""Alias"")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible (true)]
@ -88,6 +62,36 @@ using System.Runtime.InteropServices; @@ -88,6 +62,36 @@ using System.Runtime.InteropServices;
[assembly: AssemblyFlags (32769)]
[assembly: CLSCompliant (true)]";
[TestCase]
public void ReadEmptyAssemblyInfoTest()
{
var assemblyInfoFile = string.Empty;
var assemblyInfo = ReadAssemblyInfo(assemblyInfoFile);
Assert.IsNull(assemblyInfo.Title);
Assert.IsNull(assemblyInfo.Description);
Assert.IsNull(assemblyInfo.Company);
Assert.IsNull(assemblyInfo.Product);
Assert.IsNull(assemblyInfo.Copyright);
Assert.IsNull(assemblyInfo.Trademark);
Assert.IsNull(assemblyInfo.DefaultAlias);
Assert.IsNull(assemblyInfo.AssemblyVersion);
Assert.IsNull(assemblyInfo.AssemblyFileVersion);
Assert.IsNull(assemblyInfo.InformationalVersion);
Assert.IsNull(assemblyInfo.Guid);
Assert.IsNull(assemblyInfo.NeutralLanguage);
Assert.IsFalse(assemblyInfo.ComVisible);
Assert.IsFalse(assemblyInfo.ClsCompliant);
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
}
[TestCase]
public void ReadNotEmptyAssemblyInfoTest()
{
var assemblyInfoFile = AssemblyInfoSample1;
var assemblyInfo = ReadAssemblyInfo(assemblyInfoFile);
Assert.AreEqual("SharpDevelop", assemblyInfo.Title);
@ -241,13 +245,236 @@ using System.Runtime.InteropServices; @@ -241,13 +245,236 @@ using System.Runtime.InteropServices;
Assert.IsTrue(assemblyInfo.ClsCompliant);
}
[TestCase]
public void ReadAssemblyInfoWithAttributePostfixTest()
{
var assemblyInfoFile =
@"using System;
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitleAttribute (""SharpDevelop"")]
[assembly: AssemblyDescriptionAttribute (""OpenSource IDE"")]
[assembly: AssemblyCompanyAttribute (""Company"")]
[assembly: AssemblyProductAttribute (""Product"")]
[assembly: AssemblyCopyrightAttribute (""Copyright 2014"")]
[assembly: AssemblyTrademarkAttribute (""Trademark"")]
[assembly: AssemblyDefaultAliasAttribute (""Alias"")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisibleAttribute (true)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersionAttribute (""1.2.3.1"")]
[assembly: AssemblyFileVersionAttribute (""1.2.3.2"")]
[assembly: AssemblyInformationalVersionAttribute (""1.2.3.3"")]
[assembly: GuidAttribute (""0c8c889f-ced2-4167-b155-2d48a99d8c72"")]
[assembly: NeutralResourcesLanguageAttribute (""ru-RU"")]
[assembly: AssemblyFlagsAttribute (32769)]
[assembly: CLSCompliantAttribute (true)]";
var assemblyInfo = ReadAssemblyInfo(assemblyInfoFile);
Assert.AreEqual("SharpDevelop", assemblyInfo.Title);
Assert.AreEqual("OpenSource IDE", assemblyInfo.Description);
Assert.AreEqual("Company", assemblyInfo.Company);
Assert.AreEqual("Product", assemblyInfo.Product);
Assert.AreEqual("Copyright 2014", assemblyInfo.Copyright);
Assert.AreEqual("Trademark", assemblyInfo.Trademark);
Assert.AreEqual("Alias", assemblyInfo.DefaultAlias);
Assert.AreEqual(new Version(1, 2, 3, 1), assemblyInfo.AssemblyVersion);
Assert.AreEqual(new Version(1, 2, 3, 2), assemblyInfo.AssemblyFileVersion);
Assert.AreEqual(new Version(1, 2, 3, 3), assemblyInfo.InformationalVersion);
Assert.AreEqual(new Guid("0c8c889f-ced2-4167-b155-2d48a99d8c72"), assemblyInfo.Guid);
Assert.AreEqual("ru-RU", assemblyInfo.NeutralLanguage);
Assert.IsTrue(assemblyInfo.ComVisible);
Assert.IsTrue(assemblyInfo.ClsCompliant);
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsTrue(assemblyInfo.JitTracking);
}
[TestCase]
public void ReadAssemblyInfoFlagsTests()
{
var assemblyInfo = ReadAssemblyInfo("[assembly: AssemblyFlags (32769)]");
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsTrue(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo("[assembly: AssemblyFlags (16385)]");
Assert.IsFalse(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo("[assembly: AssemblyFlags (49153)]");
Assert.IsFalse(assemblyInfo.JitOptimization);
Assert.IsTrue(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo("[assembly: AssemblyFlags (0)]");
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo(
"[assembly: AssemblyFlags(AssemblyNameFlags.EnableJITcompileTracking)]");
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsTrue(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo(
"[assembly: AssemblyFlags(AssemblyNameFlags.EnableJITcompileOptimizer)]");
Assert.IsFalse(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo(
"[assembly: AssemblyFlags()]");
Assert.IsTrue(assemblyInfo.JitOptimization);
Assert.IsFalse(assemblyInfo.JitTracking);
assemblyInfo = ReadAssemblyInfo(
"[assembly: AssemblyFlags(AssemblyNameFlags.EnableJITcompileOptimizer | AssemblyNameFlags.EnableJITcompileTracking)]");
Assert.IsFalse(assemblyInfo.JitOptimization);
Assert.IsTrue(assemblyInfo.JitTracking);
}
[TestCase]
public void WriteDefaultAssemblyInfoToEmptyAssemblyInfoFileTest()
{
var assemblyInfoFile = "using System.Reflection;";
var assemblyInfo = new AssemblyInfo { JitOptimization = true };
var result = WriteAssemblyInfoFile(assemblyInfo, assemblyInfoFile);
Assert.AreEqual("using System.Reflection;\r\n\r\n", result);
}
[TestCase]
public void WriteNotDefaultAssemblyInfoToEmptyAssemblyInfoFileTest()
{
var assemblyInfoFile = "using System.Reflection;";
var assemblyInfo = new AssemblyInfo
{
Title = "SharpDevelop",
Description = "OpenSource IDE",
Company = "Company",
Product = "Product",
Copyright = "Copyright 2014",
Trademark = "Trademark",
DefaultAlias = "Alias",
AssemblyVersion = new Version(1, 2, 3, 4),
AssemblyFileVersion = new Version(1, 2, 3, 4),
InformationalVersion = new Version(1, 2, 3, 4),
Guid = new Guid("0c8c889f-ced2-4167-b155-2d48a99d8c72"),
NeutralLanguage = "ru-RU",
ComVisible = true,
ClsCompliant = true,
JitOptimization = true,
JitTracking = true
};
var result = WriteAssemblyInfoFile(assemblyInfo, assemblyInfoFile);
Assert.AreEqual(
@"using System.Reflection;
[assembly: AssemblyTitle (""SharpDevelop"")]
[assembly: AssemblyDescription (""OpenSource IDE"")]
[assembly: AssemblyCompany (""Company"")]
[assembly: AssemblyProduct (""Product"")]
[assembly: AssemblyCopyright (""Copyright 2014"")]
[assembly: AssemblyTrademark (""Trademark"")]
[assembly: AssemblyDefaultAlias (""Alias"")]
[assembly: AssemblyVersion (""1.2.3.4"")]
[assembly: AssemblyFileVersion (""1.2.3.4"")]
[assembly: AssemblyInformationalVersion (""1.2.3.4"")]
[assembly: Guid (""0c8c889f-ced2-4167-b155-2d48a99d8c72"")]
[assembly: NeutralResourcesLanguage (""ru-RU"")]
[assembly: ComVisible (true)]
[assembly: CLSCompliant (true)]
[assembly: AssemblyFlags (32769)]
", result);
}
[TestCase]
public void WriteNotDefaultAssemblyInfoToNotEmptyAssemblyInfoFileTest()
{
var assemblyInfoFile = AssemblyInfoSample1;
var assemblyInfo = new AssemblyInfo
{
Title = "SharpDevelop-changed",
Description = "OpenSource IDE-changed",
Company = "Company-changed",
Product = "Product-changed",
Copyright = "Copyright 2014-changed",
Trademark = "Trademark-changed",
DefaultAlias = "Alias-changed",
AssemblyVersion = new Version(4, 3, 2, 1),
AssemblyFileVersion = new Version(4, 3, 2, 1),
InformationalVersion = new Version(4, 3, 2, 1),
Guid = new Guid("dc8c889f-ced2-4167-b155-2d48a99d8c72"),
NeutralLanguage = "en-US",
ComVisible = false,
ClsCompliant = false,
JitOptimization = false,
JitTracking = false
};
var result = WriteAssemblyInfoFile(assemblyInfo, assemblyInfoFile);
Assert.AreEqual(
@"using System;
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle (""SharpDevelop-changed"")]
[assembly: AssemblyDescription (""OpenSource IDE-changed"")]
[assembly: AssemblyCompany (""Company-changed"")]
[assembly: AssemblyProduct (""Product-changed"")]
[assembly: AssemblyCopyright (""Copyright 2014-changed"")]
[assembly: AssemblyTrademark (""Trademark-changed"")]
[assembly: AssemblyDefaultAlias (""Alias-changed"")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible (false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion (""4.3.2.1"")]
[assembly: AssemblyFileVersion (""4.3.2.1"")]
[assembly: AssemblyInformationalVersion (""4.3.2.1"")]
[assembly: Guid (""dc8c889f-ced2-4167-b155-2d48a99d8c72"")]
[assembly: NeutralResourcesLanguage (""en-US"")]
[assembly: AssemblyFlags (16385)]
[assembly: CLSCompliant (false)]
", result);
}
private AssemblyInfo ReadAssemblyInfo(string assemblyInfoFile)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(assemblyInfoFile));
var assemblyInfoProvider = new AssemblyInfoProvider();
var assemblyInfo = assemblyInfoProvider.Read(stream);
return assemblyInfo;
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(assemblyInfoFile)))
{
var assemblyInfoProvider = new AssemblyInfoProvider();
return assemblyInfoProvider.ReadAssemblyInfo(stream);
}
}
private string WriteAssemblyInfoFile(AssemblyInfo assemblyInfo, string sourceFile)
{
using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(sourceFile)))
{
var assemblyInfoProvider = new AssemblyInfoProvider();
return assemblyInfoProvider.MergeAssemblyInfo(assemblyInfo, inputStream);
}
}
}
}

Loading…
Cancel
Save