@@ -50,6 +50,8 @@ public async Task ValidateAsync_ValidRequest_ShouldPassWithoutException()
50
50
var character = CreateValidCharacterDto ( command . CharacterId ) ;
51
51
var creditBalance = CreateCreditBalance ( command . UserId , 1000 ) ;
52
52
53
+ SetupValidSession ( command . UserId ) ;
54
+
53
55
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
54
56
. ReturnsAsync ( true ) ;
55
57
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -61,7 +63,9 @@ public async Task ValidateAsync_ValidRequest_ShouldPassWithoutException()
61
63
62
64
// Act & Assert
63
65
await _validator . ValidateAsync ( command ) ; // Should not throw
64
-
66
+
67
+ _mockSessionStorage . Verify ( x => x . GetSessionsByUserIdAsync ( command . UserId . ToString ( ) ) , Times . Once ) ;
68
+ _mockUserService . Verify ( x => x . ExistsByIdAsync ( command . UserId ) , Times . Once ) ;
65
69
_mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
66
70
_mockCreditManagementService . Verify ( x => x . GetCreditBalanceAsync ( command . UserId ) , Times . Once ) ;
67
71
}
@@ -71,6 +75,7 @@ public async Task ValidateAsync_CharacterNotFound_ShouldThrowValidationException
71
75
{
72
76
// Arrange
73
77
var command = CreateValidChatCommand ( ) ;
78
+ SetupValidSession ( command . UserId ) ;
74
79
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
75
80
. ReturnsAsync ( true ) ;
76
81
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -96,6 +101,7 @@ public async Task ValidateAsync_EmptyUserPrompt_ShouldThrowValidationException()
96
101
requestedAt : DateTime . UtcNow ,
97
102
useTTS : false
98
103
) ;
104
+ SetupValidSession ( command . UserId ) ;
99
105
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
100
106
. ReturnsAsync ( true ) ;
101
107
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -106,7 +112,7 @@ public async Task ValidateAsync_EmptyUserPrompt_ShouldThrowValidationException()
106
112
107
113
// Act & Assert - 현재 ChatRequestValidator에는 빈 prompt 검증이 없으므로 통과해야 함
108
114
await _validator . ValidateAsync ( command ) ;
109
-
115
+
110
116
// 검증: 모든 단계가 정상적으로 실행되어야 함
111
117
_mockUserService . Verify ( x => x . ExistsByIdAsync ( command . UserId ) , Times . Once ) ;
112
118
_mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
@@ -124,6 +130,7 @@ public async Task ValidateAsync_WhitespaceOnlyUserPrompt_ShouldThrowValidationEx
124
130
requestedAt : DateTime . UtcNow ,
125
131
useTTS : false
126
132
) ;
133
+ SetupValidSession ( command . UserId ) ;
127
134
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
128
135
. ReturnsAsync ( true ) ;
129
136
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -134,7 +141,7 @@ public async Task ValidateAsync_WhitespaceOnlyUserPrompt_ShouldThrowValidationEx
134
141
135
142
// Act & Assert - 현재 ChatRequestValidator에는 whitespace 검증이 없으므로 통과해야 함
136
143
await _validator . ValidateAsync ( command ) ;
137
-
144
+
138
145
// 검증: 모든 단계가 정상적으로 실행되어야 함
139
146
_mockUserService . Verify ( x => x . ExistsByIdAsync ( command . UserId ) , Times . Once ) ;
140
147
_mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
@@ -153,6 +160,7 @@ public async Task ValidateAsync_ZeroCreditBalance_ShouldThrowInsufficientCreditE
153
160
var character = CreateValidCharacterDto ( command . CharacterId ) ;
154
161
var creditBalance = CreateCreditBalance ( command . UserId , 0 ) ; // Zero balance
155
162
163
+ SetupValidSession ( command . UserId ) ;
156
164
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
157
165
. ReturnsAsync ( true ) ;
158
166
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -183,6 +191,7 @@ public async Task ValidateAsync_InsufficientCreditBalance_ShouldThrowInsufficien
183
191
var character = CreateValidCharacterDto ( command . CharacterId ) ;
184
192
var creditBalance = CreateCreditBalance ( command . UserId , 5 ) ; // Less than required 10 credits
185
193
194
+ SetupValidSession ( command . UserId ) ;
186
195
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
187
196
. ReturnsAsync ( true ) ;
188
197
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -213,6 +222,7 @@ public async Task ValidateAsync_ExactlyEnoughCredits_ShouldPassValidation()
213
222
var character = CreateValidCharacterDto ( command . CharacterId ) ;
214
223
var creditBalance = CreateCreditBalance ( command . UserId , 10 ) ; // Exactly required amount
215
224
225
+ SetupValidSession ( command . UserId ) ;
216
226
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
217
227
. ReturnsAsync ( true ) ;
218
228
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -237,6 +247,7 @@ public async Task ValidateAsync_MoreThanEnoughCredits_ShouldPassValidation()
237
247
var character = CreateValidCharacterDto ( command . CharacterId ) ;
238
248
var creditBalance = CreateCreditBalance ( command . UserId , 100 ) ; // More than enough
239
249
250
+ SetupValidSession ( command . UserId ) ;
240
251
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
241
252
. ReturnsAsync ( true ) ;
242
253
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -264,6 +275,7 @@ public async Task ValidateAsync_CreditServiceThrowsException_ShouldPropagateExce
264
275
var command = CreateValidChatCommand ( ) ;
265
276
var character = CreateValidCharacterDto ( command . CharacterId ) ;
266
277
278
+ SetupValidSession ( command . UserId ) ;
267
279
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
268
280
. ReturnsAsync ( true ) ;
269
281
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -286,6 +298,7 @@ public async Task ValidateAsync_CharacterServiceThrowsException_ShouldPropagateE
286
298
// Arrange
287
299
var command = CreateValidChatCommand ( ) ;
288
300
301
+ SetupValidSession ( command . UserId ) ;
289
302
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
290
303
. ReturnsAsync ( true ) ;
291
304
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -307,6 +320,7 @@ public async Task ValidateAsync_NegativeCreditBalance_ShouldThrowInsufficientCre
307
320
var character = CreateValidCharacterDto ( command . CharacterId ) ;
308
321
var creditBalance = CreateCreditBalance ( command . UserId , - 5 ) ; // Negative balance
309
322
323
+ SetupValidSession ( command . UserId ) ;
310
324
_mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
311
325
. ReturnsAsync ( true ) ;
312
326
_mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -413,6 +427,21 @@ private void VerifyDebugLogged(string expectedMessage)
413
427
Times . Once ) ;
414
428
}
415
429
430
+ private void SetupValidSession ( Guid userId )
431
+ {
432
+ var sessionInfos = new List < ProjectVG . Common . Models . Session . SessionInfo >
433
+ {
434
+ new ProjectVG . Common . Models . Session . SessionInfo
435
+ {
436
+ SessionId = Guid . NewGuid ( ) . ToString ( ) ,
437
+ UserId = userId . ToString ( ) ,
438
+ ConnectedAt = DateTime . UtcNow
439
+ }
440
+ } ;
441
+ _mockSessionStorage . Setup ( x => x . GetSessionsByUserIdAsync ( userId . ToString ( ) ) )
442
+ . ReturnsAsync ( sessionInfos ) ;
443
+ }
444
+
416
445
#endregion
417
446
}
418
447
}
0 commit comments