Fix to https://github.com/microsoft/typespec/pull/4301. The PR was
updated to always keep Union models, so we don't need the reflection
workaround.
This commit is contained in:
JoshLove-msft 2024-09-04 16:43:54 -07:00 коммит произвёл GitHub
Родитель b645fb3d6d
Коммит 244dbc08c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 3 добавлений и 14 удалений

Просмотреть файл

@ -100,21 +100,10 @@ namespace TestProjects.CadlRanch.Tests.Http._Type.Union
[CadlRanchTest]
public Task SendModelsOnly() => Test(async (host) =>
{
var response = await new UnionClient(host, null).GetModelsOnlyClient().SendAsync(WriteCat());
var response = await new UnionClient(host, null).GetModelsOnlyClient().SendAsync(ModelReaderWriter.Write(new Cat("test")));
Assert.AreEqual(204, response.GetRawResponse().Status);
});
private static BinaryData WriteCat()
{
// We need to use reflection because the Cat model gets deleted in Stubbed mode which is what we check in.
// The type will exist when actually running the test using the ClientModelPlugin.
var catType = typeof(UnionClient).Assembly.GetType("_Type.Union.Models.Cat");
Debug.Assert(catType != null);
var cat = Activator.CreateInstance(catType, "test");
return ModelReaderWriter.Write(cat!);
}
[CadlRanchTest]
public Task GetEnumsOnly() => Test(async (host) =>
{
@ -184,13 +173,13 @@ namespace TestProjects.CadlRanch.Tests.Http._Type.Union
public Task SendMixedTypesOnlyOnly() => Test(async (host) =>
{
var response = await new UnionClient(host, null).GetMixedTypesClient().SendAsync(new MixedTypesCases(
WriteCat(),
ModelReaderWriter.Write(new Cat("test")),
BinaryData.FromObjectAsJson("a"),
BinaryData.FromObjectAsJson(2),
BinaryData.FromObjectAsJson(true),
new[]
{
WriteCat(),
ModelReaderWriter.Write(new Cat("test")),
BinaryData.FromObjectAsJson("a"),
BinaryData.FromObjectAsJson(2),
BinaryData.FromObjectAsJson(true)