@@ -877,4 +877,120 @@ public interface ITestActor
877877
878878 await test . RunAsync ( ) ;
879879 }
880+
881+ [ Fact ]
882+ public async Task TestGenericWithConstraints ( )
883+ {
884+ var originalSource = @"
885+ using Dapr.Actors.Generators;
886+ using System.Threading.Tasks;
887+
888+ namespace Test
889+ {
890+ public interface ITrait
891+ {
892+ string GetName();
893+ }
894+
895+ [GenerateActorClient]
896+ public interface ITestActor<TTrait> where TTrait : ITrait
897+ {
898+ Task<bool> SetTrait(TTrait trait);
899+ Task<TTrait> GetTrait(string name);
900+ }
901+ }" ;
902+
903+ var generatedSource = @"// <auto-generated/>
904+ #nullable enable
905+ namespace Test
906+ {
907+ public sealed class TestActorClient<TTrait> : Test.ITestActor<TTrait> where TTrait : Test.ITrait
908+ {
909+ private readonly Dapr.Actors.Client.ActorProxy actorProxy;
910+ public TestActorClient(Dapr.Actors.Client.ActorProxy actorProxy)
911+ {
912+ if (actorProxy is null)
913+ {
914+ throw new System.ArgumentNullException(nameof(actorProxy));
915+ }
916+
917+ this.actorProxy = actorProxy;
918+ }
919+
920+ public System.Threading.Tasks.Task<TTrait> GetTrait(string name)
921+ {
922+ return this.actorProxy.InvokeMethodAsync<string, TTrait>(""GetTrait"", name);
923+ }
924+
925+ public System.Threading.Tasks.Task<bool> SetTrait(TTrait trait)
926+ {
927+ return this.actorProxy.InvokeMethodAsync<TTrait, bool>(""SetTrait"", trait);
928+ }
929+ }
930+ }" ;
931+
932+ await CreateTest ( originalSource , "Test.TestActorClient.g.cs" , generatedSource ) . RunAsync ( ) ;
933+ }
934+
935+ [ Fact ]
936+ public async Task TestGenericWithMultipleTypeParametersAndConstraints ( )
937+ {
938+ var originalSource = @"
939+ using Dapr.Actors.Generators;
940+ using System.Threading.Tasks;
941+
942+ namespace Test
943+ {
944+ public interface ITrait
945+ {
946+ string GetName();
947+ }
948+
949+ public interface IValidator<T>
950+ {
951+ bool Validate(T item);
952+ }
953+
954+ [GenerateActorClient]
955+ public interface ITestActor<TTrait, TValidator>
956+ where TTrait : ITrait, new()
957+ where TValidator : class, IValidator<TTrait>
958+ {
959+ Task<bool> SetTrait(TTrait trait);
960+ Task<TTrait> GetValidatedTrait(string name);
961+ }
962+ }" ;
963+
964+ var generatedSource = @"// <auto-generated/>
965+ #nullable enable
966+ namespace Test
967+ {
968+ public sealed class TestActorClient<TTrait, TValidator> : Test.ITestActor<TTrait, TValidator> where TTrait : Test.ITrait, new()
969+ where TValidator : class, Test.IValidator<TTrait>
970+ {
971+ private readonly Dapr.Actors.Client.ActorProxy actorProxy;
972+ public TestActorClient(Dapr.Actors.Client.ActorProxy actorProxy)
973+ {
974+ if (actorProxy is null)
975+ {
976+ throw new System.ArgumentNullException(nameof(actorProxy));
977+ }
978+
979+ this.actorProxy = actorProxy;
980+ }
981+
982+ public System.Threading.Tasks.Task<TTrait> GetValidatedTrait(string name)
983+ {
984+ return this.actorProxy.InvokeMethodAsync<string, TTrait>(""GetValidatedTrait"", name);
985+ }
986+
987+ public System.Threading.Tasks.Task<bool> SetTrait(TTrait trait)
988+ {
989+ return this.actorProxy.InvokeMethodAsync<TTrait, bool>(""SetTrait"", trait);
990+ }
991+ }
992+ }" ;
993+
994+ await CreateTest ( originalSource , "Test.TestActorClient.g.cs" , generatedSource ) . RunAsync ( ) ;
995+ }
880996}
0 commit comments