Skip to content

Commit

Permalink
- XsltArgumentList is in XmlTransformationSettings class
Browse files Browse the repository at this point in the history
- XsltArgumentList can be null according to the documentation
- fixed tests
- fixed exception messages to be aligned to documentation
- no need to overloaded aliases
  • Loading branch information
deqenq committed Jan 30, 2022
1 parent 1b2df1a commit bfca2ba
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/Cake.Common.Tests/Unit/XML/XmlTransformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Should_Throw_If_Xml_Not_Exists()
var result = Record.Exception(() => fixture.Transform());

// Then
AssertEx.IsExceptionWithMessage<FileNotFoundException>(result, "XML File not found.");
AssertEx.IsExceptionWithMessage<FileNotFoundException>(result, "XML file not found.");
}

[Fact]
Expand All @@ -105,7 +105,7 @@ public void Should_Throw_If_Xsl_Not_Exists()
var result = Record.Exception(() => fixture.Transform());

// Then
AssertEx.IsExceptionWithMessage<FileNotFoundException>(result, "Xsl File not found.");
AssertEx.IsExceptionWithMessage<FileNotFoundException>(result, "XSL file not found.");
}

[Fact]
Expand Down Expand Up @@ -210,7 +210,7 @@ public void Should_Throw_If_Xsl_Was_Null()
}

[Fact]
public void Should_Throw_If_String_Settings_Was_Null()
public void Should_Throw_If_Xml_Transformation_Settings_Was_Null()
{
// Given
var xml = Resources.XmlTransformation_Xml;
Expand All @@ -224,17 +224,21 @@ public void Should_Throw_If_String_Settings_Was_Null()
}

[Fact]
public void Should_Throw_If_XslArguments_Was_Null()
public void Should_Not_Throw_If_Xsl_Argument_List_Was_Null()
{
// Given
var xml = Resources.XmlTransformation_Xml;
var xsl = Resources.XmlTransformation_Xsl;
XmlTransformationSettings xmlTransformationSettings = new XmlTransformationSettings
{
XsltArgumentList = null
};

// When
var result = Record.Exception(() => XmlTransformation.Transform(xsl, null, xml));
var result = Record.Exception(() => XmlTransformation.Transform(xsl, xml, xmlTransformationSettings));

// Then
AssertEx.IsArgumentNullException(result, "arguments");
Assert.Null(result);
}

[Fact]
Expand All @@ -244,12 +248,17 @@ public void Should_Transform_Xml_String_And_Xsl_String_WithArguments_To_Result_S
var xml = Resources.XmlTransformation_Xml;
var xsl = Resources.XmlTransformationWithArguments_Xsl;
var htm = Resources.XmlTransformation_Htm_NoXmlDeclaration;
var arguments = new XsltArgumentList();
arguments.AddParam("BackgroundColor", string.Empty, "teal");
arguments.AddParam("Color", string.Empty, "white");
XmlTransformationSettings xmlTransformationSettings = new XmlTransformationSettings
{
OmitXmlDeclaration = true,
Encoding = new UTF8Encoding(false),
XsltArgumentList = new XsltArgumentList()
};
xmlTransformationSettings.XsltArgumentList.AddParam("BackgroundColor", string.Empty, "teal");
xmlTransformationSettings.XsltArgumentList.AddParam("Color", string.Empty, "white");

// When
var result = XmlTransformation.Transform(xsl, arguments, xml);
var result = XmlTransformation.Transform(xsl, xml, xmlTransformationSettings);

// Then
Assert.Equal(htm, result, ignoreLineEndingDifferences: true);
Expand All @@ -262,12 +271,17 @@ public void Should_Transform_Xml_String_And_Xsl_String_WithArgumentsAndNamespace
var xml = Resources.XmlTransformation_Xml;
var xsl = Resources.XmlTransformationWithArgumentsAndNamespace_Xsl;
var htm = Resources.XmlTransformation_Htm_NoXmlDeclaration;
var arguments = new XsltArgumentList();
arguments.AddParam("BackgroundColor", "http://example.com", "teal");
arguments.AddParam("Color", "http://example.com", "white");
XmlTransformationSettings xmlTransformationSettings = new XmlTransformationSettings
{
OmitXmlDeclaration = true,
Encoding = new UTF8Encoding(false),
XsltArgumentList = new XsltArgumentList()
};
xmlTransformationSettings.XsltArgumentList.AddParam("BackgroundColor", "http://example.com", "teal");
xmlTransformationSettings.XsltArgumentList.AddParam("Color", "http://example.com", "white");

// When
var result = XmlTransformation.Transform(xsl, arguments, xml);
var result = XmlTransformation.Transform(xsl, xml, xmlTransformationSettings);

// Then
Assert.Equal(htm, result, ignoreLineEndingDifferences: true);
Expand Down

0 comments on commit bfca2ba

Please sign in to comment.