Implemented using the filename of the specified .resw file as the generated class name
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem("Resources/Resources.resw")]
|
||||
public class ClassNameExtractorTests
|
||||
{
|
||||
private const string ClassName = "Resources.resw";
|
||||
|
||||
[TestMethod]
|
||||
public void DoesNotReturnNull()
|
||||
{
|
||||
var actual = ClassNameExtractor.GetClassName(ClassName);
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ReturnsFileNameWithoutExtension()
|
||||
{
|
||||
var actual = ClassNameExtractor.GetClassName(ClassName);
|
||||
Assert.AreEqual("Resources", actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FileNotFoundException))]
|
||||
public void ThrowsFileNotFoundException()
|
||||
{
|
||||
ClassNameExtractor.GetClassName("C:\\Test\\Resources\\Strings.resw");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
public class CodeGeneratorFactoryTests
|
||||
{
|
||||
private string reswFileContents;
|
||||
private const string ClassName = "C:\\Test\\Resources\\Strings.resw";
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -19,7 +20,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
public void CodeGeneratorFactoryReturnsValidInstance()
|
||||
{
|
||||
var target = new CodeGeneratorFactory();
|
||||
var actual = target.Create("TestApp", reswFileContents);
|
||||
var actual = target.Create(ClassName, "TestApp", reswFileContents);
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -6,32 +5,34 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem("Resources/Valid/Resources.resw")]
|
||||
[DeploymentItem("Resources/Resources.resw")]
|
||||
public class CodeGeneratorTests
|
||||
{
|
||||
private string reswFileContents;
|
||||
private const string FilePath = "Resources.resw";
|
||||
private string actual;
|
||||
private ICodeGenerator target;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
reswFileContents = File.ReadAllText("Resources.resw");
|
||||
reswFileContents = File.ReadAllText(FilePath);
|
||||
|
||||
target = new CodeGeneratorFactory().Create(FilePath, "TestApp", reswFileContents);
|
||||
actual = target.GenerateCode();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateCodeDoesNotReturnNull()
|
||||
{
|
||||
var target = new CodeGeneratorFactory().Create("TestApp", reswFileContents);
|
||||
var actual = target.GenerateCode();
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeContainsPropertiesDefinedInResources()
|
||||
{
|
||||
var target = new CodeGeneratorFactory().Create("TestApp", reswFileContents);
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
var actual = target.GenerateCode();
|
||||
|
||||
|
||||
foreach (var item in resourceItems.Where(item => !item.Name.Contains(".")))
|
||||
Assert.IsTrue(actual.Contains("public static string " + item.Name));
|
||||
}
|
||||
@@ -39,12 +40,16 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
[TestMethod]
|
||||
public void GeneratedCodePropertiesContainsCommentsSimilarToValuesDefinedInResources()
|
||||
{
|
||||
var target = new CodeGeneratorFactory().Create("TestApp", reswFileContents);
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
var actual = target.GenerateCode();
|
||||
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClassNameExtractorTests.cs" />
|
||||
<Compile Include="CodeGeneratorFactoryTests.cs" />
|
||||
<Compile Include="CodeGeneratorTests.cs" />
|
||||
<Compile Include="ResourceParserErrorHandlingTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user