Skip to content

Commit

Permalink
[http-client-csharp] onboard http\specialwords (#5132)
Browse files Browse the repository at this point in the history
fixes: #5100
  • Loading branch information
jorgerangel-msft authored Nov 15, 2024
1 parent 08bda52 commit f080aec
Show file tree
Hide file tree
Showing 86 changed files with 9,961 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function IsSpecDir {
}

$failingSpecs = @(
Join-Path 'http' 'special-words'
Join-Path 'http' 'payload' 'json-merge-patch'
Join-Path 'http' 'payload' 'pageable'
Join-Path 'http' 'resiliency' 'srv-driven'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-special-words": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/special-words -p StubLibraryPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-type-array": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/type/array -p StubLibraryPlugin",
"commandName": "Executable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ private PropertyProvider(InputModelProperty inputProperty, CSharpType propertyTy

Type = inputProperty.IsReadOnly ? propertyType.OutputType : propertyType;
Modifiers = inputProperty.IsDiscriminator ? MethodSignatureModifiers.Internal : MethodSignatureModifiers.Public;
Name = inputProperty.Name.ToCleanName();
Name = inputProperty.Name == enclosingType.Name
? $"{inputProperty.Name.ToCleanName()}Property"
: inputProperty.Name.ToCleanName();
Body = new AutoPropertyBody(propHasSetter, setterModifier, GetPropertyInitializationValue(propertyType, inputProperty));
Description = string.IsNullOrEmpty(inputProperty.Description) ? PropertyDescriptionBuilder.CreateDefaultPropertyDescription(Name, !Body.HasSetter) : $"{inputProperty.Description}";
XmlDocSummary = PropertyDescriptionBuilder.BuildPropertyDescription(inputProperty, propertyType, serializationFormat, Description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace Microsoft.Generator.CSharp.Tests.Providers
{
public class PropertyProviderTests
{
public PropertyProviderTests()
[SetUp]
public void SetUp()
{
MockHelpers.LoadMockPlugin();
}
Expand Down Expand Up @@ -107,6 +108,18 @@ public void AsParameterRespectsChangesToPropertyType()
Assert.IsTrue(parameter.Type.Equals(typeof(int)));
}

[Test]
public void TestSpecialWords()
{
var testTypeProvider = new TestTypeProvider();
var inputPropertyName = testTypeProvider.Name;
InputModelProperty inputModelProperty = InputFactory.Property(inputPropertyName, InputPrimitiveType.String);
InputFactory.Model("TestModel", properties: [inputModelProperty]);

var property = new PropertyProvider(inputModelProperty, testTypeProvider);
Assert.AreEqual(inputPropertyName.ToCleanName() + "Property", property.Name);
}

private static IEnumerable<TestCaseData> CollectionPropertyTestCases()
{
// List<string> -> IReadOnlyList<string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using NUnit.Framework;
using SpecialWords;
using SpecialWords.Models;
using SpecialWordsAssert = SpecialWords.Models.Assert;
using SpecialWordsIs = SpecialWords.Models.Is;

namespace TestProjects.CadlRanch.Tests.Http.SpecialWords
{
public partial class SpecialWordsTests : CadlRanchTestBase
{
[CadlRanchTest]
public Task ModelsWithAndAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithAndAsync(new And("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithAsAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithAsAsync(new As("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithAssertAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithAssertAsync(new SpecialWordsAssert("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithAsyncAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithAsyncAsync(new Async("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithAwaitAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithAwaitAsync(new Await("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithBreakAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithBreakAsync(new Break("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithClassAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithClassAsync(new Class("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithConstructorAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithConstructorAsync(new Constructor("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithContinueAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithContinueAsync(new Continue("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithDefAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithDefAsync(new Def("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithDelAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithDelAsync(new Del("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithElifAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithElifAsync(new Elif("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithElseAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithElseAsync(new Else("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithExceptAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithExceptAsync(new Except("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithExecAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithExecAsync(new Exec("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithFinallyAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithFinallyAsync(new Finally("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithFromAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithFromAsync(new From("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithGlobalAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithGlobalAsync(new Global("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithImportAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithImportAsync(new Import("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithInAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithInAsync(new In("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithIsAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithIsAsync(new SpecialWordsIs("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithLambdaAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithLambdaAsync(new Lambda("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithNotAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithNotAsync(new Not("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});


[CadlRanchTest]
public Task ModelsWithOrAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithOrAsync(new Or("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithPassAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithPassAsync(new Pass("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithRaiseAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithRaiseAsync(new Raise("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithReturnAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithReturnAsync(new Return("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithTryAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithTryAsync(new Try("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithIfAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithIfAsync(new If("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithForAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithForAsync(new For("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithWithAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithWithAsync(new With("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithWhileAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithWhileAsync(new While("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelsWithYieldAsync() => Test(async (host) =>
{
var client = new SpecialWordsClient(host, null).GetModelsOpsClient();
var response = await client.WithYieldAsync(new Yield("ok"));
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task ModelProperties_SameAsModelAsync() => Test(async (host) =>
{
SameAsModel body = new SameAsModel("ok");
var client = new SpecialWordsClient(host, null).GetModelPropertiesClient();
var response = await client.SameAsModelAsync(body);
NUnit.Framework.Assert.AreEqual(204, response.GetRawResponse().Status);
});
}
}
Loading

0 comments on commit f080aec

Please sign in to comment.