Skip to content

Commit ea1db5a

Browse files
Adopt Spector payload scenarios (Azure#49751)
* Adopt payload Spector scenarios * regen
1 parent eac4d87 commit ea1db5a

File tree

16 files changed

+4129
-1
lines changed

16 files changed

+4129
-1
lines changed

eng/packages/http-client-csharp/eng/scripts/Generate.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function IsSpecDir {
5353
$failingSpecs = @(
5454
Join-Path 'http' 'payload' 'pageable'
5555
Join-Path 'http' 'payload' 'xml'
56-
Join-Path 'http' 'payload' 'multipart'
5756
Join-Path 'http' 'server' 'path' 'multiple'
5857
Join-Path 'http' 'server' 'versions' 'versioned'
5958
Join-Path 'http' 'versioning' 'added'

eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
"commandName": "Executable",
106106
"executablePath": "dotnet"
107107
},
108+
"http-payload-multipart": {
109+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/payload/multipart -g AzureStubGenerator",
110+
"commandName": "Executable",
111+
"executablePath": "dotnet"
112+
},
108113
"http-serialization-encoded-name-json": {
109114
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/serialization/encoded-name/json -g AzureStubGenerator",
110115
"commandName": "Executable",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using NUnit.Framework;
7+
using Payload.ContentNegotiation;
8+
9+
namespace TestProjects.Spector.Tests.Http.Payload.ContentNegotiation
10+
{
11+
public class ContentNegotiationTests : SpectorTestBase
12+
{
13+
private readonly string _samplePngPath = Path.Combine(SpectorServer.GetSpecDirectory(), "assets", "image.png");
14+
private readonly string _sampleJpgPath = Path.Combine(SpectorServer.GetSpecDirectory(), "assets", "image.jpg");
15+
16+
[SpectorTest]
17+
public Task SameBody() => Test(async (host) =>
18+
{
19+
var response1 = await new ContentNegotiationClient(host, null).GetSameBodyClient().GetAvatarAsPngAsync();
20+
Assert.AreEqual(200, response1.GetRawResponse().Status);
21+
CollectionAssert.AreEqual(File.ReadAllBytes(_samplePngPath), response1.Value.ToArray());
22+
23+
var response2 = await new ContentNegotiationClient(host, null).GetSameBodyClient().GetAvatarAsJpegAsync();
24+
Assert.AreEqual(200, response2.GetRawResponse().Status);
25+
CollectionAssert.AreEqual(File.ReadAllBytes(_sampleJpgPath), response2.Value.ToArray());
26+
});
27+
28+
[SpectorTest]
29+
public Task DifferentBody() => Test(async (host) =>
30+
{
31+
var response1 = await new ContentNegotiationClient(host, null).GetDifferentBodyClient().GetAvatarAsPngAsync();
32+
Assert.AreEqual(200, response1.GetRawResponse().Status);
33+
CollectionAssert.AreEqual(File.ReadAllBytes(_samplePngPath), response1.Value.ToArray());
34+
35+
var response2 = await new ContentNegotiationClient(host, null).GetDifferentBodyClient().GetAvatarAsJsonAsync();
36+
Assert.AreEqual(200, response2.GetRawResponse().Status);
37+
CollectionAssert.AreEqual(File.ReadAllBytes(_samplePngPath), response2.Value.Content.ToArray());
38+
});
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
5+
using System;
6+
using System.Threading.Tasks;
7+
using Azure.Core;
8+
using NUnit.Framework;
9+
using Payload.JsonMergePatch;
10+
11+
namespace TestProjects.Spector.Tests.Http.Payload.JsonMergePatch
12+
{
13+
public class JsonMergePatchTests : SpectorTestBase
14+
{
15+
[SpectorTest]
16+
public Task CreateResource() => Test(async (host) =>
17+
{
18+
var response = await new JsonMergePatchClient(host, null).CreateResourceAsync(new Resource("Madge")
19+
{
20+
Description = "desc",
21+
Map = { { "key", new InnerModel { Name = "InnerMadge", Description = "innerDesc" } } },
22+
Array = { new InnerModel { Name = "InnerMadge", Description = "innerDesc" } },
23+
IntValue = 1,
24+
FloatValue = 1.25f,
25+
InnerModel = new InnerModel { Name = "InnerMadge", Description = "innerDesc" },
26+
IntArray = { 1, 2, 3 }
27+
});
28+
Assert.AreEqual(200, response.GetRawResponse().Status);
29+
});
30+
31+
[SpectorTest]
32+
public Task UpdateOptionalResource() => Test(async (host) =>
33+
{
34+
var response = await new JsonMergePatchClient(host, null).UpdateOptionalResourceAsync(RequestContent.Create(
35+
new BinaryData(
36+
new
37+
{
38+
description = (string?)null,
39+
map = new { key = new { description = (string?)null }, key2 = (string?)null },
40+
array = (object[]?)null,
41+
intValue = (int?)null,
42+
floatValue = (float?)null,
43+
innerModel = (InnerModel?)null,
44+
intArray = (int[]?)null
45+
})));
46+
Assert.AreEqual(200, response.Status);
47+
});
48+
49+
[SpectorTest]
50+
public Task UpdateResource() => Test(async (host) =>
51+
{
52+
var response = await new JsonMergePatchClient(host, null).UpdateResourceAsync(RequestContent.Create(
53+
new BinaryData(
54+
new
55+
{
56+
description = (string?)null,
57+
map = new { key = new { description = (string?)null }, key2 = (string?)null },
58+
array = (object[]?)null,
59+
intValue = (int?)null,
60+
floatValue = (float?)null,
61+
innerModel = (InnerModel?)null,
62+
intArray = (int[]?)null
63+
})));
64+
Assert.AreEqual(200, response.Status);
65+
});
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 Payload.MediaType;
7+
8+
namespace TestProjects.Spector.Tests.Http.Payload.MediaType
9+
{
10+
public class MediaTypeTests : SpectorTestBase
11+
{
12+
[SpectorTest]
13+
public Task SendAsText() => Test(async (host) =>
14+
{
15+
var response1 = await new MediaTypeClient(host, null).GetStringBodyClient().SendAsTextAsync("{cat}");
16+
Assert.AreEqual(200, response1.Status);
17+
});
18+
19+
[SpectorTest]
20+
public Task GetAsText() => Test(async (host) =>
21+
{
22+
var response2 = await new MediaTypeClient(host, null).GetStringBodyClient().GetAsTextAsync();
23+
Assert.AreEqual("{cat}", response2.Value);
24+
});
25+
26+
[SpectorTest]
27+
public Task SendAsJson() => Test(async (host) =>
28+
{
29+
var response3 = await new MediaTypeClient(host, null).GetStringBodyClient().SendAsJsonAsync("foo");
30+
Assert.AreEqual(200, response3.Status);
31+
});
32+
33+
[SpectorTest]
34+
public Task GetAsJson() => Test(async (host) =>
35+
{
36+
var response4 = await new MediaTypeClient(host, null).GetStringBodyClient().GetAsJsonAsync();
37+
Assert.AreEqual("foo", response4.Value);
38+
});
39+
}
40+
}

0 commit comments

Comments
 (0)