Skip to content

Commit

Permalink
Merge pull request #238 from max-ieremenko/bug-fix/array-analyzer
Browse files Browse the repository at this point in the history
DesignTime: fix array parameters handling
  • Loading branch information
max-ieremenko authored Sep 28, 2024
2 parents e00bd56 + 3b631bf commit b3e0b14
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ private sealed class ResponseTypeCases
[ResponseHeaderNames([])]
public Task<(string Value1, int Value2)> TaskValueTuple() => throw new NotSupportedException();

[OperationContract]
[ResponseType(typeof(string[]))]
[ResponseHeaderNames([])]
public Task<string[]> TaskArrayString() => throw new NotSupportedException();

[OperationContract]
[ResponseType(typeof(int))]
[ResponseHeaderNames([])]
Expand All @@ -119,6 +124,12 @@ private sealed class ResponseTypeCases
[HeaderResponseType([1], [typeof(int)], 0)]
[ResponseHeaderNames(["Value"])]
public ValueTask<(IAsyncEnumerable<string> Stream, int Value)> ValueTaskAsyncEnumerableWithHeader() => throw new NotSupportedException();

[OperationContract]
[ResponseType(typeof(string[]))]
[HeaderResponseType([1], [typeof(int[])], 0)]
[ResponseHeaderNames(["Values"])]
public ValueTask<(IAsyncEnumerable<string[]> Stream, int[] Values)> ValueTaskAsyncEnumerableWithArraysHeader() => throw new NotSupportedException();
}

[ServiceContract]
Expand Down Expand Up @@ -195,6 +206,10 @@ private sealed class RequestTypeCases
[RequestType([0, 1], [typeof(string), typeof(int?)])]
public void StringInt(string? value1, int? value2) => throw new NotSupportedException();

[OperationContract]
[RequestType([0], [typeof(string[])])]
public void StringArray(string[] value) => throw new NotSupportedException();

[OperationContract]
[RequestType([0], [typeof(int)])]
public void AsyncEnumerableInt(IAsyncEnumerable<int> value) => throw new NotSupportedException();
Expand All @@ -203,6 +218,11 @@ private sealed class RequestTypeCases
[RequestType([2], [typeof(int)])]
[HeaderRequestType([0, 1], [typeof(int), typeof(string)])]
public void AsyncEnumerableInt(int value2, string value3, IAsyncEnumerable<int> value1) => throw new NotSupportedException();

[OperationContract]
[RequestType([1], [typeof(int[])])]
[HeaderRequestType([0], [typeof(int[])])]
public void AsyncEnumerableIntArray(int[] value2, IAsyncEnumerable<int[]> value1) => throw new NotSupportedException();
}

[AttributeUsage(AttributeTargets.Method)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public partial class OperationDescriptionBuilderTest
[TestCaseSource(nameof(GetResponseTypeCases))]
public void ResponseType(
IMethodSymbol method,
INamedTypeSymbol? valueType,
ITypeSymbol? valueType,
int[]? headerIndexes,
INamedTypeSymbol[]? headerValueType,
ITypeSymbol[]? headerValueType,
int? streamIndex)
{
var actual = Build(method, "s1", "o1");
Expand All @@ -45,11 +45,11 @@ public void ResponseType(
else
{
actual.ResponseType.Properties.Length.ShouldBe(1);
var actualValueType = actual.ResponseType.Properties[0].ShouldBeAssignableTo<INamedTypeSymbol>().ShouldNotBeNull();
var actualValueType = actual.ResponseType.Properties[0].ShouldBeAssignableTo<ITypeSymbol>().ShouldNotBeNull();
if (valueType.IsTupleType)
{
actualValueType.IsTupleType.ShouldBeTrue();
actualValueType.TupleUnderlyingType.ShouldBe(valueType, SymbolEqualityComparer.Default);
((INamedTypeSymbol)actualValueType).TupleUnderlyingType.ShouldBe(valueType, SymbolEqualityComparer.Default);
}
else
{
Expand Down Expand Up @@ -93,9 +93,9 @@ public void NotSupportedResponseType(IMethodSymbol method)
public void RequestType(
IMethodSymbol method,
int[] requestIndexes,
INamedTypeSymbol[] requestValueType,
ITypeSymbol[] requestValueType,
int[] headerIndexes,
INamedTypeSymbol[]? headerValueType)
ITypeSymbol[]? headerValueType)
{
var actual = Build(method, "s1", "o1");

Expand Down Expand Up @@ -165,7 +165,7 @@ private static IEnumerable<TestCaseData> GetResponseTypeCases()
method,
response.ConstructorArguments[0].Value,
responseHeader?.ConstructorArguments[0].Values.Select(i => (int)i.Value!).ToArray(),
responseHeader?.ConstructorArguments[1].Values.Select(i => (INamedTypeSymbol)i.Value!).ToArray(),
responseHeader?.ConstructorArguments[1].Values.Select(i => (ITypeSymbol)i.Value!).ToArray(),
responseHeader?.ConstructorArguments[2].Value)
{
TestName = "ResponseType." + method.Name
Expand Down Expand Up @@ -201,9 +201,9 @@ private static IEnumerable<TestCaseData> GetRequestTypeCases()
yield return new TestCaseData(
method,
request.ConstructorArguments[0].Values.Select(i => (int)i.Value!).ToArray(),
request.ConstructorArguments[1].Values.Select(i => (INamedTypeSymbol)i.Value!).ToArray(),
request.ConstructorArguments[1].Values.Select(i => (ITypeSymbol)i.Value!).ToArray(),
headerRequest?.ConstructorArguments[0].Values.Select(i => (int)i.Value!).ToArray(),
headerRequest?.ConstructorArguments[1].Values.Select(i => (INamedTypeSymbol)i.Value!).ToArray())
headerRequest?.ConstructorArguments[1].Values.Select(i => (ITypeSymbol)i.Value!).ToArray())
{
TestName = "RequestType." + method.Name
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public IMethodInfo<ITypeSymbol>[] GetMethods(ITypeSymbol type)

public ITypeSymbol[] GenericTypeArguments(ITypeSymbol type)
{
var args = ((INamedTypeSymbol)type).TypeArguments;
if (type is not INamedTypeSymbol typeSymbol || typeSymbol.TypeArguments.Length == 0)
{
return [];
}

var args = typeSymbol.TypeArguments;
var result = new ITypeSymbol[args.Length];
args.CopyTo(result);
return result;
Expand Down

0 comments on commit b3e0b14

Please sign in to comment.