2016-08-06 3 views
0

NSubstitue를 사용하여 IDBCommand를 대체하고 싶습니다. 나는 필드의 CommandText를 대체 값해야하고, 나는IDBCommand에 대한 NS substitue CA2100

string settedCommandText=string.Empty; 

IDbCommand fakeCommand = Substitute.For<IDbCommand>(); 

command.CommandText =Arg.Do<string>(x => settedCommandText = x); 

모든 권리를했지만 컴파일러 던져 오류 :

CA2100 The query string passed to 'IDbCommand.CommandText.set(string)' in 'DriverTest.RevertCommandSendRevertInstruction()' could contain the following variables 'Arg.Do(...)'. If any of these variables could come from user input, consider using a stored procedure or a parameterized SQL query instead of building the query with string concatenations.

가 어떻게이 오류를 억제하지 않고이 코드를 다시 작성할 수 있습니다. 사용하지 않으려는 경우 System.Diagnostics.CodeAnalysis.SuppressMessage

+0

저는 Arg.Do가 필요하지 않다고 생각합니다. 테스트 액션 후에'fakeCommand.CommandText' 속성을 선언하십시오. –

답변

0

먼저 fakeCommand을 만든 다음 command이라는 변수를 설정 한 것 같습니다.
두 번째로, Arg.Do<string>은 메소드에 전달할 항목의 일부 여야합니다. command의 값으로 설정하지 않았습니다.

완료 방법은 here (official documentation)입니다.

내가 기대하는 문자열이 명령에 추가되어 있는지 확인하기를 원한다면 내가

fakeCommand.Received(1).CommandText = Arg.Any<string>(); 

또는

fakeCommand.Received(1).CommandText = "some specific string"; 

를 작성합니다

0

var _ = fakeCommand.Received(1).Commandtext 

가 있는지 확인하기 위해 가치는 실제로 어딘가에서 사용되었습니다. 이것은 가짜 명령이기 때문에 이것은 당신이 알고 싶어하는만큼 많이 생각할 것입니다.