add version 0.0.1
This commit is contained in:
@@ -11,8 +11,8 @@ public class LogicResourcesTests
|
||||
{
|
||||
var rm = Properties.Resources.ResourceManager;
|
||||
Assert.AreEqual(
|
||||
new FormattableResourceString(
|
||||
Properties.Resources.ResourceStringMembers,
|
||||
new FormattedResourceString(
|
||||
Properties.Resources.ResourceStringMembers.Format,
|
||||
LiteralString.Factory("ResourceStringMembers"),
|
||||
LiteralString.Factory("ResourceManager")
|
||||
).Value,
|
||||
@@ -24,6 +24,44 @@ public class LogicResourcesTests
|
||||
);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Get_ResourceFormatClassMembers()
|
||||
{
|
||||
var rm = Properties.Resources.ResourceManager;
|
||||
Assert.AreEqual(
|
||||
new FormattedResourceString(
|
||||
Properties.Resources.ResourceFormatClassMembers.Format,
|
||||
LiteralString.Factory("ResourceFormatClassMembers"),
|
||||
LiteralString.Factory("ResourceManager"),
|
||||
LiteralString.Factory("Format")
|
||||
).Value,
|
||||
string.Format(
|
||||
rm.GetString("ResourceFormatClassMembers") ?? string.Empty,
|
||||
"ResourceFormatClassMembers",
|
||||
"ResourceManager",
|
||||
"Format"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Get_ResourceFormatClassFromMethod()
|
||||
{
|
||||
var rm = Properties.Resources.ResourceManager;
|
||||
Assert.AreEqual(
|
||||
new FormattedResourceString(
|
||||
Properties.Resources.ResourceFormatClassFromMethod.Format,
|
||||
LiteralString.Factory("IResourceString name"),
|
||||
LiteralString.Factory("name")
|
||||
).Value,
|
||||
string.Format(
|
||||
rm.GetString("ResourceFormatClassFromMethod") ?? string.Empty,
|
||||
"IResourceString name",
|
||||
"name"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Get_ResourceManagerMemberTemplate()
|
||||
{
|
||||
@@ -45,7 +83,7 @@ public class LogicResourcesTests
|
||||
var rm = Properties.Resources.ResourceManager;
|
||||
|
||||
var rmSnippet = CodeSnippetFactory.CreateResourceMangerMemberCodeSnippet(
|
||||
"Resources"
|
||||
"Resources"
|
||||
);
|
||||
|
||||
Assert.AreEqual(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
@@ -9,10 +9,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -11,13 +11,18 @@ public class ResxFileTests
|
||||
<root>
|
||||
<data name='Test1'>
|
||||
<value>Value1</value>
|
||||
<comment>This is a greeting message.</comment>
|
||||
</data>
|
||||
<data name='Test2' type='{typeof(int).FullName}'>
|
||||
<value>Value2</value>
|
||||
<data name='Test2' type='{typeof(string).FullName}'>
|
||||
<value>{{2}}Value2{{0}}{{{{1}}}}</value>
|
||||
<comment>2 = prefix</comment>
|
||||
</data>
|
||||
<data name='Test3' type='{typeof(byte[]).FullName}'>
|
||||
<value>0xDEADBEEF</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
private const string expectedClass = @"
|
||||
private const string expectedClass = @"
|
||||
using ResourceString.Net.Contract;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
@@ -34,7 +39,7 @@ namespace TestNameSpace
|
||||
private static readonly Type _Type = typeof(ResourceManager);
|
||||
|
||||
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||
() => new ResourceManager(_Type.FullName, _Type.Assembly),
|
||||
() => new ResourceManager(_Type.FullName ?? string.Empty, _Type.Assembly),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -54,16 +59,22 @@ namespace TestNameSpace
|
||||
|
||||
#endregion // Test1
|
||||
|
||||
#region Test2
|
||||
internal static class Test2
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString(""Test2"", ResourceManager, CultureInfo.CurrentCulture),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
private static readonly Lazy<IResourceString> LazyTest2 = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString(""Test2"", ResourceManager, CultureInfo.CurrentCulture),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Test2 => LazyTest2.Value;
|
||||
|
||||
#endregion // Test2
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString prefix, IResourceString p1) => new FormattedResourceString(
|
||||
Format,
|
||||
prefix,
|
||||
p1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}";
|
||||
@@ -77,8 +88,9 @@ namespace TestNameSpace
|
||||
{
|
||||
// Arrange
|
||||
var expectedData = new[] {
|
||||
("Test1", "Value1", string.Empty),
|
||||
("Test2", "Value2", typeof(int).FullName)
|
||||
("Test1", "Value1", string.Empty, "This is a greeting message."),
|
||||
("Test2", "{2}Value2{0}{{1}}", typeof(string).FullName, "2 = prefix"),
|
||||
("Test3", "0xDEADBEEF", typeof(byte[]).FullName, string.Empty)
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -89,8 +101,13 @@ namespace TestNameSpace
|
||||
|
||||
// Assert
|
||||
CollectionAssert.AreEqual(
|
||||
expectedData,
|
||||
result.Select(i => (i.Name, i.Value, i.Type.IfNone(string.Empty))).ToList()
|
||||
expectedData,
|
||||
result.Select(i => (
|
||||
i.Name,
|
||||
i.Value,
|
||||
i.Type.IfNone(string.Empty),
|
||||
i.Comment.IfNone(string.Empty)
|
||||
)).ToList()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,7 +145,7 @@ namespace TestNameSpace
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ToMemberString()
|
||||
{
|
||||
{
|
||||
// Act
|
||||
var result = Parser.TryParse(validXml).Match(
|
||||
Some: v => CodeSnippetFactory.CreateMemberCodeSnippets(v.Resources),
|
||||
@@ -144,8 +161,8 @@ namespace TestNameSpace
|
||||
);
|
||||
|
||||
Assert.AreEqual(
|
||||
"#region Test2",
|
||||
result.Select(i => i.Value.Substring(0, 25).Trim()).ToList()[1]
|
||||
"internal static class Test2",
|
||||
result.Select(i => i.Value.Substring(0, 45).Trim()).ToList()[1]
|
||||
);
|
||||
|
||||
}
|
||||
@@ -160,7 +177,7 @@ namespace TestNameSpace
|
||||
"TestResourceClass",
|
||||
CodeSnippetFactory.CreateResourceMangerMemberCodeSnippet("ResourceManager"),
|
||||
v.Resources
|
||||
),
|
||||
),
|
||||
None: () => throw new InvalidOperationException()
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user