Skip to content

Commit 781e22d

Browse files
committed
fix: reorganize internals
1 parent afeab7c commit 781e22d

25 files changed

+898
-897
lines changed

Catglobe.ResXFileCodeGenerator.Tests/Catglobe.ResXFileCodeGenerator.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
<EmbeddedResource Update="**/*.??.resx;**/*.??-??.resx">
3333
<DependentUpon>$([System.IO.Path]::GetFileNameWithoutExtension('%(FileName)')).resx</DependentUpon>
3434
</EmbeddedResource>
35-
<EmbeddedResource Update="IntegrationTests\Test2.resx">
36-
<UseResManager>true</UseResManager>
37-
</EmbeddedResource>
35+
<EmbeddedResource Update="IntegrationTests\Test2.resx">
36+
<UseResManager>true</UseResManager>
37+
</EmbeddedResource>
3838
</ItemGroup>
3939

4040
<ItemGroup>

Catglobe.ResXFileCodeGenerator.Tests/CodeGenTests.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,12 @@ namespace Resources;
247247
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.ActivityEntrySortRuleNames",
248248
CustomToolNamespace = "Resources",
249249
ClassName = "ActivityEntrySortRuleNames",
250-
GroupedFile = new GroupedAdditionalFile(
251-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub(string.Empty, Text), NewGuid()),
252-
subFiles: new[]
253-
{
254-
new AdditionalTextWithHash(new AdditionalTextStub("test.da.rex", TextDa), NewGuid()),
255-
new AdditionalTextWithHash(new AdditionalTextStub("test.da-dk.rex", TextDaDk), NewGuid()),
256-
}
257-
),
250+
//make random to test sorting
251+
GroupedFile = new(new[]{
252+
ResxFile.From(new AdditionalTextStub("test.resx", Text))!,
253+
ResxFile.From(new AdditionalTextStub("test.da.resx", TextDa))!,
254+
ResxFile.From(new AdditionalTextStub("test.da-dk.resx", TextDaDk))!,
255+
}.OrderBy(_=>NewGuid()).ToList()),
258256
PublicClass = publicClass,
259257
UseResManager = true,
260258
NullForgivingOperators = nullForgivingOperators,

Catglobe.ResXFileCodeGenerator.Tests/GeneratorTests.cs

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private static void Generate(
8989
// ------------------------------------------------------------------------------
9090
#nullable enable
9191
namespace Resources;
92-
using System.Globalization;
93-
using System.Resources;
92+
using global::System.Globalization;
93+
using global::System.Resources;
9494
9595
{(publicClass ? "public" : "internal")}{(staticClass ? " static" : string.Empty)}{(partial ? " partial" : string.Empty)} class ActivityEntrySortRuleNames
9696
{{
@@ -116,10 +116,9 @@ namespace Resources;
116116
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.ActivityEntrySortRuleNames",
117117
CustomToolNamespace = "Resources",
118118
ClassName = "ActivityEntrySortRuleNames",
119-
GroupedFile = new GroupedAdditionalFile(
120-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", Text), NewGuid()),
121-
subFiles: Array.Empty<AdditionalTextWithHash>()
122-
),
119+
GroupedFile = new([
120+
ResxFile.From(new AdditionalTextStub("test.resx", Text))!,
121+
]),
123122
PublicClass = publicClass,
124123
NullForgivingOperators = nullForgivingOperators,
125124
StaticClass = staticClass,
@@ -153,8 +152,8 @@ private static void GenerateInner(
153152
// ------------------------------------------------------------------------------
154153
#nullable enable
155154
namespace Resources;
156-
using System.Globalization;
157-
using System.Resources;
155+
using global::System.Globalization;
156+
using global::System.Resources;
158157
159158
{(publicClass ? "public" : "internal")}{(partial ? " partial" : string.Empty)}{(staticClass ? " static" : string.Empty)} class ActivityEntrySortRuleNames
160159
{{{(string.IsNullOrEmpty(innerClassInstanceName) ? string.Empty : $"\n public {innerClassName} {innerClassInstanceName} {{ get; }} = new();\n")}
@@ -185,10 +184,9 @@ namespace Resources;
185184
ClassName = "ActivityEntrySortRuleNames",
186185
PublicClass = publicClass,
187186
NullForgivingOperators = nullForgivingOperators,
188-
GroupedFile = new GroupedAdditionalFile(
189-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", Text), NewGuid()),
190-
subFiles: Array.Empty<AdditionalTextWithHash>()
191-
),
187+
GroupedFile = new([
188+
ResxFile.From(new AdditionalTextStub("test.resx", Text))!,
189+
]),
192190
StaticClass = staticClass,
193191
PartialClass = partial,
194192
StaticMembers = staticMembers,
@@ -408,8 +406,8 @@ read any of the formats listed below.
408406
// ------------------------------------------------------------------------------
409407
#nullable enable
410408
namespace Catglobe.Web.App_GlobalResources;
411-
using System.Globalization;
412-
using System.Resources;
409+
using global::System.Globalization;
410+
using global::System.Resources;
413411
414412
public static class CommonMessages
415413
{
@@ -458,10 +456,9 @@ public static class CommonMessages
458456
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.CommonMessages",
459457
CustomToolNamespace = null,
460458
ClassName = "CommonMessages",
461-
GroupedFile = new GroupedAdditionalFile(
462-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
463-
subFiles: Array.Empty<AdditionalTextWithHash>()
464-
),
459+
GroupedFile = new([
460+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
461+
]),
465462
PublicClass = true,
466463
NullForgivingOperators = false,
467464
StaticClass = true,
@@ -492,8 +489,8 @@ public void Generate_StringBuilder_Name_PartialXmlWorks()
492489
// ------------------------------------------------------------------------------
493490
#nullable enable
494491
namespace Catglobe.Web.App_GlobalResources;
495-
using System.Globalization;
496-
using System.Resources;
492+
using global::System.Globalization;
493+
using global::System.Resources;
497494
498495
public static class CommonMessages
499496
{
@@ -514,10 +511,9 @@ public static class CommonMessages
514511
LocalNamespace = "Catglobe.Web.App_GlobalResources",
515512
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.CommonMessages",
516513
CustomToolNamespace = null,
517-
GroupedFile = new GroupedAdditionalFile(
518-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
519-
subFiles: Array.Empty<AdditionalTextWithHash>()
520-
),
514+
GroupedFile = new([
515+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
516+
]),
521517
ClassName = "CommonMessages",
522518
PublicClass = true,
523519
NullForgivingOperators = false,
@@ -548,10 +544,9 @@ public void Generate_StringBuilder_Name_DuplicatedataGivesWarning()
548544
{
549545
LocalNamespace = "Catglobe.Web.App_GlobalResources",
550546
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.CommonMessages",
551-
GroupedFile = new GroupedAdditionalFile(
552-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
553-
subFiles: Array.Empty<AdditionalTextWithHash>()
554-
),
547+
GroupedFile = new([
548+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
549+
]),
555550
CustomToolNamespace = null,
556551
ClassName = "CommonMessages",
557552
PublicClass = true,
@@ -584,10 +579,9 @@ public void Generate_StringBuilder_Name_MemberSameAsFileGivesWarning()
584579
{
585580
LocalNamespace = "Catglobe.Web.App_GlobalResources",
586581
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.CommonMessages",
587-
GroupedFile = new GroupedAdditionalFile(
588-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
589-
subFiles: Array.Empty<AdditionalTextWithHash>()
590-
),
582+
GroupedFile = new([
583+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
584+
]),
591585
CustomToolNamespace = null,
592586
ClassName = "CommonMessages",
593587
PublicClass = true,
@@ -611,10 +605,4 @@ public void GetLocalNamespace_ShouldNotGenerateIllegalNamespace()
611605
ns.ShouldBe("root");
612606
}
613607

614-
[Fact]
615-
public void ResxFileName_ShouldNotGenerateIllegalClassnames()
616-
{
617-
var ns = Utilities.GetClassNameFromPath("test.cshtml.resx");
618-
ns.ShouldBe("test");
619-
}
620608
}

Catglobe.ResXFileCodeGenerator.Tests/GithubIssues/Issue3/GeneratorTests.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public void Generate_StringBuilder_Name_NotValidIdentifier()
8080
// ------------------------------------------------------------------------------
8181
#nullable enable
8282
namespace Catglobe.Web.App_GlobalResources;
83-
using System.Globalization;
84-
using System.Resources;
83+
using global::System.Globalization;
84+
using global::System.Resources;
8585
8686
public static class CommonMessages
8787
{
@@ -102,10 +102,9 @@ public static class CommonMessages
102102
LocalNamespace = "Catglobe.Web.App_GlobalResources",
103103
EmbeddedFilename = "Catglobe.Web.App_GlobalResources.CommonMessages",
104104
CustomToolNamespace = null,
105-
GroupedFile = new GroupedAdditionalFile(
106-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
107-
subFiles: Array.Empty<AdditionalTextWithHash>()
108-
),
105+
GroupedFile = new([
106+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
107+
]),
109108
ClassName = "CommonMessages",
110109
PublicClass = true,
111110
NullForgivingOperators = false,
@@ -193,17 +192,15 @@ public void Generate_StringBuilder_Value_InvalidCharacter()
193192
LocalNamespace = "Catglobe.Web.App_GlobalResources",
194193
CustomToolNamespace = "Resources",
195194
ClassName = "ActivityEntrySortRuleNames",
196-
GroupedFile = new GroupedAdditionalFile(
197-
mainFile: new AdditionalTextWithHash(new AdditionalTextStub("", text), NewGuid()),
198-
subFiles: Array.Empty<AdditionalTextWithHash>()
199-
),
195+
GroupedFile = new([
196+
ResxFile.From(new AdditionalTextStub("test.resx", text))!,
197+
]),
200198
PublicClass = true,
201199
NullForgivingOperators = false,
202200
StaticClass = true
203201
};
204-
Should.Throw<XmlException>(() =>
205-
{
206-
generator.Generate(options);
207-
});
202+
var (_, _, errorsAndWarnings) = generator.Generate(options);
203+
errorsAndWarnings.ShouldNotBeNull().ShouldNotBeEmpty();
204+
errorsAndWarnings.ShouldNotBeNull().ShouldAllBe(x => x.Severity == DiagnosticSeverity.Error);
208205
}
209206
}

0 commit comments

Comments
 (0)