Skip to content

Commit d4df122

Browse files
committed
Add AccessConditionWrapper.GenerateIfNoneMatchCondition (#6762)
Progress on #6449
1 parent 776d4e0 commit d4df122

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/NuGetGallery.Core/Services/AccessConditionWrapper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public static IAccessCondition GenerateIfMatchCondition(string etag)
3131
ifMatchETag: AccessCondition.GenerateIfMatchCondition(etag).IfMatchETag);
3232
}
3333

34+
public static IAccessCondition GenerateIfNoneMatchCondition(string etag)
35+
{
36+
return new AccessConditionWrapper(
37+
ifNoneMatchETag: AccessCondition.GenerateIfNoneMatchCondition(etag).IfNoneMatchETag,
38+
ifMatchETag: null);
39+
}
40+
3441
public static IAccessCondition GenerateIfNotExistsCondition()
3542
{
3643
return new AccessConditionWrapper(

tests/NuGetGallery.Core.Facts/Services/AccessConditionWrapperFacts.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Collections.Generic;
45
using Xunit;
56

67
namespace NuGetGallery.Services
78
{
89
public class AccessConditionWrapperFacts
910
{
1011
[Theory]
11-
[InlineData("*")]
12-
[InlineData("\"some-etag\"")]
13-
[InlineData("no quotes")]
14-
[InlineData("")]
15-
[InlineData(null)]
12+
[MemberData(nameof(ETags))]
1613
public void GenerateIfMatchCondition(string etag)
1714
{
1815
var actual = AccessConditionWrapper.GenerateIfMatchCondition(etag);
@@ -21,6 +18,16 @@ public void GenerateIfMatchCondition(string etag)
2118
Assert.Null(actual.IfNoneMatchETag);
2219
}
2320

21+
[Theory]
22+
[MemberData(nameof(ETags))]
23+
public void GenerateIfNoneMatchCondition(string etag)
24+
{
25+
var actual = AccessConditionWrapper.GenerateIfNoneMatchCondition(etag);
26+
27+
Assert.Null(actual.IfMatchETag);
28+
Assert.Equal(etag, actual.IfNoneMatchETag);
29+
}
30+
2431
[Fact]
2532
public void GenerateIfNotExistsCondition()
2633
{
@@ -38,5 +45,14 @@ public void GenerateEmptyCondition()
3845
Assert.Null(actual.IfMatchETag);
3946
Assert.Null(actual.IfNoneMatchETag);
4047
}
48+
49+
public static IEnumerable<object[]> ETags => new[]
50+
{
51+
new object[] { "*" },
52+
new object[] { "\"some-etag\"" },
53+
new object[] { "no quotes" },
54+
new object[] { "" },
55+
new object[] { null },
56+
};
4157
}
4258
}

0 commit comments

Comments
 (0)