Skip to content

Commit

Permalink
Support non-kebab-case directories for cadl-ranch scenarios (microsof…
Browse files Browse the repository at this point in the history
…t#5286)

Fixes microsoft#5287

Follow up to microsoft#5273. The
directories defined in cadl-ranch spec for the versioning scenarios do
not use kebab-case which led to our test attribute skipping the tests.

Also adds one missing scenario for versioning.
  • Loading branch information
JoshLove-msft authored and Mingzhe Huang (from Dev Box) committed Dec 17, 2024
1 parent 74affd3 commit d5fc978
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Versioning.Removed.V1;
using Versioning.Removed.V1.Models;

namespace TestProjects.CadlRanch.Tests.Http.Versioning.Removed.V1
{
Expand Down Expand Up @@ -39,5 +41,15 @@ public void TestRemovedMembers()
var enumType = typeof(RemovedClientOptions.ServiceVersion);
Assert.AreEqual(new string[] { "V1" }, enumType.GetEnumNames());
}

[CadlRanchTest]
public Task Versioning_Removed_V3Model() => Test(async (host) =>
{
var model = new ModelV3("123", EnumV3.EnumMemberV1);
var response = await new RemovedClient(host).ModelV3Async(model);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual("123", response.Value.Id);
Assert.AreEqual(EnumV3.EnumMemberV1, response.Value.EnumProp);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ internal partial class CadlRanchTestAttribute : TestAttribute, IApplyToTest
{
string clientCodeDirectory = GetGeneratedDirectory(test);

if (!Directory.Exists(clientCodeDirectory))
{
// Not all cadl-ranch scenarios use kebab-case directories, so try again without kebab-case.
clientCodeDirectory = GetGeneratedDirectory(test, false);
}

var clientCsFile = GetClientCsFile(clientCodeDirectory);

TestContext.Progress.WriteLine($"Checking if '{clientCsFile}' is a stubbed implementation.");
Expand Down Expand Up @@ -69,14 +75,14 @@ private static void SkipTest(Test test)
.FirstOrDefault();
}

private static string GetGeneratedDirectory(Test test)
private static string GetGeneratedDirectory(Test test, bool kebabCaseDirectories = true)
{
var namespaceParts = test.FullName.Split('.').Skip(3);
namespaceParts = namespaceParts.Take(namespaceParts.Count() - 2);
var clientCodeDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "..", "..", "TestProjects", "CadlRanch");
foreach (var part in namespaceParts)
{
clientCodeDirectory = Path.Combine(clientCodeDirectory, FixName(part));
clientCodeDirectory = Path.Combine(clientCodeDirectory, kebabCaseDirectories ? FixName(part) : part);
}
return Path.Combine(clientCodeDirectory, "src", "Generated");
}
Expand Down

0 comments on commit d5fc978

Please sign in to comment.