Skip to content

Commit

Permalink
make the test project individually for each cadl ranch project
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Jan 10, 2025
1 parent fd933a7 commit a544bef
Show file tree
Hide file tree
Showing 34 changed files with 526 additions and 165 deletions.
2 changes: 1 addition & 1 deletion packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ $failingSpecs = @(
Join-Path 'http' 'payload' 'xml'
Join-Path 'http' 'type' 'model' 'flatten'
Join-Path 'http' 'type' 'model' 'templated'
Join-Path 'http' 'client' 'naming'
)

$azureAllowSpecs = @(
Join-Path 'http' 'client' 'naming'
Join-Path 'http' 'client' 'structure' 'client-operation-group'
Join-Path 'http' 'client' 'structure' 'default'
Join-Path 'http' 'client' 'structure' 'multi-client'
Expand Down
17 changes: 14 additions & 3 deletions packages/http-client-csharp/eng/scripts/Get-CadlRanch-Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ $specsDirectory = Join-Path $packageRoot 'node_modules' '@typespec' 'http-specs'
$azureSpecsDirectory = Join-Path $packageRoot 'node_modules' '@azure-tools' 'azure-http-specs' 'specs'
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch' 'http'
$directories = Get-ChildItem -Path "$cadlRanchRoot" -Directory -Recurse
$cadlRanchCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests' 'TestProjects.CadlRanch.Tests.csproj'
$cadlRanchTestDir = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests'
# Get all .csproj files recursively
$csprojFiles = Get-ChildItem -Path $cadlRanchTestDir -Recurse -Filter *.csproj

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

Expand Down Expand Up @@ -67,8 +69,17 @@ foreach ($directory in $directories) {

# test all
Write-Host "Generating CadlRanch coverage" -ForegroundColor Cyan
$command = "dotnet test $cadlRanchCsproj"
Invoke $command

foreach ($csprojFile in $csprojFiles) {
Write-Host "Testing $csprojFile" -ForegroundColor Cyan
$command = "dotnet test $csprojFile"
Invoke $command
# exit if the testing failed
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}

# exit if the testing failed
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Configuration
"Type",
"Array",
"Enum",
"ClientModel", // segment of `System.ClientModel`
];

internal enum UnreferencedTypesHandlingOption
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\authentication\api-key\src\Authentication.ApiKey.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\authentication\http\custom\src\Authentication.Http.Custom.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<!-- <ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\naming\src\Client.Naming.csproj" /> -->
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//using System.Threading.Tasks;
//using Client.Naming;
//using Client.Naming.Model;
//using Client.Naming.Property;
//using NUnit.Framework;
//using ClientModel = Client.Naming.Model.ClientModel;
// using System.Threading.Tasks;
// using Client.Naming;
// using Client.Naming.Model;
// using Client.Naming.Property;
// using NUnit.Framework;
// using ClientModel = Client.Naming.Model.ClientModel;

//namespace TestProjects.CadlRanch.Tests.Http.Client.Naming
//{
// public class ClientNamingTests : CadlRanchTestBase
// {
// [CadlRanchTest]
// public Task Client() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ClientAsync(new ClientNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// namespace TestProjects.CadlRanch.Tests.Http.Client.Naming
// {
// public class ClientNamingTests : CadlRanchTestBase
// {
// [CadlRanchTest]
// public Task Client() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ClientAsync(new ClientNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);

// Assert.NotNull(typeof(ClientNameModel).GetProperty("ClientName"));
// Assert.IsNull(typeof(ClientNameModel).GetProperty("DefaultName"));
// });
// Assert.NotNull(typeof(ClientNameModel).GetProperty("ClientName"));
// Assert.IsNull(typeof(ClientNameModel).GetProperty("DefaultName"));
// });

// [CadlRanchTest]
// public Task Language() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).LanguageAsync(new LanguageClientNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// [CadlRanchTest]
// public Task Language() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).LanguageAsync(new LanguageClientNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);

// Assert.NotNull(typeof(LanguageClientNameModel).GetProperty("CSName"));
// Assert.IsNull(typeof(LanguageClientNameModel).GetProperty("DefaultName"));
// });
// Assert.NotNull(typeof(LanguageClientNameModel).GetProperty("CSName"));
// Assert.IsNull(typeof(LanguageClientNameModel).GetProperty("DefaultName"));
// });

// [CadlRanchTest]
// public Task CompatibleWithEncodedName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).CompatibleWithEncodedNameAsync(new ClientNameAndJsonEncodedNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// [CadlRanchTest]
// public Task CompatibleWithEncodedName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).CompatibleWithEncodedNameAsync(new ClientNameAndJsonEncodedNameModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);

// Assert.NotNull(typeof(ClientNameModel).GetProperty("ClientName"));
// Assert.IsNull(typeof(ClientNameModel).GetProperty("DefaultName"));
// });
// Assert.NotNull(typeof(ClientNameModel).GetProperty("ClientName"));
// Assert.IsNull(typeof(ClientNameModel).GetProperty("DefaultName"));
// });

// [CadlRanchTest]
// public Task Operation() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ClientNameAsync();
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task Operation() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ClientNameAsync();
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task Parameter() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ParameterAsync(clientName: "true");
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task Parameter() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ParameterAsync(clientName: "true");
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task Request() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).RequestAsync(clientName: "true");
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task Request() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).RequestAsync(clientName: "true");
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task Response() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ResponseAsync();
// Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("default-name", out _));
// foreach (var header in response.GetRawResponse().Headers)
// {
// var key = header.Key;
// if (key == "default-name")
// {
// var value = header.Value;
// Assert.AreEqual("true", value);
// }
// }
// });
// [CadlRanchTest]
// public Task Response() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).ResponseAsync();
// Assert.IsTrue(response.GetRawResponse().Headers.TryGetValue("default-name", out _));
// foreach (var header in response.GetRawResponse().Headers)
// {
// var key = header.Key;
// if (key == "default-name")
// {
// var value = header.Value;
// Assert.AreEqual("true", value);
// }
// }
// });

// [CadlRanchTest]
// public Task ModelClient() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetClientModelClient().ClientAsync(new ClientModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task ModelClient() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetClientModelClient().ClientAsync(new ClientModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task ModelLanguage() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetClientModelClient().LanguageAsync(new CSModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task ModelLanguage() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetClientModelClient().LanguageAsync(new CSModel(true));
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task UnionEnumName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetUnionEnumClient().UnionEnumNameAsync(ClientExtensibleEnum.EnumValue1);
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// [CadlRanchTest]
// public Task UnionEnumName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetUnionEnumClient().UnionEnumNameAsync(ClientExtensibleEnum.EnumValue1);
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });

// [CadlRanchTest]
// public Task UnionEnumMemberName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetUnionEnumClient().UnionEnumMemberNameAsync(ExtensibleEnum.ClientEnumValue1);
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// }
//}
// [CadlRanchTest]
// public Task UnionEnumMemberName() => Test(async (host) =>
// {
// var response = await new NamingClient(host, null).GetUnionEnumClient().UnionEnumMemberNameAsync(ExtensibleEnum.ClientEnumValue1);
// Assert.AreEqual(204, response.GetRawResponse().Status);
// });
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\structure\client-operation-group\src\Client.Structure.Service.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

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

namespace TestProjects.CadlRanch.Tests.Http.Client.Structure.ClientOperationGroup
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\structure\default\src\Client.Structure.Service.Default.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\structure\multi-client\src\Client.Structure.Service.MultiClient.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\structure\renamed-operation\src\Client.Structure.Service.RenamedOperation.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\Microsoft.Generator.CSharp\test\common\Microsoft.Generator.CSharp.Tests.Common.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch\http\client\structure\two-operation-group\src\Client.Structure.Service.TwoOperationGroup.csproj" />
<ProjectReference Include="$(RepoRoot)\TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit a544bef

Please sign in to comment.