Skip to content

Commit c7dcb11

Browse files
Adopt special-headers and serialization spector scenarios (Azure#50471)
* Adopt special-headers and serialization spector scenarios * fix csproj
1 parent b441f8e commit c7dcb11

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

eng/packages/http-client-csharp/generator/TestProjects/Local.Tests/TestProjects.Local.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
<ItemGroup>
99
<PackageReference Include="Azure.Core" />
1010
<PackageReference Include="Azure.ResourceManager" />
11-
<PackageReference Include="System.ClientModel" />
1211
<PackageReference Include="NUnit" />
1312
<PackageReference Include="NUnit3TestAdapter" />
1413
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1514
</ItemGroup>
16-
15+
1716
<ItemGroup>
1817
<None Remove="./**/*.*" />
1918
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using NUnit.Framework;
6+
using Serialization.EncodedName.Json;
7+
using Serialization.EncodedName.Json._Property;
8+
9+
namespace TestProjects.Spector.Tests.Http.Serialization.EncodedName.Json
10+
{
11+
public class EncodedNameJsonTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task PropertySend() => Test(async (host) =>
15+
{
16+
var response = await new JsonClient(host, null).GetPropertyClient().SendAsync(new JsonEncodedNameModel(true));
17+
Assert.AreEqual(204, response.Status);
18+
});
19+
20+
[SpectorTest]
21+
public Task PropertyGet() => Test(async (host) =>
22+
{
23+
var response = await new JsonClient(host, null).GetPropertyClient().GetAsync();
24+
25+
Assert.AreEqual(200, response.GetRawResponse().Status);
26+
Assert.IsTrue(response.Value.DefaultName);
27+
});
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using NUnit.Framework;
7+
using SpecialHeaders.ConditionalRequest;
8+
9+
namespace TestProjects.Spector.Tests.Http.SpecialHeaders.ConditionalRequest
10+
{
11+
public class ConditionalRequestHeaderTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task Special_Headers_Conditional_Request_PostIfMatch() => Test(async (host) =>
15+
{
16+
string ifMatch = "\"valid\"";
17+
var response = await new ConditionalRequestClient(host, null).PostIfMatchAsync(ifMatch);
18+
Assert.AreEqual(204, response.Status);
19+
});
20+
21+
[SpectorTest]
22+
public Task Special_Headers_Conditional_Request_PostIfNoneMatch() => Test(async (host) =>
23+
{
24+
string ifNoneMatch = "\"invalid\"";
25+
var response = await new ConditionalRequestClient(host, null).PostIfNoneMatchAsync(ifNoneMatch);
26+
Assert.AreEqual(204, response.Status);
27+
});
28+
29+
[SpectorTest]
30+
public Task Special_Headers_Conditional_Request_HeadIfModifiedSince() => Test(async (host) =>
31+
{
32+
DateTimeOffset ifModifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
33+
var response = await new ConditionalRequestClient(host, null).HeadIfModifiedSinceAsync(ifModifiedSince);
34+
Assert.AreEqual(204, response.Status);
35+
});
36+
37+
[SpectorTest]
38+
public Task Special_Headers_Conditional_Request_PostIfUnmodifiedSince() => Test(async (host) =>
39+
{
40+
DateTimeOffset ifUnmodifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
41+
var response = await new ConditionalRequestClient(host, null).PostIfUnmodifiedSinceAsync(ifUnmodifiedSince);
42+
Assert.AreEqual(204, response.Status);
43+
});
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using NUnit.Framework;
5+
using SpecialHeaders.Repeatability;
6+
using System.Reflection;
7+
using System.Threading.Tasks;
8+
using System.Linq;
9+
10+
namespace TestProjects.Spector.Tests.Http.SpecialHeaders.Repeatability
11+
{
12+
public class RepeatabilityTests : SpectorTestBase
13+
{
14+
[SpectorTest]
15+
public Task ImmediateSuccess() => Test(async (host) =>
16+
{
17+
var response = await new RepeatabilityClient(host, null).ImmediateSuccessAsync();
18+
19+
Assert.AreEqual(204, response.Status);
20+
Assert.IsTrue(response.Headers.TryGetValue("repeatability-result", out var headerValue));
21+
Assert.AreEqual("accepted", headerValue);
22+
});
23+
24+
[Test]
25+
public void RepeatabilityHeadersNotInMethodSignature()
26+
{
27+
var methods = typeof(RepeatabilityClient).GetMethods(BindingFlags.Public | BindingFlags.Instance)
28+
.Where(m => m.Name.StartsWith("ImmediateSuccess"));
29+
30+
Assert.IsNotEmpty(methods);
31+
foreach (var m in methods)
32+
{
33+
Assert.False(m.GetParameters().Any(p => p.Name == "repeatabilityRequestId" || p.Name == "repeatabilityFirstSent"));
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)