1+ using System . Text . Json ;
2+ using ModelContextProtocol . Protocol ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public class ElicitResultTests
7+ {
8+ [ Theory ]
9+ [ InlineData ( "accept" ) ]
10+ [ InlineData ( "Accept" ) ]
11+ [ InlineData ( "ACCEPT" ) ]
12+ [ InlineData ( "AccEpt" ) ]
13+ public void IsAccepted_Returns_True_For_VariousAcceptedActions ( string action )
14+ {
15+ // Arrange
16+ var result = new ElicitResult { Action = action } ;
17+
18+ // Act
19+ var isAccepted = result . IsAccepted ;
20+
21+ // Assert
22+ Assert . True ( isAccepted ) ;
23+ }
24+
25+ [ Theory ]
26+ [ InlineData ( "decline" ) ]
27+ [ InlineData ( "Decline" ) ]
28+ [ InlineData ( "DECLINE" ) ]
29+ [ InlineData ( "DecLine" ) ]
30+ public void IsDeclined_Returns_True_For_VariousDeclinedActions ( string action )
31+ {
32+ // Arrange
33+ var result = new ElicitResult { Action = action } ;
34+
35+ // Act
36+ var isDeclined = result . IsDeclined ;
37+
38+ // Assert
39+ Assert . True ( isDeclined ) ;
40+ }
41+
42+ [ Theory ]
43+ [ InlineData ( "cancel" ) ]
44+ [ InlineData ( "Cancel" ) ]
45+ [ InlineData ( "CANCEL" ) ]
46+ [ InlineData ( "CanCel" ) ]
47+ public void IsCancelled_Returns_True_For_VariousCancelledActions ( string action )
48+ {
49+ // Arrange
50+ var result = new ElicitResult { Action = action } ;
51+
52+ // Act
53+ var isCancelled = result . IsCancelled ;
54+
55+ // Assert
56+ Assert . True ( isCancelled ) ;
57+ }
58+
59+ [ Fact ]
60+ public void IsAccepted_Returns_False_For_DefaultAction ( )
61+ {
62+ // Arrange
63+ var result = new ElicitResult ( ) ;
64+
65+ // Act & Assert
66+ Assert . False ( result . IsAccepted ) ;
67+ }
68+
69+ [ Fact ]
70+ public void IsDeclined_Returns_False_For_DefaultAction ( )
71+ {
72+ // Arrange
73+ var result = new ElicitResult ( ) ;
74+
75+ // Act & Assert
76+ Assert . False ( result . IsDeclined ) ;
77+ }
78+
79+ [ Fact ]
80+ public void IsCancelled_Returns_True_For_DefaultAction ( )
81+ {
82+ // Arrange
83+ var result = new ElicitResult ( ) ;
84+
85+ // Act & Assert
86+ Assert . True ( result . IsCancelled ) ;
87+ }
88+
89+ [ Fact ]
90+ public void IsAccepted_Returns_False_For_Null_Action ( )
91+ {
92+ // Arrange
93+ var result = new ElicitResult { Action = null ! } ;
94+
95+ // Act & Assert
96+ Assert . False ( result . IsAccepted ) ;
97+ }
98+
99+ [ Fact ]
100+ public void IsDeclined_Returns_False_For_Null_Action ( )
101+ {
102+ // Arrange
103+ var result = new ElicitResult { Action = null ! } ;
104+
105+ // Act & Assert
106+ Assert . False ( result . IsDeclined ) ;
107+ }
108+
109+ [ Fact ]
110+ public void IsCancelled_Returns_False_For_Null_Action ( )
111+ {
112+ // Arrange
113+ var result = new ElicitResult { Action = null ! } ;
114+
115+ // Act & Assert
116+ Assert . False ( result . IsCancelled ) ;
117+ }
118+
119+ [ Theory ]
120+ [ InlineData ( "accept" ) ]
121+ [ InlineData ( "decline" ) ]
122+ [ InlineData ( "cancel" ) ]
123+ [ InlineData ( "unknown" ) ]
124+ public void JsonSerialization_ExcludesJsonIgnoredProperties ( string action )
125+ {
126+ // Arrange
127+ var result = new ElicitResult { Action = action } ;
128+
129+ // Act
130+ var json = JsonSerializer . Serialize ( result , McpJsonUtilities . DefaultOptions ) ;
131+
132+ // Assert
133+ Assert . DoesNotContain ( "IsAccepted" , json ) ;
134+ Assert . DoesNotContain ( "IsDeclined" , json ) ;
135+ Assert . DoesNotContain ( "IsCancelled" , json ) ;
136+ Assert . Contains ( $ "\" action\" :\" { action } \" ", json ) ;
137+ }
138+
139+ [ Theory ]
140+ [ InlineData ( "accept" , true , false , false ) ]
141+ [ InlineData ( "decline" , false , true , false ) ]
142+ [ InlineData ( "cancel" , false , false , true ) ]
143+ [ InlineData ( "unknown" , false , false , false ) ]
144+ public void JsonRoundTrip_PreservesActionAndComputedProperties ( string action , bool isAccepted , bool isDeclined , bool isCancelled )
145+ {
146+ // Arrange
147+ var result = new ElicitResult { Action = action } ;
148+
149+ // Act
150+ var json = JsonSerializer . Serialize ( result , McpJsonUtilities . DefaultOptions ) ;
151+ var deserialized = JsonSerializer . Deserialize < ElicitResult > ( json , McpJsonUtilities . DefaultOptions ) ;
152+
153+ // Assert
154+ Assert . NotNull ( deserialized ) ;
155+ Assert . Equal ( action , deserialized . Action ) ;
156+ Assert . Equal ( isAccepted , deserialized . IsAccepted ) ;
157+ Assert . Equal ( isDeclined , deserialized . IsDeclined ) ;
158+ Assert . Equal ( isCancelled , deserialized . IsCancelled ) ;
159+ }
160+ }
0 commit comments