1+ using Microsoft . AspNetCore . DataProtection ;
2+ using Microsoft . AspNetCore . Razor . TagHelpers ;
3+ using Moq ;
4+ using NUnit . Framework ;
5+ using Our . Umbraco . TagHelpers . Tests . Helpers ;
6+ using System ;
7+ using System . Collections . Generic ;
8+
9+ namespace Our . Umbraco . TagHelpers . Tests
10+ {
11+ public class SurfaceControllerFormTagHelperTests
12+ {
13+ [ Test ]
14+ public void Constructor_WithValidParameters_InitializesProperties ( )
15+ {
16+ // Arrange
17+ var mockDataProtectionProvider = new Mock < IDataProtectionProvider > ( ) ;
18+
19+ // Act
20+ var tagHelper = new SurfaceControllerFormTagHelper ( mockDataProtectionProvider . Object ) ;
21+
22+ // Assert
23+ Assert . IsNotNull ( tagHelper ) ;
24+ Assert . AreEqual ( "" , tagHelper . Area ) ;
25+ Assert . IsNull ( tagHelper . ControllerAction ) ;
26+ Assert . IsNull ( tagHelper . ControllerName ) ;
27+ Assert . IsNotNull ( tagHelper . RouteValues ) ;
28+ }
29+
30+ [ Test ]
31+ public void Properties_CanBeSetAndRetrieved ( )
32+ {
33+ // Arrange
34+ var mockDataProtectionProvider = new Mock < IDataProtectionProvider > ( ) ;
35+ var tagHelper = new SurfaceControllerFormTagHelper ( mockDataProtectionProvider . Object ) ;
36+
37+ // Act
38+ tagHelper . ControllerAction = "TestAction" ;
39+ tagHelper . ControllerName = "TestController" ;
40+ tagHelper . Area = "TestArea" ;
41+
42+ var routeValues = new Dictionary < string , string > { { "id" , "123" } } ;
43+ tagHelper . RouteValues = routeValues ;
44+
45+ // Assert
46+ Assert . AreEqual ( "TestAction" , tagHelper . ControllerAction ) ;
47+ Assert . AreEqual ( "TestController" , tagHelper . ControllerName ) ;
48+ Assert . AreEqual ( "TestArea" , tagHelper . Area ) ;
49+ Assert . AreEqual ( routeValues , tagHelper . RouteValues ) ;
50+ }
51+
52+ [ Test ]
53+ public void Process_WithNullContext_ThrowsArgumentNullException ( )
54+ {
55+ // Arrange
56+ var mockDataProtectionProvider = new Mock < IDataProtectionProvider > ( ) ;
57+ var tagHelper = new SurfaceControllerFormTagHelper ( mockDataProtectionProvider . Object ) ;
58+ var tagHelperOutput = TestContextHelpers . GetTagHelperOutput ( "form" ) ;
59+
60+ // Act & Assert
61+ Assert . Throws < ArgumentNullException > ( ( ) => tagHelper . Process ( null , tagHelperOutput ) ) ;
62+ }
63+
64+ [ Test ]
65+ public void Process_WithNullOutput_ThrowsArgumentNullException ( )
66+ {
67+ // Arrange
68+ var mockDataProtectionProvider = new Mock < IDataProtectionProvider > ( ) ;
69+ var tagHelper = new SurfaceControllerFormTagHelper ( mockDataProtectionProvider . Object ) ;
70+ var tagHelperContext = TestContextHelpers . GetTagHelperContext ( "form-id" ) ;
71+
72+ // Act & Assert
73+ Assert . Throws < ArgumentNullException > ( ( ) => tagHelper . Process ( tagHelperContext , null ) ) ;
74+ }
75+
76+ [ Test ]
77+ public void Process_WithEmptyControllerName_ReturnsEarly ( )
78+ {
79+ // Arrange
80+ var mockDataProtectionProvider = new Mock < IDataProtectionProvider > ( ) ;
81+ var tagHelper = new SurfaceControllerFormTagHelper ( mockDataProtectionProvider . Object ) ;
82+ var tagHelperContext = TestContextHelpers . GetTagHelperContext ( "form-id" ) ;
83+ var tagHelperOutput = TestContextHelpers . GetTagHelperOutput ( "form" ) ;
84+
85+ tagHelper . ControllerName = "" ;
86+ tagHelper . ControllerAction = "TestAction" ;
87+
88+ // Act - Should return early without doing anything
89+ tagHelper . Process ( tagHelperContext , tagHelperOutput ) ;
90+
91+ // Assert - Since it returns early, PostContent should not be modified
92+ // This is a basic test to ensure the method doesn't throw
93+ Assert . DoesNotThrow ( ( ) => tagHelper . Process ( tagHelperContext , tagHelperOutput ) ) ;
94+ }
95+ }
96+ }
0 commit comments