Skip to content

Commit 3ab44b5

Browse files
committed
Fix tests
1 parent 035a863 commit 3ab44b5

File tree

4 files changed

+73
-18
lines changed

4 files changed

+73
-18
lines changed

src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpointProperty.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static void PopulateFromMetadataValue(string value, List<StaticWebAssetEn
4343
{
4444
properties.Clear();
4545

46+
properties.Clear();
4647
if (string.IsNullOrEmpty(value))
4748
{
4849
return;

test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointPropertyTest.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void PopulateFromMetadataValue_MixedProperties_HandlesCorrectly()
128128
}
129129

130130
[Fact]
131-
public void PopulateFromMetadataValue_ExistingList_AppendsToList()
131+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_BeforeAppendingElements()
132132
{
133133
// Arrange
134134
var json = """[{"Name":"label","Value":"new-value"}]""";
@@ -141,11 +141,29 @@ public void PopulateFromMetadataValue_ExistingList_AppendsToList()
141141
StaticWebAssetEndpointProperty.PopulateFromMetadataValue(json, properties);
142142

143143
// Assert
144-
properties.Should().HaveCount(2);
145-
properties[0].Name.Should().Be("existing");
146-
properties[0].Value.Should().Be("existing-value");
147-
properties[1].Name.Should().Be("label");
148-
properties[1].Value.Should().Be("new-value");
144+
properties.Should().HaveCount(1);
145+
properties[0].Name.Should().Be("label");
146+
properties[0].Value.Should().Be("new-value");
147+
}
148+
149+
[Fact]
150+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_ValidatesClearingBehavior()
151+
{
152+
// Arrange
153+
var json = """[{"Name":"newProp","Value":"newValue"}]""";
154+
var properties = new List<StaticWebAssetEndpointProperty>
155+
{
156+
new() { Name = "existing1", Value = "existingValue1" },
157+
new() { Name = "existing2", Value = "existingValue2" }
158+
};
159+
160+
// Act
161+
StaticWebAssetEndpointProperty.PopulateFromMetadataValue(json, properties);
162+
163+
// Assert - List should be cleared and contain only the new property
164+
properties.Should().HaveCount(1);
165+
properties[0].Name.Should().Be("newProp");
166+
properties[0].Value.Should().Be("newValue");
149167
}
150168

151169
[Fact]

test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointResponseHeaderTest.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void PopulateFromMetadataValue_MixedHeaders_HandlesCorrectly()
150150
}
151151

152152
[Fact]
153-
public void PopulateFromMetadataValue_ExistingList_AppendsToList()
153+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_BeforeAppendingElements()
154154
{
155155
// Arrange
156156
var json = """[{"Name":"Content-Type","Value":"application/json"}]""";
@@ -163,11 +163,29 @@ public void PopulateFromMetadataValue_ExistingList_AppendsToList()
163163
StaticWebAssetEndpointResponseHeader.PopulateFromMetadataValue(json, headers);
164164

165165
// Assert
166-
headers.Should().HaveCount(2);
167-
headers[0].Name.Should().Be("X-Existing");
168-
headers[0].Value.Should().Be("existing-value");
169-
headers[1].Name.Should().Be("Content-Type");
170-
headers[1].Value.Should().Be("application/json");
166+
headers.Should().HaveCount(1);
167+
headers[0].Name.Should().Be("Content-Type");
168+
headers[0].Value.Should().Be("application/json");
169+
}
170+
171+
[Fact]
172+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_ValidatesClearingBehavior()
173+
{
174+
// Arrange
175+
var json = """[{"Name":"X-Custom","Value":"custom-value"}]""";
176+
var headers = new List<StaticWebAssetEndpointResponseHeader>
177+
{
178+
new() { Name = "Content-Type", Value = "text/html" },
179+
new() { Name = "Cache-Control", Value = "max-age=3600" }
180+
};
181+
182+
// Act
183+
StaticWebAssetEndpointResponseHeader.PopulateFromMetadataValue(json, headers);
184+
185+
// Assert - List should be cleared and contain only the new header
186+
headers.Should().HaveCount(1);
187+
headers[0].Name.Should().Be("X-Custom");
188+
headers[0].Value.Should().Be("custom-value");
171189
}
172190

173191
[Fact]

test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointSelectorTest.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void PopulateFromMetadataValue_MixedSelectors_HandlesCorrectly()
149149
}
150150

151151
[Fact]
152-
public void PopulateFromMetadataValue_ExistingList_AppendsToList()
152+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_BeforeAppendingElements()
153153
{
154154
// Arrange
155155
var json = """[{"Name":"Content-Encoding","Value":"gzip"}]""";
@@ -162,11 +162,29 @@ public void PopulateFromMetadataValue_ExistingList_AppendsToList()
162162
StaticWebAssetEndpointSelector.PopulateFromMetadataValue(json, selectors);
163163

164164
// Assert
165-
selectors.Should().HaveCount(2);
166-
selectors[0].Name.Should().Be("Existing-Selector");
167-
selectors[0].Value.Should().Be("existing-value");
168-
selectors[1].Name.Should().Be("Content-Encoding");
169-
selectors[1].Value.Should().Be("gzip");
165+
selectors.Should().HaveCount(1);
166+
selectors[0].Name.Should().Be("Content-Encoding");
167+
selectors[0].Value.Should().Be("gzip");
168+
}
169+
170+
[Fact]
171+
public void PopulateFromMetadataValue_ExistingList_ClearsExistingItems_ValidatesClearingBehavior()
172+
{
173+
// Arrange
174+
var json = """[{"Name":"Accept-Encoding","Value":"br"}]""";
175+
var selectors = new List<StaticWebAssetEndpointSelector>
176+
{
177+
new() { Name = "Content-Encoding", Value = "gzip" },
178+
new() { Name = "Content-Type", Value = "text/css" }
179+
};
180+
181+
// Act
182+
StaticWebAssetEndpointSelector.PopulateFromMetadataValue(json, selectors);
183+
184+
// Assert - List should be cleared and contain only the new selector
185+
selectors.Should().HaveCount(1);
186+
selectors[0].Name.Should().Be("Accept-Encoding");
187+
selectors[0].Value.Should().Be("br");
170188
}
171189

172190
[Fact]

0 commit comments

Comments
 (0)