Created separate VSPackage classes for VS2012 and VS2013
This commit is contained in:
@@ -10,16 +10,16 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
public class CSharpCodeGeneratorTests
|
||||
{
|
||||
private string reswFileContents;
|
||||
private const string FilePath = "Resources.resw";
|
||||
private const string FILE_PATH = "Resources.resw";
|
||||
private string actual;
|
||||
private ICodeGenerator target;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
reswFileContents = File.ReadAllText(FilePath);
|
||||
reswFileContents = File.ReadAllText(FILE_PATH);
|
||||
|
||||
target = new CodeGeneratorFactory().Create(FilePath.Replace(".resw", string.Empty), "TestApp", reswFileContents);
|
||||
target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents);
|
||||
actual = target.GenerateCode();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.CodeDom;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem("Resources/Resources.resw")]
|
||||
public class CSharpCodeGeneratorTestsInternal
|
||||
{
|
||||
private string reswFileContents;
|
||||
private const string FILE_PATH = "Resources.resw";
|
||||
private string actual;
|
||||
private ICodeGenerator target;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
reswFileContents = File.ReadAllText(FILE_PATH);
|
||||
|
||||
target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents, classAccessibility: MemberAttributes.Assembly);
|
||||
actual = target.GenerateCode();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateCodeDoesNotReturnNull()
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeContainsPropertiesDefinedInResources()
|
||||
{
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
|
||||
foreach (var item in resourceItems.Where(item => !item.Name.Contains(".")))
|
||||
Assert.IsTrue(actual.Contains("public static string " + item.Name));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodePropertiesContainsCommentsSimilarToValuesDefinedInResources()
|
||||
{
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
|
||||
foreach (var item in resourceItems.Where(item => !item.Name.Contains(".")))
|
||||
Assert.IsTrue(actual.Contains("Localized resource similar to \"" + item.Value + "\""));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClassNameEqualsFileNameWithoutExtension()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("class Resources"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ResourceLoaderInitializedWithClassName()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("new ResourceLoader(currentAssemblyName + \"/Resources\");"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
public class CodeGeneratorFactoryTests
|
||||
{
|
||||
private string reswFileContents;
|
||||
private const string ClassName = "C:\\Test\\Resources\\Strings.resw";
|
||||
private const string CLASS_NAME = "C:\\Test\\Resources\\Strings.resw";
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -21,7 +21,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
public void CodeGeneratorFactoryReturnsValidInstance()
|
||||
{
|
||||
var target = new CodeGeneratorFactory();
|
||||
var actual = target.Create(ClassName, "TestApp", reswFileContents);
|
||||
var actual = target.Create(CLASS_NAME, "TestApp", reswFileContents);
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
<Compile Include="ClassNameExtractorTests.cs" />
|
||||
<Compile Include="CodeGeneratorFactoryTests.cs" />
|
||||
<Compile Include="CSharpCodeGeneratorTests.cs" />
|
||||
<Compile Include="CSharpCodeGeneratorTestsInternal.cs" />
|
||||
<Compile Include="ResourceParserErrorHandlingTests.cs" />
|
||||
<Compile Include="ResourceParserTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -10,19 +9,31 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
[DeploymentItem("Resources/Resources.resw")]
|
||||
public class StringExtensionTests
|
||||
{
|
||||
private const string FILE_PATH = "Resources.resw";
|
||||
const string TEXT = "test";
|
||||
|
||||
[TestMethod]
|
||||
public void LineEndingsAreSame()
|
||||
public void ConvertToIntPtrDoesNotReturnZero()
|
||||
{
|
||||
var reswFileContents = File.ReadAllText(FILE_PATH);
|
||||
var target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents);
|
||||
var expected = target.GenerateCode();
|
||||
uint len;
|
||||
var ptr = TEXT.ConvertToIntPtr(out len);
|
||||
Assert.AreNotEqual(IntPtr.Zero, ptr);
|
||||
}
|
||||
|
||||
uint length;
|
||||
var ptr = expected.ConvertToIntPtr(out length);
|
||||
var actual = Marshal.PtrToStringAnsi(ptr);
|
||||
Assert.AreEqual(expected, actual);
|
||||
[TestMethod]
|
||||
public void ConvertToIntPtrReturnsStringLengthAsParameter()
|
||||
{
|
||||
uint len;
|
||||
TEXT.ConvertToIntPtr(out len);
|
||||
Assert.AreNotEqual(TEXT.Length, len);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ConvertToIntPtrConvertsCorrectString()
|
||||
{
|
||||
uint len;
|
||||
var ptr = TEXT.ConvertToIntPtr(out len);
|
||||
var str = Marshal.PtrToStringAnsi(ptr, (int) len);
|
||||
Assert.AreEqual(TEXT, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("1.0.4.*")]
|
||||
[assembly: AssemblyVersion("1.0.5.*")]
|
||||
|
||||
[assembly: InternalsVisibleTo("VSPackage_IntegrationTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010045bd05a5b24c74b83f069df52e138682c2fb8b1ee65cb9d351fd7e8d622308aeb588b2a2975d75da4fe8a392510528baa26a3317809ec064d3cc852f0df94752ad2228d9f2a048ee2858c1e9d505b05f7fb4ede02f34154f75ea50445741c84f5ab1c814358f5fd6a6f08bb3d94284cff0524d5ca9d888c8648bcbc7a1e0a3c8")]
|
||||
[assembly: InternalsVisibleTo("VSPackage_UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010045bd05a5b24c74b83f069df52e138682c2fb8b1ee65cb9d351fd7e8d622308aeb588b2a2975d75da4fe8a392510528baa26a3317809ec064d3cc852f0df94752ad2228d9f2a048ee2858c1e9d505b05f7fb4ede02f34154f75ea50445741c84f5ab1c814358f5fd6a6f08bb3d94284cff0524d5ca9d888c8648bcbc7a1e0a3c8")]
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="VisualStudio2013Package.cs" />
|
||||
<Compile Include="CustomTool\ClassNameExtractor.cs" />
|
||||
<Compile Include="CustomTool\CodeDomCodeGenerator.cs" />
|
||||
<Compile Include="CustomTool\CodeGenerator.cs" />
|
||||
@@ -140,7 +141,7 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="VSPackagePackage.cs" />
|
||||
<Compile Include="VisualStudio2012Package.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -26,13 +26,13 @@ namespace VSPackage_UnitTests
|
||||
[TestMethod()]
|
||||
public void CreateInstance()
|
||||
{
|
||||
VSPackagePackage package = new VSPackagePackage();
|
||||
VisualStudio2012Package package = new VisualStudio2012Package();
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void IsIVsPackage()
|
||||
{
|
||||
VSPackagePackage package = new VSPackagePackage();
|
||||
VisualStudio2012Package package = new VisualStudio2012Package();
|
||||
Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage");
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace VSPackage_UnitTests
|
||||
public void SetSite()
|
||||
{
|
||||
// Create the package
|
||||
IVsPackage package = new VSPackagePackage() as IVsPackage;
|
||||
IVsPackage package = new VisualStudio2012Package() as IVsPackage;
|
||||
Assert.IsNotNull(package, "The object does not implement IVsPackage");
|
||||
|
||||
// Create a basic service provider
|
||||
|
||||
+6
-4
@@ -29,9 +29,11 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGenerator))]
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "ReswFileCodeGeneratorInternal", "ResW File Code Generator for C#", "{151F74CA-404D-4188-B994-D7683C32ACF4}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "ReswFileCodeGeneratorInternal", "ResW File Code Generator for VB", "{6C6AC14F-9B11-47C1-BC90-DFBFB89B1CB8}", true)] // visual basic
|
||||
public sealed class VSPackagePackage : Package
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{151F74CA-404D-4188-B994-D7683C32ACF4}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{6C6AC14F-9B11-47C1-BC90-DFBFB89B1CB8}", true)] // visual basic
|
||||
public sealed class VisualStudio2012Package : Package
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor of the package.
|
||||
@@ -40,7 +42,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
|
||||
/// not sited yet inside Visual Studio environment. The place to do all the other
|
||||
/// initialization is the Initialize method.
|
||||
/// </summary>
|
||||
public VSPackagePackage()
|
||||
public VisualStudio2012Package()
|
||||
{
|
||||
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool;
|
||||
using Microsoft.VisualStudio.Shell;
|
||||
using Microsoft.VisualStudio.Shell.Design.Serialization;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the class that implements the package exposed by this assembly.
|
||||
///
|
||||
/// The minimum requirement for a class to be considered a valid package for Visual Studio
|
||||
/// is to implement the IVsPackage interface and register itself with the shell.
|
||||
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
|
||||
/// to do it: it derives from the Package class that provides the implementation of the
|
||||
/// IVsPackage interface and uses the registration attributes defined in the framework to
|
||||
/// register itself and its components with the shell.
|
||||
/// </summary>
|
||||
// This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
|
||||
// a package.
|
||||
[PackageRegistration(UseManagedResourcesOnly = true)]
|
||||
// This attribute is used to register the information needed to show this package
|
||||
// in the Help/About dialog of Visual Studio.
|
||||
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
|
||||
[Guid(GuidList.guidVSPackagePkgString)]
|
||||
[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\12.0")]
|
||||
[ProvideObject(typeof(ReswFileCSharpCodeGenerator))]
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGenerator))]
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{151F74CA-404D-4188-B994-D7683C32ACF4}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{6C6AC14F-9B11-47C1-BC90-DFBFB89B1CB8}", true)] // visual basic
|
||||
public sealed class VisualStudio2013Package : Package
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor of the package.
|
||||
/// Inside this method you can place any initialization code that does not require
|
||||
/// any Visual Studio service because at this point the package object is created but
|
||||
/// not sited yet inside Visual Studio environment. The place to do all the other
|
||||
/// initialization is the Initialize method.
|
||||
/// </summary>
|
||||
public VisualStudio2013Package()
|
||||
{
|
||||
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Overridden Package Implementation
|
||||
#region Package Members
|
||||
|
||||
/// <summary>
|
||||
/// Initialization of the package; this method is called right after the package is sited, so this is the place
|
||||
/// where you can put all the initialization code that rely on services provided by VisualStudio.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
|
||||
base.Initialize();
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
|
||||
<Metadata>
|
||||
<Identity Id="6a4c1726-440f-4b2d-a2e5-711277da6099"
|
||||
Version="1.0.4"
|
||||
Version="1.0.5"
|
||||
Language="en-US"
|
||||
Publisher="Christian Resma Helle" />
|
||||
<DisplayName>ResW File Code Generator</DisplayName>
|
||||
@@ -13,8 +13,8 @@
|
||||
<License>License.txt</License>
|
||||
</Metadata>
|
||||
<Installation InstalledByMsi="false">
|
||||
<InstallationTarget Id="Microsoft.VisualStudio.Pro"
|
||||
Version="11.0" />
|
||||
<InstallationTarget Version="[11.0,12.0]"
|
||||
Id="Microsoft.VisualStudio.Premium" />
|
||||
</Installation>
|
||||
<Dependencies>
|
||||
<Dependency Id="Microsoft.Framework.NDP"
|
||||
|
||||
Reference in New Issue
Block a user