Skip to content

Commit

Permalink
Merge pull request #1 from farlee2121/pr-nullref
Browse files Browse the repository at this point in the history
PR Tidy up, mainly testing
  • Loading branch information
AdrianKokot authored Mar 5, 2024
2 parents affcd3c + a947f4f commit b6a1f0e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 33 deletions.
17 changes: 6 additions & 11 deletions System.Resources.NetStandard/WinformsTypeMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ public static Func<Type, string> InterceptWinformsTypes(Func<Type,string> typeNa
{
if (type.AssemblyQualifiedName == typeof(ResXFileRef).AssemblyQualifiedName)
{
return NetStandard.ResXConstants.ResxFileRefTypeInfo;
}
if (type.AssemblyQualifiedName == typeof(ResXNullRef).AssemblyQualifiedName)
return ResXConstants.ResxFileRefTypeInfo;
}
else if (type.AssemblyQualifiedName == typeof(ResXNullRef).AssemblyQualifiedName)
{
return NetStandard.ResXConstants.ResxNullRefTypeInfo;
return ResXConstants.ResxNullRefTypeInfo;
}
if (typeNameConverter != null)
return typeNameConverter(type);
return null;
else if (typeNameConverter != null) return typeNameConverter(type);
else return null;
};
}

Expand Down
46 changes: 28 additions & 18 deletions Tests/Example.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Tests/Example.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<data name="text_ansi" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestResources\Files\text.ansi.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="ResxWithNullRef" type="System.Resources.ResXNullRef, System.Windows.Forms">
<value />
<data name="ResxWithNullRef" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>ResxWithNullRef.resx;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
29 changes: 27 additions & 2 deletions Tests/ResxDataNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private List<ResXDataNode> ReaderToNodes(ResXResourceReader reader)
}

[Fact]
public void ResxDataNode_ResXFileRefsWrittenBackWithSameAssemblyInfo()
public void ResxDataNode_ResXFileRefs_WrittenBackWithSameAssemblyInfo()
{
// This test ensures compatibility with tooling like Visual Studio's visual ResX editor

Expand Down Expand Up @@ -190,7 +190,7 @@ public void ResxDataNode_CreateForResXNullRef()
[Fact]
public void ResxDataNode_ResXNullRef_RoundTrip()
{
var referencedFileContent = Example.ResxWithNullRef;
object referencedFileContent = null;
var nodeInfo = new DataNodeInfo
{
Name = "ResxWithNullRef",
Expand All @@ -217,5 +217,30 @@ public void ResxDataNode_ResXNullRef_RoundTrip()
Assert.Equal(referencedFileContent, dictionary.GetValueOrDefault(nodeInfo.Name));
}
}

[Fact]
public void ResxDataNode_ResXNullRefs_WrittenBackWithSameAssemblyInfo()
{
// This test ensures compatibility with tooling like Visual Studio's visual ResX editor

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

string originalResx = Example.ResxWithNullRef;
StringBuilder writerOutput = new StringBuilder();

using (var reader = new ResXResourceReader(new StringReader(originalResx)))
{
reader.UseResXDataNodes = true;
var dataNodes = ReaderToNodes(reader);

using (ResXResourceWriter writer = new ResXResourceWriter(new StringWriter(writerOutput)))
{
dataNodes.ForEach(writer.AddResource);
writer.Generate();
}
}

Assert.Equal(originalResx, writerOutput.ToString());
}
}
}
65 changes: 65 additions & 0 deletions Tests/ResxWithNullRef.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ResxWithNullRef" type="System.Resources.ResXNullRef, System.Windows.Forms">
<value />
</data>
</root>
4 changes: 4 additions & 0 deletions Tests/System.Resources.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="ResxWithNullRef.resx" />
<EmbeddedResource Remove="TestResources\Files\ResxWithFileRef.resx" />
</ItemGroup>
<ItemGroup>
<Content Include="ResxWithNullRef.resx">
<SubType>Designer</SubType>
</Content>
<Content Include="ResxWithFileRef.resx" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit b6a1f0e

Please sign in to comment.