|
1 | | -// using FluentAssertions; |
2 | | -// using System.Net.Mime; |
3 | | -// using System.Text; |
4 | | -// using HttpClientToCurl.Builder; |
5 | | -// using Xunit; |
6 | | -// |
7 | | -// namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Xml; |
8 | | -// |
9 | | -// public class SuccessCurlGeneratorTests |
10 | | -// { |
11 | | -// [Fact] |
12 | | -// public void Get_Curl_Script_For_PostMethod() |
13 | | -// { |
14 | | -// // Arrange |
15 | | -// string requestBody = @"<?xml version = ""1.0"" encoding = ""UTF-8""?> |
16 | | -// <Order> |
17 | | -// <Id>12</Id> |
18 | | -// <name>Jason</name> |
19 | | -// <requestId>10001024</requestId> |
20 | | -// <amount>240000</amount> |
21 | | -// </Order>"; |
22 | | -// |
23 | | -// var requestUri = "api/test"; |
24 | | -// var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Text.Xml) }; |
25 | | -// httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61"); |
26 | | -// |
27 | | -// using var httpClient = new HttpClient(); |
28 | | -// httpClient.BaseAddress = new Uri("http://localhost:1213/v1/"); |
29 | | -// |
30 | | -// // Act |
31 | | -// string script = Generator.GenerateCurl( |
32 | | -// httpClient, |
33 | | -// httpRequestMessage, |
34 | | -// null); |
35 | | -// |
36 | | -// // Assert |
37 | | -// script.Should().NotBeNullOrEmpty(); |
38 | | -// script.Should().StartWith("curl -X POST"); |
39 | | -// script.Trim().Should().BeEquivalentTo( |
40 | | -// @"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""?> |
41 | | -// <Order> |
42 | | -// <Id>12</Id> |
43 | | -// <name>Jason</name> |
44 | | -// <requestId>10001024</requestId> |
45 | | -// <amount>240000</amount> |
46 | | -// </Order>'"); |
47 | | -// } |
48 | | -// |
49 | | -// [Fact] |
50 | | -// public void Get_Error_Message_When_Input_XML_Is_Invalid_For_PostMethod() |
51 | | -// { |
52 | | -// // Arrange |
53 | | -// string requestBody = @"<xml version = ""1.0"" encoding = ""UTF-8""?> |
54 | | -// <Order> |
55 | | -// <Id>12</Id> |
56 | | -// <name>Jason</name> |
57 | | -// <requestId>10001024</requestId> |
58 | | -// <amount>240000</amount> |
59 | | -// </Order>"; |
60 | | -// |
61 | | -// var requestUri = "api/test"; |
62 | | -// var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Text.Xml) }; |
63 | | -// httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61"); |
64 | | -// |
65 | | -// using var httpClient = new HttpClient(); |
66 | | -// httpClient.BaseAddress = new Uri("http://localhost:1213/v1/"); |
67 | | -// |
68 | | -// // Act |
69 | | -// string script = Generator.GenerateCurl( |
70 | | -// httpClient, |
71 | | -// httpRequestMessage, |
72 | | -// null); |
73 | | -// |
74 | | -// // Assert |
75 | | -// script.Should().NotBeNull(); |
76 | | -// script.Should().NotBeEmpty(); |
77 | | -// script.Should().StartWith("curl -X POST"); |
78 | | -// script.Trim().Should().BeEquivalentTo( |
79 | | -// @"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""?> |
80 | | -// <Order> |
81 | | -// <Id>12</Id> |
82 | | -// <name>Jason</name> |
83 | | -// <requestId>10001024</requestId> |
84 | | -// <amount>240000</amount> |
85 | | -// </Order>'"); |
86 | | -// } |
87 | | -// } |
| 1 | +using FluentAssertions; |
| 2 | +using System.Net.Mime; |
| 3 | +using System.Text; |
| 4 | +using HttpClientToCurl.Builder; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Xml; |
| 8 | + |
| 9 | +public class SuccessCurlGeneratorTests |
| 10 | +{ |
| 11 | + [Fact] |
| 12 | + public void Get_Curl_Script_For_PostMethod() |
| 13 | + { |
| 14 | + // Arrange |
| 15 | + string requestBody = @"<?xml version = ""1.0"" encoding = ""UTF-8""?> |
| 16 | + <Order> |
| 17 | + <Id>12</Id> |
| 18 | + <name>Jason</name> |
| 19 | + <requestId>10001024</requestId> |
| 20 | + <amount>240000</amount> |
| 21 | + </Order>"; |
| 22 | + |
| 23 | + var requestUri = "api/test"; |
| 24 | + var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Text.Xml) }; |
| 25 | + httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61"); |
| 26 | + |
| 27 | + using var httpClient = new HttpClient(); |
| 28 | + httpClient.BaseAddress = new Uri("http://localhost:1213/v1/"); |
| 29 | + |
| 30 | + // Act |
| 31 | + string script = Generator.GenerateCurl( |
| 32 | + httpClient, |
| 33 | + httpRequestMessage, |
| 34 | + null); |
| 35 | + |
| 36 | + // Assert |
| 37 | + script.Should().NotBeNullOrEmpty(); |
| 38 | + script.Should().StartWith("curl -X POST"); |
| 39 | + script.Trim().Should().BeEquivalentTo( |
| 40 | + @"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""?> |
| 41 | + <Order> |
| 42 | + <Id>12</Id> |
| 43 | + <name>Jason</name> |
| 44 | + <requestId>10001024</requestId> |
| 45 | + <amount>240000</amount> |
| 46 | + </Order>'"); |
| 47 | + } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + public void Get_Error_Message_When_Input_XML_Is_Invalid_For_PostMethod() |
| 51 | + { |
| 52 | + // Arrange |
| 53 | + string requestBody = @"<xml version = ""1.0"" encoding = ""UTF-8""?> |
| 54 | + <Order> |
| 55 | + <Id>12</Id> |
| 56 | + <name>Jason</name> |
| 57 | + <requestId>10001024</requestId> |
| 58 | + <amount>240000</amount> |
| 59 | + </Order>"; |
| 60 | + |
| 61 | + var requestUri = "api/test"; |
| 62 | + var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Text.Xml) }; |
| 63 | + httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61"); |
| 64 | + |
| 65 | + using var httpClient = new HttpClient(); |
| 66 | + httpClient.BaseAddress = new Uri("http://localhost:1213/v1/"); |
| 67 | + |
| 68 | + // Act |
| 69 | + string script = Generator.GenerateCurl( |
| 70 | + httpClient, |
| 71 | + httpRequestMessage, |
| 72 | + null); |
| 73 | + |
| 74 | + // Assert |
| 75 | + script.Should().NotBeNull(); |
| 76 | + script.Should().NotBeEmpty(); |
| 77 | + script.Should().StartWith("curl -X POST"); |
| 78 | + script.Trim().Should().BeEquivalentTo( |
| 79 | + @"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""?> |
| 80 | + <Order> |
| 81 | + <Id>12</Id> |
| 82 | + <name>Jason</name> |
| 83 | + <requestId>10001024</requestId> |
| 84 | + <amount>240000</amount> |
| 85 | + </Order>'"); |
| 86 | + } |
| 87 | +} |
0 commit comments