public void VerifyVariableResolverUsingVaribleParameter() { string query = @" Invoke-Sqlcmd -Query ""SELECT `$(calcOne)"" -Variable ""calcOne = 10 + 20"" "; TestCommandHandler handler = new TestCommandHandler(new StringBuilder()); IVariableResolver resolver = new TestVariableResolver(new StringBuilder()); using (Parser p = new Parser( handler, resolver, new StringReader(query), "test")) { p.ThrowOnUnresolvedVariable = true; handler.SetParser(p); Assert.Throws <BatchParserException>(() => p.Parse()); } }
public void VerifyVariableResolverIsStartIdentifierChar() { // instead of using variable calcOne, I purposely used In-variable 0alcOne string query = @" Invoke-Sqlcmd -Query ""SELECT `$(0alcOne)"" -Variable ""calcOne1 = 1"" "; TestCommandHandler handler = new TestCommandHandler(new StringBuilder()); IVariableResolver resolver = new TestVariableResolver(new StringBuilder()); using (Parser p = new Parser( handler, resolver, new StringReader(query), "test")) { p.ThrowOnUnresolvedVariable = true; handler.SetParser(p); Assert.Throws <BatchParserException>(() => p.Parse()); } }
public void VerifyThrowOnUnresolvedVariable() { string script = "print '$(NotDefined)'"; StringBuilder output = new StringBuilder(); TestCommandHandler handler = new TestCommandHandler(output); IVariableResolver resolver = new TestVariableResolver(new StringBuilder()); using (Parser p = new Parser( handler, resolver, new StringReader(script), "test")) { p.ThrowOnUnresolvedVariable = true; handler.SetParser(p); Assert.Throws <BatchParserException>(() => p.Parse()); } }
public void VerifySqlCmdExecute() { string query = ":!!if exist foo.txt del foo.txt"; var inputStream = GenerateStreamFromString(query); TestCommandHandler handler = new TestCommandHandler(new StringBuilder()); IVariableResolver resolver = new TestVariableResolver(new StringBuilder()); using (Parser p = new Parser( handler, resolver, new StringReader(query), "test")) { p.ThrowOnUnresolvedVariable = true; handler.SetParser(p); var exception = Assert.Throws <BatchParserException>(() => p.Parse()); // Verify the message should be "Command Execute is not supported." Assert.Equal("Command Execute is not supported.", exception.Message); } }
public void VerifyInvalidNumber() { string query = @" SELECT 1+1 GO 999999999999999999999999999999999999999"; TestCommandHandler handler = new TestCommandHandler(new StringBuilder()); IVariableResolver resolver = new TestVariableResolver(new StringBuilder()); using (Parser p = new Parser( handler, resolver, new StringReader(query), "test")) { p.ThrowOnUnresolvedVariable = true; handler.SetParser(p); // This test will fail because we are passing invalid number. // Exception will be raised from ParseGo() Assert.Throws <BatchParserException>(() => p.Parse()); } }