Skip to content

Commit dfe57f8

Browse files
committed
Added support for string or string[] formdata src property.
1 parent 371c49b commit dfe57f8

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

src/Collections/Models/FormData.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Postman.NET.Collections.Models
1+
using Newtonsoft.Json.Linq;
2+
using System.Linq;
3+
4+
namespace Postman.NET.Collections.Models
25
{
36
public class FormData
47
{
@@ -10,7 +13,29 @@ public class FormData
1013

1114
public string Type { get; set; }
1215

13-
public string[] Src { get; set; }
16+
/// <summary>
17+
/// String list of file paths.
18+
/// </summary>
19+
public object Src
20+
{
21+
get
22+
{
23+
if (_src is JArray a)
24+
{
25+
return a.Select(x => x.ToString()).ToArray();
26+
}
27+
else if (_src is string s)
28+
{
29+
return new string[] { s };
30+
}
31+
else
32+
{
33+
return _src;
34+
}
35+
}
36+
set => _src = value;
37+
}
38+
private object _src;
1439

1540
public bool Disabled { get; set; }
1641
}

src/Collections/Postman.NET.Collections.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackageId>JeniusApps.Postman.NET</PackageId>
6-
<Version>0.2.3.0-preview</Version>
6+
<Version>0.2.4.0-preview</Version>
77
<Authors>Daniel Paulino</Authors>
88
<Company>JeniusApps</Company>
99
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>

src/Postman.NET.sln

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29519.87
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postman.NET.Collections", "Collections\Postman.NET.Collections.csproj", "{7A638A38-79E8-473B-B5DA-88242BB2F656}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{93977A57-8855-4BBF-8639-658BF4EC831C}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{7A638A38-79E8-473B-B5DA-88242BB2F656}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{7A638A38-79E8-473B-B5DA-88242BB2F656}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{7A638A38-79E8-473B-B5DA-88242BB2F656}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{93977A57-8855-4BBF-8639-658BF4EC831C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{93977A57-8855-4BBF-8639-658BF4EC831C}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{93977A57-8855-4BBF-8639-658BF4EC831C}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{93977A57-8855-4BBF-8639-658BF4EC831C}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
using Postman.NET.Collections.Models;
3+
using Xunit;
4+
5+
namespace Tests.Models
6+
{
7+
public class DeserializationTests
8+
{
9+
[Theory]
10+
[InlineData("{\"src\":[\"/C:/path/to/file.json\",\"/C:/path/to/file.json\"]}")]
11+
[InlineData("{\"src\":[]}")]
12+
[InlineData("{\"src\":\"/C:/path/to/file.json\"}")]
13+
public void FormDataSrc(string json)
14+
{
15+
var item = JsonConvert.DeserializeObject<FormData>(json);
16+
Assert.True(item.Src is string[]);
17+
}
18+
}
19+
}

src/Tests/Tests.csproj

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
11+
<PackageReference Include="xunit" Version="2.4.0" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
13+
<PackageReference Include="coverlet.collector" Version="1.2.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\Collections\Postman.NET.Collections.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

0 commit comments

Comments
 (0)