I want substituting IDBCommand with using NSubstitue. I must substitue field CommandText, and I did
string settedCommandText=string.Empty;
IDbCommand fakeCommand = Substitute.For<IDbCommand>();
command.CommandText =Arg.Do<string>(x => settedCommandText = x);
All right, but compiler throw error:
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.
How can I rewrite this code without suppressing this error. I don't want use System.Diagnostics.CodeAnalysis.SuppressMessage
First, it seems like you're creating a
fakeCommand
and then setting a variable calledcommand
.Second, your
Arg.Do<string>
needs to be part of what you're passing to a method. You're not setting it as the value of thecommand
.Have a look here (official documentation) for how it's done.