|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using NUnit.Framework; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Resiliency.ServiceDriven; |
| 7 | + |
| 8 | +namespace TestProjects.CadlRanch.Tests.Http.Resiliency.SrvDriven |
| 9 | +{ |
| 10 | + public partial class SrvDrivenTests : CadlRanchTestBase |
| 11 | + { |
| 12 | + private const string ServiceDeploymentV1 = "v1"; |
| 13 | + private const string ServiceDeploymentV2 = "v2"; |
| 14 | + |
| 15 | + [CadlRanchTest] |
| 16 | + public Task AddOperation() => Test(async (host) => |
| 17 | + { |
| 18 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2); |
| 19 | + var response = await client.AddOperationAsync(); |
| 20 | + |
| 21 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 22 | + }); |
| 23 | + |
| 24 | + // This test validates the "new" client behavior when the api version is set to V1. |
| 25 | + [CadlRanchTest] |
| 26 | + public Task AddOptionalParamFromNone_WithApiVersionV1() => Test(async (host) => |
| 27 | + { |
| 28 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1); |
| 29 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 30 | + var response = await client.FromNoneAsync(); |
| 31 | + |
| 32 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 33 | + }); |
| 34 | + |
| 35 | + // This test validates the "new" client behavior when the api version is set to V2. |
| 36 | + [CadlRanchTest] |
| 37 | + public Task AddOptionalParamFromNone_WithApiVersionV2() => Test(async (host) => |
| 38 | + { |
| 39 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2); |
| 40 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 41 | + var response = await client.FromNoneAsync("new", cancellationToken: default); |
| 42 | + |
| 43 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 44 | + }); |
| 45 | + |
| 46 | + [CadlRanchTest] |
| 47 | + public Task AddOptionalParamFromOneOptional_WithApiVersionV1() => Test(async (host) => |
| 48 | + { |
| 49 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1); |
| 50 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 51 | + var response = await client.FromOneOptionalAsync("optional"); |
| 52 | + |
| 53 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 54 | + }); |
| 55 | + |
| 56 | + [CadlRanchTest] |
| 57 | + public Task AddOptionalParamFromOneOptional_WithApiVersionV2() => Test(async (host) => |
| 58 | + { |
| 59 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2); |
| 60 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 61 | + var response = await client.FromOneOptionalAsync("optional", "new", cancellationToken: default); |
| 62 | + |
| 63 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 64 | + }); |
| 65 | + |
| 66 | + [CadlRanchTest] |
| 67 | + public Task AddOptionalParamFromOneRequired_WithApiVersionV1() => Test(async (host) => |
| 68 | + { |
| 69 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1); |
| 70 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 71 | + var response = await client.FromOneRequiredAsync("required"); |
| 72 | + |
| 73 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 74 | + }); |
| 75 | + |
| 76 | + [CadlRanchTest] |
| 77 | + public Task AddOptionalParamFromOneRequired_WithApiVersionV2() => Test(async (host) => |
| 78 | + { |
| 79 | + var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2); |
| 80 | + var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options); |
| 81 | + var response = await client.FromOneRequiredAsync("required", "new", cancellationToken: default); |
| 82 | + |
| 83 | + Assert.AreEqual(204, response.GetRawResponse().Status); |
| 84 | + }); |
| 85 | + } |
| 86 | +} |
0 commit comments