Skip to content

Commit fc89a8e

Browse files
author
Roman Ettlinger
committed
Make existing Methods compatible
1 parent c4f9b48 commit fc89a8e

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/abstractions/MultipartBody.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,21 @@ public void AddOrReplacePart<T>(string partName, string contentType, T partValue
6363
/// <returns>The value of the part.</returns>
6464
public T? GetPartValue<T>(string partName)
6565
{
66-
return GetPartValue<T>(partName, null);
66+
var value = GetPartValue<T>(partName, null);
67+
68+
if(EqualityComparer<T?>.Default.Equals(value, default))
69+
{
70+
foreach(var key in _parts.Keys)
71+
{
72+
if(key.Item1 == partName)
73+
{
74+
value = GetPartValue<T>(partName, key.Item2);
75+
break;
76+
}
77+
}
78+
}
79+
80+
return value;
6781
}
6882
/// <summary>
6983
/// Gets the value of a part from the multipart body.
@@ -95,7 +109,21 @@ public void AddOrReplacePart<T>(string partName, string contentType, T partValue
95109
/// <returns>True if the part was removed, false otherwise.</returns>
96110
public bool RemovePart(string partName)
97111
{
98-
return RemovePart(partName, null);
112+
bool success = RemovePart(partName, null);
113+
114+
if(!success)
115+
{
116+
foreach(var key in _parts.Keys)
117+
{
118+
if(key.Item1 == partName)
119+
{
120+
success = RemovePart(partName, key.Item2);
121+
break;
122+
}
123+
}
124+
}
125+
126+
return success;
99127
}
100128

101129
/// <summary>

tests/abstractions/MultipartBodyTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,16 @@ public void AllowsDuplicateEntries()
114114
}
115115

116116
[Fact]
117-
public void ImplementationBreaksExisting()
117+
public void MultiPartBodyExistingGetAndRemoveStillWork()
118118
{
119119
var body = new MultipartBody();
120120

121121
body.AddOrReplacePart("file", "application/json", "fileContent", "file.json");
122122

123123
// existing usecase, file should still be able to be retreived
124124
Assert.Equal("fileContent", body.GetPartValue<string>("file"));
125+
126+
// existing usecase, file should be sucesfully removed
127+
Assert.True(body.RemovePart("file"));
125128
}
126129
}

0 commit comments

Comments
 (0)