1+ namespace Temporalio . Tests ;
2+
3+ using System . Reflection ;
4+ using Xunit ;
5+ using Xunit . Abstractions ;
6+
7+ public class GeneralTests : TestBase
8+ {
9+ public GeneralTests ( ITestOutputHelper output )
10+ : base ( output )
11+ {
12+ }
13+
14+ [ Fact ]
15+ public void CloneableTypes_InstantiateAndClone_Succeeds ( )
16+ {
17+ // Walk Temporal assemblies finding all classes that are cloneable
18+ var types = AppDomain . CurrentDomain . GetAssemblies ( ) . SelectMany ( a => a . GetTypes ( ) . Where ( t =>
19+ t . IsClass &&
20+ t . Namespace is { } ns &&
21+ ns . StartsWith ( "Temporalio." ) &&
22+ ! ns . StartsWith ( "Temporalio.Api." ) &&
23+ ! ns . StartsWith ( "Temporalio.Bridge." ) &&
24+ t . GetMethod ( "Clone" , BindingFlags . Public | BindingFlags . Instance ) != null ) ) ;
25+ // Ensure at least one we know of is there
26+ Assert . Contains ( typeof ( Temporalio . Client . Schedules . ScheduleListOptions ) , types ) ;
27+ foreach ( var type in types )
28+ {
29+ // Instantiate and attempt clone
30+ var noParamConstructor = type . GetConstructors ( ) .
31+ First ( c => c . GetParameters ( ) . All ( p => p . IsOptional ) ) ;
32+ var instance = noParamConstructor . Invoke ( noParamConstructor . GetParameters ( )
33+ . Select ( p => p . DefaultValue )
34+ . ToArray ( ) ) ;
35+ var clone = type . GetMethod ( "Clone" ) ! . Invoke ( instance , null ) ;
36+ Assert . IsType ( type , clone ) ;
37+ }
38+ }
39+ }
0 commit comments