Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the test project to reference cadl ranch source code projects instead of including their source code #5570

Merged
merged 29 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b42a16f
make the test project individually for each cadl ranch project
ArcturusZhang Jan 9, 2025
3b39806
update test cases
ArcturusZhang Jan 10, 2025
722173d
clean up
ArcturusZhang Jan 10, 2025
fbc52f0
Merge remote-tracking branch 'origin/main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 10, 2025
506e47c
Merge branch 'main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 13, 2025
d1a9a9e
fix casing issue
ArcturusZhang Jan 13, 2025
9f8bad1
unify casing
ArcturusZhang Jan 13, 2025
f6eefc1
refresh launchsettings
ArcturusZhang Jan 13, 2025
cc2a6be
Merge branch 'main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 14, 2025
b7a13bf
restore a test case which is actually fine
ArcturusZhang Jan 14, 2025
2ee2ced
clean up
ArcturusZhang Jan 14, 2025
42335a1
clean up the script
ArcturusZhang Jan 14, 2025
8ab119a
revert unnecessary changes
ArcturusZhang Jan 14, 2025
7d57995
fix the test-cadlranch script
ArcturusZhang Jan 14, 2025
884b07f
Merge branch 'main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 14, 2025
f78ba65
regen
ArcturusZhang Jan 14, 2025
1badecd
Merge remote-tracking branch 'origin/main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 16, 2025
693cff1
add parameters/spread back
ArcturusZhang Jan 16, 2025
aa0b6a2
add srv-driven/v2 back
ArcturusZhang Jan 16, 2025
bb81e49
add special-words back
ArcturusZhang Jan 16, 2025
6572d1a
restore launchsettings
ArcturusZhang Jan 16, 2025
1377564
clean up
ArcturusZhang Jan 16, 2025
a9a27da
revert the generate script back
ArcturusZhang Jan 16, 2025
deeec6e
try another way to fix this
ArcturusZhang Jan 16, 2025
5d3b45e
apply a new solution
ArcturusZhang Jan 16, 2025
ef37103
revert some unncessary changes
ArcturusZhang Jan 16, 2025
3c0589d
fix test failures
ArcturusZhang Jan 16, 2025
d2b5e4e
Merge branch 'main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 16, 2025
9b715b2
Merge branch 'main' into isolate-cadl-ranch-cases
ArcturusZhang Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ $azureSpecsDirectory = Join-Path $packageRoot 'node_modules' '@azure-tools' 'azu
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch'
$cadlRanchRootHttp = Join-Path $cadlRanchRoot 'http'
$directories = Get-ChildItem -Path "$cadlRanchRootHttp" -Directory -Recurse
$cadlRanchCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests' 'TestProjects.CadlRanch.Tests.csproj'

$coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage'

Expand Down Expand Up @@ -46,7 +45,7 @@ foreach ($directory in $directories) {
$testFilter += "._$segment"
$testPath = Join-Path $testPath "_$segment"
}
else{
else {
$testFilter += ".$segment"
$testPath = Join-Path $testPath $segment
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Linq;
using System.Threading.Tasks;
using Client.Structure.Service;
using Client.Structure.Service.Models;
using NUnit.Framework;
using System.Linq;
using System.Threading.Tasks;

namespace TestProjects.CadlRanch.Tests.Http.Client.Structure.ClientOperationGroup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Client.Structure.Service.Default;
using Client.Structure.Service.Default.Models;
using Client.Structure.Service.Renamed.Operation;
using NUnit.Framework;

namespace TestProjects.CadlRanch.Tests.Http.Client.Structure.Default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.Globalization;
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Payload.MultiPart;
Expand Down Expand Up @@ -219,5 +225,185 @@ private Task MultiBinaryParts(bool hasPicture) => Test(async (host) =>
var response = await new MultiPartClient(host, null).GetFormDataClient().MultiBinaryPartsAsync(content, content.ContentType, null);
Assert.AreEqual(204, response.GetRawResponse().Status);
});

internal partial class MultiPartFormDataBinaryContent : BinaryContent
ArcturusZhang marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly MultipartFormDataContent _multipartContent;
private static readonly Random _random = new Random();
private static readonly char[] _boundaryValues = "0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".ToCharArray();

public MultiPartFormDataBinaryContent()
{
_multipartContent = new MultipartFormDataContent(CreateBoundary());
}

public string? ContentType
{
get
{
return _multipartContent.Headers.ContentType?.ToString();
}
}

internal HttpContent HttpContent => _multipartContent;

private static string CreateBoundary()
{
Span<char> chars = new char[70];
byte[] random = new byte[70];
_random.NextBytes(random);
int mask = 255 >> 2;
int i = 0;
for (; i < 70; i++)
{
chars[i] = _boundaryValues[random[i] & mask];
}
return chars.ToString();
}

public void Add(string content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

Add(new StringContent(content), name, filename, contentType);
}

public void Add(int content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(long content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(float content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(double content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(decimal content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(bool content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

string value = content ? "true" : "false";
Add(new StringContent(value), name, filename, contentType);
}

public void Add(Stream content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

Add(new StreamContent(content), name, filename, contentType);
}

public void Add(byte[] content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

Add(new ByteArrayContent(content), name, filename, contentType);
}

public void Add(BinaryData content, string name, string? filename = default, string? contentType = default)
{
ArgumentNullException.ThrowIfNull(content, nameof(content));
ArgumentNullException.ThrowIfNullOrEmpty(name, nameof(name));

Add(new ByteArrayContent(content.ToArray()), name, filename, contentType);
}

private void Add(HttpContent content, string name, string? filename, string? contentType)
{
if (contentType != null)
{
ArgumentNullException.ThrowIfNullOrEmpty(contentType, nameof(contentType));
AddContentTypeHeader(content, contentType);
}
if (filename != null)
{
ArgumentNullException.ThrowIfNullOrEmpty(filename, nameof(filename));
_multipartContent.Add(content, name, filename);
}
else
{
_multipartContent.Add(content, name);
}
}

public static void AddContentTypeHeader(HttpContent content, string contentType)
{
MediaTypeHeaderValue header = new MediaTypeHeaderValue(contentType);
content.Headers.ContentType = header;
}

public override bool TryComputeLength(out long length)
{
if (_multipartContent.Headers.ContentLength is long contentLength)
{
length = contentLength;
return true;
}
length = 0;
return false;
}

public override void WriteTo(Stream stream, CancellationToken cancellationToken = default)
{
#if NET6_0_OR_GREATER
_multipartContent.CopyTo(stream, default, cancellationToken);
#else
_multipartContent.CopyToAsync(stream).GetAwaiter().GetResult();
#endif
}

public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default)
{
#if NET6_0_OR_GREATER
await _multipartContent.CopyToAsync(stream).ConfigureAwait(false);
#else
await _multipartContent.CopyToAsync(stream).ConfigureAwait(false);
#endif
}

public override void Dispose()
{
_multipartContent.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using NUnit.Framework;
extern alias VersioningAddedV1;

using System;
using System.Linq;
using Versioning.Added.V1;
using Versioning.Added.V1.Models;
using NUnit.Framework;
using VersioningAddedV1::Versioning.Added.V1;
using VersioningAddedV1::Versioning.Added.V1.Models;

namespace TestProjects.CadlRanch.Tests.Http.Versioning.Added.V1
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using NUnit.Framework;
extern alias VersioningAddedV2;

using System;
using System.Linq;
using Versioning.Added.V2;
using Versioning.Added.V2.Models;
using System.Threading.Tasks;
using NUnit.Framework;
using VersioningAddedV2::Versioning.Added.V2;
using VersioningAddedV2::Versioning.Added.V2.Models;

namespace TestProjects.CadlRanch.Tests.Http.Versioning.Added.V2
{
Expand All @@ -31,10 +33,12 @@ public void TestAddedMembersV2Client()
Assert.IsTrue(enumValues.Contains("EnumMemberV2"));

/* check existence of the added model ModelV2. */
Assert.IsNotNull(Type.GetType("Versioning.Added.V2.Models.ModelV2"));
var modelV2Type = typeof(ModelV1).Assembly.GetType("Versioning.Added.V2.Models.ModelV2");
Assert.IsNotNull(modelV2Type);

/* check existence of the added enum EnumV2. */
Assert.IsNotNull(Type.GetType("Versioning.Added.V2.Models.EnumV2"));
var enumV2Type = typeof(ModelV1).Assembly.GetType("Versioning.Added.V2.Models.EnumV2");
Assert.IsNotNull(enumV2Type);

/* check the added parameter. */
var methods = typeof(AddedClient).GetMethods().Where(m => m.Name == "V1" || m.Name == "V1Async");
Expand All @@ -52,7 +56,8 @@ public void TestAddedMembersV2Client()
Assert.AreEqual(4, addedMethods.Count());

/* check the existence of added interface in V2. */
Assert.IsNotNull(Type.GetType("Versioning.Added.V2.InterfaceV2"));
var interfaceV2Type = typeof(ModelV1).Assembly.GetType("Versioning.Added.V2.InterfaceV2");
Assert.IsNotNull(interfaceV2Type);
}

[CadlRanchTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public class VersioningRemovedV1Tests : CadlRanchTestBase
[CadlRanchTest]
public void TestRemovedMembers()
{
var assembly = typeof(RemovedClient).Assembly;
/* check existence of the removed model ModelV1. */
Assert.IsNotNull(Type.GetType("Versioning.Removed.V1.Models.ModelV1"));
var modelV1Type = assembly.GetType("Versioning.Removed.V1.Models.ModelV1");
Assert.IsNotNull(modelV1Type);

/* check existence of the removed enum EnumV1. */
Assert.IsNotNull(Type.GetType("Versioning.Removed.V1.Models.EnumV1"));
var enumV1Type = assembly.GetType("Versioning.Removed.V1.Models.EnumV1");
Assert.IsNotNull(enumV1Type);

/* check existence of removed method V1 */
var removedMethods = typeof(RemovedClient).GetMethods().Where(m => m.Name == "V1" || m.Name == "V1Async");
Expand All @@ -35,7 +38,8 @@ public void TestRemovedMembers()
}

/* check existence of removed interface. */
Assert.IsNotNull(Type.GetType("Versioning.Removed.V1.InterfaceV1"));
var interfaceV1Type = assembly.GetType("Versioning.Removed.V1.InterfaceV1");
Assert.IsNotNull(interfaceV1Type);

// Only initial versions is defined
var enumType = typeof(RemovedClientOptions.ServiceVersion);
Expand Down

This file was deleted.

Loading
Loading