Skip to content

Commit e005674

Browse files
committed
Added several more unit tests.
1 parent 27885b9 commit e005674

16 files changed

+5152
-48
lines changed

2021-06-03_vstestconsole.xml

+2,463
Large diffs are not rendered by default.

Execute.HttpRequest/Execute.HttpRequest.cs

+46-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Net.Http;
8+
using System.Net.Http.Headers;
89
using System.Net;
910
using System.Collections;
1011
using System.Text.RegularExpressions;
1112
using System.IO;
1213
using System.IO.Compression;
1314
using mshtml;
1415
using System.Reflection;
16+
using System.Web;
1517

1618
namespace Execute
1719
{
@@ -501,7 +503,10 @@ public async Task<RetObject> SendHttp(string uri, HttpMethod method = null, Orde
501503
if (File.Exists(filepath))
502504
{
503505
ByteArrayContent bac = new ByteArrayContent(File.ReadAllBytes(filepath));
504-
bac.Headers.Add("Content-Type", "application/octet-stream");
506+
bac.Headers.Add("Content-Type", MimeMapping.GetMimeMapping(filepath));
507+
bac.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment");
508+
bac.Headers.ContentDisposition.Name = "file";
509+
bac.Headers.ContentDisposition.FileName = new FileInfo(filepath).Name;
505510
mpc.Add(bac, new FileInfo(filepath).Name);
506511
}
507512
}
@@ -552,7 +557,46 @@ public async Task<RetObject> SendHttp(string uri, HttpMethod method = null, Orde
552557
}
553558
else
554559
{
555-
res = await client.SendAsync((new HttpRequestMessage(method, uri)));
560+
switch (contentType)
561+
{
562+
case @"application/x-www-form-urlencoded":
563+
res = await client.SendAsync(
564+
(new HttpRequestMessage(method, uri)
565+
{
566+
Content = (new StringContent(String.Empty, Encoding.UTF8, contentType))
567+
})
568+
);
569+
break;
570+
case @"multipart/form-data":
571+
MultipartFormDataContent mpc = new MultipartFormDataContent("Boundary----" + DateTime.Now.Ticks.ToString("x"));
572+
if (!String.IsNullOrEmpty(filepath))
573+
{
574+
if (File.Exists(filepath))
575+
{
576+
ByteArrayContent bac = new ByteArrayContent(File.ReadAllBytes(filepath));
577+
bac.Headers.Add("Content-Type", MimeMapping.GetMimeMapping(filepath));
578+
bac.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment");
579+
bac.Headers.ContentDisposition.Name = "file";
580+
bac.Headers.ContentDisposition.FileName = new FileInfo(filepath).Name;
581+
mpc.Add(bac, new FileInfo(filepath).Name);
582+
}
583+
}
584+
if (!String.IsNullOrEmpty(body))
585+
{
586+
StringContent sc = new StringContent(body, Encoding.UTF8, @"application/x-www-form-urlencoded");
587+
mpc.Add(sc);
588+
}
589+
res = await client.SendAsync(
590+
(new HttpRequestMessage(method, uri)
591+
{
592+
Content = mpc
593+
})
594+
);
595+
break;
596+
default:
597+
res = await client.SendAsync((new HttpRequestMessage(method, uri)));
598+
break;
599+
}
556600
if (res.Content.Headers.ContentEncoding.ToString().ToLower().Equals("gzip"))
557601
{
558602
reStream = res.Content.ReadAsByteArrayAsync().Result;

Execute.HttpRequest/Execute.HttpRequest.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<Reference Include="System.ComponentModel.Composition" />
4545
<Reference Include="System.Core" />
4646
<Reference Include="System.Net.Http" />
47+
<Reference Include="System.Web" />
4748
<Reference Include="System.Xml.Linq" />
4849
<Reference Include="System.Data.DataSetExtensions" />
4950
<Reference Include="Microsoft.CSharp" />
@@ -61,6 +62,7 @@
6162
</ItemGroup>
6263
<ItemGroup>
6364
<EmbeddedResource Include="lib\Microsoft.mshtml.dll" />
65+
<EmbeddedResource Include="lib\System.Web.dll" />
6466
<Content Include="packageIcon.ico" />
6567
</ItemGroup>
6668
<ItemGroup>

Execute.HttpRequest/Properties/Resources.Designer.cs

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Execute.HttpRequest/Properties/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,7 @@
121121
<data name="Microsoft_mshtml" type="System.Resources.ResXFileRef, System.Windows.Forms">
122122
<value>..\lib\Microsoft.mshtml.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
123123
</data>
124+
<data name="System_Web" type="System.Resources.ResXFileRef, System.Windows.Forms">
125+
<value>..\lib\System.Web.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
126+
</data>
124127
</root>
5.15 MB
Binary file not shown.

UnitTests/Properties/Resources.Designer.cs

+10-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitTests/Properties/Resources.resx

+3-6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+
<data name="Microsoft_mshtml" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+
<value>..\lib\Microsoft.mshtml.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
123+
</data>
121124
<data name="Microsoft_VisualStudio_TestPlatform_MSTestAdapter_PlatformServices" type="System.Resources.ResXFileRef, System.Windows.Forms">
122125
<value>..\lib\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
123126
</data>
@@ -133,18 +136,12 @@
133136
<data name="Microsoft_VisualStudio_TestPlatform_TestFramework_Extensions" type="System.Resources.ResXFileRef, System.Windows.Forms">
134137
<value>..\lib\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
135138
</data>
136-
<data name="System_Buffers" type="System.Resources.ResXFileRef, System.Windows.Forms">
137-
<value>..\lib\System.Buffers.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
138-
</data>
139139
<data name="System_Memory" type="System.Resources.ResXFileRef, System.Windows.Forms">
140140
<value>..\lib\System.Memory.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
141141
</data>
142142
<data name="System_Net_Http" type="System.Resources.ResXFileRef, System.Windows.Forms">
143143
<value>..\lib\System.Net.Http.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
144144
</data>
145-
<data name="System_Runtime_CompilerServices_Unsafe" type="System.Resources.ResXFileRef, System.Windows.Forms">
146-
<value>..\lib\System.Runtime.CompilerServices.Unsafe.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
147-
</data>
148145
<data name="System_Text_Json" type="System.Resources.ResXFileRef, System.Windows.Forms">
149146
<value>..\lib\System.Text.Json.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
150147
</data>

0 commit comments

Comments
 (0)