Skip to content

Commit 5bf51f0

Browse files
Merge pull request #6 from Sabermotamedi/change/add-fluentassertion-to-xml-tests
replace fluent assertions with pure Nunit assert in xml tests
2 parents 48fea55 + 20591dc commit 5bf51f0

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/HttpClientToCurl/Main.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static string GenerateCurlInString(
4545
return script;
4646
}
4747

48+
4849
public static void GenerateCurlInConsole(this HttpClient httpClient, HttpRequestMessage httpRequestMessage, Action<ConsoleConfig> config = null)
4950
{
5051
var consoleConfig = new ConsoleConfig();

src/HttpClientToCurlGeneratorTest/HttpClientToCurlGeneratorTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
1213
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
1314
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1415
<PackageReference Include="NUnit" Version="3.13.3" />

src/HttpClientToCurlGeneratorTest/UnitTest/MediaTypes/Xml/FailedCurlGeneratorTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using System.Net.Mime;
2-
using System.Text;
1+
using FluentAssertions;
32
using HttpClientToCurl;
43
using NUnit.Framework;
4+
using System.Net.Mime;
5+
using System.Text;
56

67
namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Xml;
78

89
public class FailedCurlGeneratorTests
910
{
1011
[Theory]
11-
public void GenerateCurl_When_Invalid_Xml()
12+
public void Get_Error_Message_When_Input_XML_Is_Invalid()
1213
{
1314
// Arrange
1415
string requestBody = @"<xml version = ""1.0"" encoding = ""UTF-8""?>
@@ -34,16 +35,17 @@ public void GenerateCurl_When_Invalid_Xml()
3435
true);
3536

3637
// Assert
37-
Assert.That(!string.IsNullOrWhiteSpace(script?.Trim()), Is.True);
38-
Assert.That(script, Does.StartWith("GenerateCurlError"));
39-
Assert.That(script?.Trim(), Is.EqualTo(@"GenerateCurlError => exception in parsing request body text/xml!
38+
script.Should().NotBeNull();
39+
script.Should().NotBeEmpty();
40+
script.Should().StartWith("GenerateCurlError");
41+
script.Should().BeEquivalentTo(@"GenerateCurlError => exception in parsing request body text/xml!
4042
request body:
4143
<xml version = ""1.0"" encoding = ""UTF-8""?>
4244
<Order>
4345
<Id>12</Id>
4446
<name>Jason</name>
4547
<requestId>10001024</requestId>
4648
<amount>240000</amount>
47-
</Order>"));
49+
</Order> ");
4850
}
4951
}

src/HttpClientToCurlGeneratorTest/UnitTest/MediaTypes/Xml/SuccessCurlGeneratorTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using System.Net.Mime;
2-
using System.Text;
1+
using FluentAssertions;
32
using HttpClientToCurl;
43
using NUnit.Framework;
4+
using System.Net.Mime;
5+
using System.Text;
56

67
namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Xml;
78

89
public class SuccessCurlGeneratorTests
910
{
1011
[Theory]
11-
public void GenerateCurl_For_PostMethod()
12+
public void Get_Curl_Script_When_Input_XML_Is_Valid()
1213
{
1314
// Arrange
1415
string requestBody = @"<?xml version = ""1.0"" encoding = ""UTF-8""?>
@@ -34,16 +35,15 @@ public void GenerateCurl_For_PostMethod()
3435
true);
3536

3637
// Assert
37-
Assert.That(!string.IsNullOrWhiteSpace(script?.Trim()), Is.True);
38-
Assert.That(script, Does.StartWith("curl -X POST"));
39-
Assert.That(script?.Trim(),
40-
Is.EqualTo(
41-
@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<?xml version = ""1.0"" encoding = ""UTF-8""?>
38+
script.Should().NotBeNull();
39+
script.Should().NotBeEmpty();
40+
script.Should().StartWith("curl -X POST");
41+
script.Should().BeEquivalentTo(@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<?xml version = ""1.0"" encoding = ""UTF-8""?>
4242
<Order>
4343
<Id>12</Id>
4444
<name>Jason</name>
4545
<requestId>10001024</requestId>
4646
<amount>240000</amount>
47-
</Order>'"));
47+
</Order>' ");
4848
}
4949
}

0 commit comments

Comments
 (0)