@@ -702,4 +702,93 @@ public async Task Test309()
702702 var exception = await Should . ThrowAsync < JSRuntimeInvocationNotSetException > ( invocationTask . AsTask ( ) ) ;
703703 exception . Invocation . Identifier . ShouldBe ( identifier ) ;
704704 }
705+
706+ #if NET10_0_OR_GREATER
707+ [ Fact ( DisplayName = "InvokeConstructorAsync returns IJSObjectReference in loose mode without setup" ) ]
708+ public async Task Test400 ( )
709+ {
710+ var sut = CreateSut ( JSRuntimeMode . Loose ) ;
711+
712+ var result = await sut . JSRuntime . InvokeConstructorAsync ( "SomeClass" ) ;
713+
714+ result . ShouldNotBeNull ( ) ;
715+ result . ShouldBeAssignableTo < IJSObjectReference > ( ) ;
716+ }
717+
718+ [ Fact ( DisplayName = "InvokeConstructorAsync throws in strict mode when no handler is set up" ) ]
719+ public void Test401 ( )
720+ {
721+ var sut = CreateSut ( JSRuntimeMode . Strict ) ;
722+
723+ Should . Throw < JSRuntimeUnhandledInvocationException > (
724+ async ( ) => await sut . JSRuntime . InvokeConstructorAsync ( "SomeClass" ) ) ;
725+ }
726+
727+ [ Theory ( DisplayName = "InvokeConstructorAsync records invocation with correct method name and arguments" ) , AutoData ]
728+ public void Test402 ( string identifier )
729+ {
730+ var args = new object [ ] { "arg1" , 42 } ;
731+ var sut = CreateSut ( JSRuntimeMode . Loose ) ;
732+
733+ sut . JSRuntime . InvokeConstructorAsync ( identifier , args ) ;
734+
735+ var invocation = sut . Invocations [ identifier ] . ShouldHaveSingleItem ( ) ;
736+ invocation . Identifier . ShouldBe ( identifier ) ;
737+ invocation . Arguments . ShouldBe ( args ) ;
738+ invocation . InvocationMethodName . ShouldBe ( "InvokeConstructorAsync" ) ;
739+ invocation . ResultType . ShouldBe ( typeof ( IJSObjectReference ) ) ;
740+ }
741+
742+ [ Theory ( DisplayName = "InvokeConstructorAsync with CancellationToken records invocation correctly" ) , AutoData ]
743+ public void Test403 ( string identifier )
744+ {
745+ var args = new object [ ] { "arg1" } ;
746+ using var cts = new CancellationTokenSource ( ) ;
747+ var sut = CreateSut ( JSRuntimeMode . Loose ) ;
748+
749+ sut . JSRuntime . InvokeConstructorAsync ( identifier , cts . Token , args ) ;
750+
751+ var invocation = sut . Invocations [ identifier ] . ShouldHaveSingleItem ( ) ;
752+ invocation . Identifier . ShouldBe ( identifier ) ;
753+ invocation . Arguments . ShouldBe ( args ) ;
754+ invocation . CancellationToken . ShouldBe ( cts . Token ) ;
755+ invocation . InvocationMethodName . ShouldBe ( "InvokeConstructorAsync" ) ;
756+ }
757+
758+ [ Fact ( DisplayName = "InvokeConstructorAsync with SetupModule handler returns configured object reference" ) ]
759+ public async Task Test404 ( )
760+ {
761+ var sut = CreateSut ( JSRuntimeMode . Strict ) ;
762+ sut . SetupModule ( inv => inv . Identifier == "SomeClass" && inv . InvocationMethodName == "InvokeConstructorAsync" ) ;
763+
764+ var result = await sut . JSRuntime . InvokeConstructorAsync ( "SomeClass" ) ;
765+
766+ result . ShouldNotBeNull ( ) ;
767+ result . ShouldBeAssignableTo < IJSObjectReference > ( ) ;
768+ }
769+
770+ [ Fact ( DisplayName = "InvokeConstructorAsync on IJSObjectReference from module import works in loose mode" ) ]
771+ public async Task Test405 ( )
772+ {
773+ var sut = CreateSut ( JSRuntimeMode . Loose ) ;
774+
775+ var module = await sut . JSRuntime . InvokeAsync < IJSObjectReference > ( "import" , "./myModule.js" ) ;
776+ var result = await module . InvokeConstructorAsync ( "JsClass" , "arg1" , "arg2" ) ;
777+
778+ result . ShouldNotBeNull ( ) ;
779+ result . ShouldBeAssignableTo < IJSObjectReference > ( ) ;
780+ }
781+
782+ [ Fact ( DisplayName = "InvokeConstructorAsync on IJSObjectReference records invocation" ) ]
783+ public async Task Test406 ( )
784+ {
785+ var sut = CreateSut ( JSRuntimeMode . Loose ) ;
786+
787+ var module = await sut . JSRuntime . InvokeAsync < IJSObjectReference > ( "import" , "./myModule.js" ) ;
788+ await module . InvokeConstructorAsync ( "JsClass" , "arg1" ) ;
789+
790+ sut . Invocations [ "JsClass" ] . ShouldHaveSingleItem ( )
791+ . InvocationMethodName . ShouldBe ( "InvokeConstructorAsync" ) ;
792+ }
793+ #endif
705794}
0 commit comments