private Session CreateSession( Action <ScopedObjectRegistry> sessionObjectsConfigurator = null, params Type[] commandTypes) { var parser = new Parser(); var nameValidator = new NameValidator(); var descriptorGenerator = new CommandAttributeInspector(); var registry = new CommandRegistry(nameValidator, descriptorGenerator); foreach (var commandType in commandTypes) { registry.Register(commandType); } var services = new CommandServices(); var scopedObjects = new ScopedObjectRegistry(); scopedObjects.Register <VariableCollection>(); sessionObjectsConfigurator?.Invoke(scopedObjects); var factory = new CommandFactory(registry, services, scopedObjects); var variables = scopedObjects.Resolve(typeof(VariableCollection)) as VariableCollection; var replacer = new VariableReplacer(); var binder = new CommandParameterBinder(registry, replacer, variables); return(new Session(parser, factory, binder)); }
public VariableReplacerTests() { _variableExtractor = Substitute.For <IVariableExtractor>(); _valueProvider = Substitute.For <IValueProvider>(); _sut = new VariableReplacer(_variableExtractor, _valueProvider); }
private CommandParameterBinder CreateCommandParameterBinder(params Type[] commandTypes) { var registry = CreateCommandRegistry(commandTypes); var variables = new VariableCollection(); var replacer = new VariableReplacer(); return(new CommandParameterBinder(registry, replacer, variables)); }
public void ReplaceVariables_VariablesIsNull_ThrowsException() { // arange var sut = new VariableReplacer(); Action sutAction = () => sut.ReplaceVariables(null, new LiteralCommandParameter("input")); // act, assert var ex = Assert.Throws <ArgumentNullException>(sutAction); Assert.Equal("variables", ex.ParamName); }
public void ReplaceVariables_InputIsEmpty_ReturnsEmpty() { // arrange var sut = new VariableReplacer(); var variables = new VariableCollection(); // act var result = sut.ReplaceVariables(variables, new AggregateCommandParameter(new LiteralCommandParameter[0])); // assert Assert.Empty(result); }
public void ReplaceVariables_InputIsNull_ThrowsException() { // arange var sut = new VariableReplacer(); var variables = new VariableCollection(); Action sutAction = () => sut.ReplaceVariables(variables, null); // act, assert var ex = Assert.Throws <ArgumentNullException>(sutAction); Assert.Equal("input", ex.ParamName); }
public void ReplaceVariables_VariableNotSet_ThrowsException() { // arrange var sut = new VariableReplacer(); var variables = new VariableCollection(); Action sutAction = () => sut.ReplaceVariables(variables, new VariableCommandParameter("foo")); // act, assert var ex = Assert.Throws <UnsetVariableException>(sutAction); Assert.Equal("foo", ex.VariableName); }
public void ReplaceVariables_NoVariablesInInput_ReturnsInput() { // arrange var sut = new VariableReplacer(); var variables = new VariableCollection(); var input = "Input without variables"; // act var result = sut.ReplaceVariables(variables, new LiteralCommandParameter(input)); // assert Assert.Equal(input, result); }
public void ReplaceVariables_InputContainsSetVariable_ReplacesVariable(CommandParameter input, string expected) { // arrange var sut = new VariableReplacer(); var variables = new VariableCollection(); variables.Set(new ValueVariable("foo", "bar")); // act var result = sut.ReplaceVariables(variables, input); // assert Assert.Equal(expected, result); }
public void Bind_NumberedParameterContainsVariable_VariableIsReplaced() { // arrange var registry = CreateCommandRegistry(typeof(NumericNumberedParameterCommand)); var variables = new VariableCollection(); variables.Set(new ValueVariable("foo", "10")); var replacer = new VariableReplacer(); var sut = new CommandParameterBinder(registry, replacer, variables); var command = new NumericNumberedParameterCommand(); var input = CreateCommandInput("command", new VariableCommandParameter("foo")); // act var result = sut.Bind(command, input); // assert Assert.True(result.Success); Assert.Equal(10, command.NumberedParameter); }
public void Bind_NamedParameterContainsVariable_VariableIsReplaced() { // arrange var registry = CreateCommandRegistry(typeof(NamedParameterCommand)); var variables = new VariableCollection(); variables.Set(new ValueVariable("foo", "bar")); var replacer = new VariableReplacer(); var sut = new CommandParameterBinder(registry, replacer, variables); var command = new NamedParameterCommand(); var input = CreateCommandInput("nam", new ParameterNameCommandParameter("param1"), new VariableCommandParameter("foo")); // act var result = sut.Bind(command, input); // assert Assert.True(result.Success); Assert.Equal("bar", command.NamedParameter1); }
private static SqlExpression ReplaceAliasedVariables(SqlExpression expression, IList<SelectColumn> selectedColumns) { var replacer = new VariableReplacer(selectedColumns); return replacer.Visit(expression); }
private static SqlExpression ReplaceAliasedVariables(SqlExpression expression, IList <SelectColumn> selectedColumns) { var replacer = new VariableReplacer(selectedColumns); return(replacer.Visit(expression)); }
public void SetUp() { theReplacer = new VariableReplacer(); theLocator = new InMemoryServiceLocator(); theGameState = new StubGameState(); theVars = new SimpleDictionary<string, string>(); theContext = new ScriptContext("1", "Name", CancellationToken.None, theLocator, theVars); theLocator.Add<IGameState>(theGameState); }