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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user