@@ -50,6 +50,8 @@ public async Task ValidateAsync_ValidRequest_ShouldPassWithoutException()
5050 var character = CreateValidCharacterDto ( command . CharacterId ) ;
5151 var creditBalance = CreateCreditBalance ( command . UserId , 1000 ) ;
5252
53+ SetupValidSession ( command . UserId ) ;
54+
5355 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
5456 . ReturnsAsync ( true ) ;
5557 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -61,7 +63,9 @@ public async Task ValidateAsync_ValidRequest_ShouldPassWithoutException()
6163
6264 // Act & Assert
6365 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 ) ;
6569 _mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
6670 _mockCreditManagementService . Verify ( x => x . GetCreditBalanceAsync ( command . UserId ) , Times . Once ) ;
6771 }
@@ -71,6 +75,7 @@ public async Task ValidateAsync_CharacterNotFound_ShouldThrowValidationException
7175 {
7276 // Arrange
7377 var command = CreateValidChatCommand ( ) ;
78+ SetupValidSession ( command . UserId ) ;
7479 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
7580 . ReturnsAsync ( true ) ;
7681 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -96,6 +101,7 @@ public async Task ValidateAsync_EmptyUserPrompt_ShouldThrowValidationException()
96101 requestedAt : DateTime . UtcNow ,
97102 useTTS : false
98103 ) ;
104+ SetupValidSession ( command . UserId ) ;
99105 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
100106 . ReturnsAsync ( true ) ;
101107 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -106,7 +112,7 @@ public async Task ValidateAsync_EmptyUserPrompt_ShouldThrowValidationException()
106112
107113 // Act & Assert - 현재 ChatRequestValidator에는 빈 prompt 검증이 없으므로 통과해야 함
108114 await _validator . ValidateAsync ( command ) ;
109-
115+
110116 // 검증: 모든 단계가 정상적으로 실행되어야 함
111117 _mockUserService . Verify ( x => x . ExistsByIdAsync ( command . UserId ) , Times . Once ) ;
112118 _mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
@@ -124,6 +130,7 @@ public async Task ValidateAsync_WhitespaceOnlyUserPrompt_ShouldThrowValidationEx
124130 requestedAt : DateTime . UtcNow ,
125131 useTTS : false
126132 ) ;
133+ SetupValidSession ( command . UserId ) ;
127134 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
128135 . ReturnsAsync ( true ) ;
129136 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -134,7 +141,7 @@ public async Task ValidateAsync_WhitespaceOnlyUserPrompt_ShouldThrowValidationEx
134141
135142 // Act & Assert - 현재 ChatRequestValidator에는 whitespace 검증이 없으므로 통과해야 함
136143 await _validator . ValidateAsync ( command ) ;
137-
144+
138145 // 검증: 모든 단계가 정상적으로 실행되어야 함
139146 _mockUserService . Verify ( x => x . ExistsByIdAsync ( command . UserId ) , Times . Once ) ;
140147 _mockCharacterService . Verify ( x => x . CharacterExistsAsync ( command . CharacterId ) , Times . Once ) ;
@@ -153,6 +160,7 @@ public async Task ValidateAsync_ZeroCreditBalance_ShouldThrowInsufficientCreditE
153160 var character = CreateValidCharacterDto ( command . CharacterId ) ;
154161 var creditBalance = CreateCreditBalance ( command . UserId , 0 ) ; // Zero balance
155162
163+ SetupValidSession ( command . UserId ) ;
156164 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
157165 . ReturnsAsync ( true ) ;
158166 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -183,6 +191,7 @@ public async Task ValidateAsync_InsufficientCreditBalance_ShouldThrowInsufficien
183191 var character = CreateValidCharacterDto ( command . CharacterId ) ;
184192 var creditBalance = CreateCreditBalance ( command . UserId , 5 ) ; // Less than required 10 credits
185193
194+ SetupValidSession ( command . UserId ) ;
186195 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
187196 . ReturnsAsync ( true ) ;
188197 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -213,6 +222,7 @@ public async Task ValidateAsync_ExactlyEnoughCredits_ShouldPassValidation()
213222 var character = CreateValidCharacterDto ( command . CharacterId ) ;
214223 var creditBalance = CreateCreditBalance ( command . UserId , 10 ) ; // Exactly required amount
215224
225+ SetupValidSession ( command . UserId ) ;
216226 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
217227 . ReturnsAsync ( true ) ;
218228 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -237,6 +247,7 @@ public async Task ValidateAsync_MoreThanEnoughCredits_ShouldPassValidation()
237247 var character = CreateValidCharacterDto ( command . CharacterId ) ;
238248 var creditBalance = CreateCreditBalance ( command . UserId , 100 ) ; // More than enough
239249
250+ SetupValidSession ( command . UserId ) ;
240251 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
241252 . ReturnsAsync ( true ) ;
242253 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -264,6 +275,7 @@ public async Task ValidateAsync_CreditServiceThrowsException_ShouldPropagateExce
264275 var command = CreateValidChatCommand ( ) ;
265276 var character = CreateValidCharacterDto ( command . CharacterId ) ;
266277
278+ SetupValidSession ( command . UserId ) ;
267279 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
268280 . ReturnsAsync ( true ) ;
269281 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -286,6 +298,7 @@ public async Task ValidateAsync_CharacterServiceThrowsException_ShouldPropagateE
286298 // Arrange
287299 var command = CreateValidChatCommand ( ) ;
288300
301+ SetupValidSession ( command . UserId ) ;
289302 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
290303 . ReturnsAsync ( true ) ;
291304 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -307,6 +320,7 @@ public async Task ValidateAsync_NegativeCreditBalance_ShouldThrowInsufficientCre
307320 var character = CreateValidCharacterDto ( command . CharacterId ) ;
308321 var creditBalance = CreateCreditBalance ( command . UserId , - 5 ) ; // Negative balance
309322
323+ SetupValidSession ( command . UserId ) ;
310324 _mockUserService . Setup ( x => x . ExistsByIdAsync ( command . UserId ) )
311325 . ReturnsAsync ( true ) ;
312326 _mockCharacterService . Setup ( x => x . CharacterExistsAsync ( command . CharacterId ) )
@@ -413,6 +427,21 @@ private void VerifyDebugLogged(string expectedMessage)
413427 Times . Once ) ;
414428 }
415429
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+
416445 #endregion
417446 }
418447}
0 commit comments