Skip to content

Commit b8a3dc7

Browse files
Adopt auth spector scenarios (Azure#49629)
1 parent b6c62bb commit b8a3dc7

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using Authentication.Http.Custom;
6+
using Azure;
7+
using NUnit.Framework;
8+
9+
namespace TestProjects.Spector.Tests.Http.Authentication.Http.Custom
10+
{
11+
internal class CustomAuthTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task Valid() => Test(async (host) =>
15+
{
16+
Response response = await new CustomClient(host, new AzureKeyCredential("valid-key"), null).ValidAsync();
17+
Assert.AreEqual(204, response.Status);
18+
});
19+
20+
[SpectorTest]
21+
public Task Invalid() => Test((host) =>
22+
{
23+
var exception = Assert.ThrowsAsync<RequestFailedException>(() => new CustomClient(host, new AzureKeyCredential("invalid-key"), null).InvalidAsync());
24+
Assert.AreEqual(403, exception!.Status);
25+
return Task.CompletedTask;
26+
});
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using Authentication.Union;
6+
using Azure;
7+
using Azure.Core;
8+
using CadlRanchProjects.Tests;
9+
using NUnit.Framework;
10+
11+
namespace TestProjects.Spector.Tests.Http.Authentication.Union
12+
{
13+
public class AuthenticationUnionTests : SpectorTestBase
14+
{
15+
[Test]
16+
public Task Authentication_Union_validKey() => Test(async (host) =>
17+
{
18+
Response response = await new UnionClient(host, new AzureKeyCredential("valid-key"), null).ValidKeyAsync();
19+
Assert.AreEqual(204, response.Status);
20+
});
21+
22+
[Test]
23+
public Task Authentication_Union_validToken() => Test(async (host) =>
24+
{
25+
var options = new UnionClientOptions();
26+
options.AddPolicy(new OAuth2TestHelper.MockBearerTokenAuthenticationPolicy(new OAuth2TestHelper.MockCredential(), new string[] { "https://security.microsoft.com/.default" }, options.Transport), HttpPipelinePosition.PerCall);
27+
Response response = await new UnionClient(host, new OAuth2TestHelper.MockCredential(), options).ValidTokenAsync();
28+
Assert.AreEqual(204, response.Status);
29+
});
30+
}
31+
}

eng/packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Parameters/BodyOptionality/BodyOptionalityTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.ClientModel;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
24
using System.Threading.Tasks;
35
using Azure;
46
using NUnit.Framework;

0 commit comments

Comments
 (0)