Ejemplo n.º 1
0
        public FreeTextParameterChangeResult CheckForChanges(string sql)
        {
            try
            {
                string oldName = Parameter.ParameterName;

                ConstantParameter newPrototype;
                newPrototype = ConstantParameter.Parse(sql, _querySyntaxHelper);

                if (string.Equals(newPrototype.Comment, Parameter.Comment)//can be null you see
                    &&
                    string.Equals(newPrototype.Value, Parameter.Value)
                    &&
                    newPrototype.ParameterSQL.Equals(Parameter.ParameterSQL))
                {
                    return(FreeTextParameterChangeResult.NoChangeMade);
                }

                Parameter.Comment      = newPrototype.Comment;
                Parameter.Value        = newPrototype.Value;
                Parameter.ParameterSQL = newPrototype.ParameterSQL;
                Parameter.SaveToDatabase();

                _refactorer.HandleRename(Parameter, oldName, Parameter.ParameterName);


                return(FreeTextParameterChangeResult.ChangeAccepted);
            }
            catch (Exception)
            {
                return(FreeTextParameterChangeResult.ChangeRejected);
            }
        }
Ejemplo n.º 2
0
        public void FindOverridenParameters_TwoTest()
        {
            var myParameter1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", new MicrosoftQuerySyntaxHelper());
            var myParameter2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here", new MicrosoftQuerySyntaxHelper());

            var overridingParameter = new ConstantParameter("DECLARE @fish as int", "3", "overriding value", new MicrosoftQuerySyntaxHelper());

            var pm = new ParameterManager();

            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(myParameter1);
            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.CompositeQueryLevel].Add(myParameter2);
            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.Global].Add(overridingParameter);

            var overrides = pm.GetOverridenParameters().ToArray();

            Assert.IsNull(pm.GetOverrideIfAnyFor(overridingParameter));
            Assert.AreEqual(pm.GetOverrideIfAnyFor(myParameter1), overridingParameter);
            Assert.AreEqual(pm.GetOverrideIfAnyFor(myParameter2), overridingParameter);

            Assert.AreEqual(2, overrides.Length);
            Assert.AreEqual(myParameter1, overrides[0]);
            Assert.AreEqual(myParameter2, overrides[1]);

            var final = pm.GetFinalResolvedParametersList().ToArray();

            Assert.AreEqual(1, final.Length);
            Assert.AreEqual(overridingParameter, final[0]);
        }
Ejemplo n.º 3
0
        public ParameterEditorScintillaSection(ParameterRefactorer refactorer, int lineStart, int lineEnd, ISqlParameter parameter, bool editable, string originalText)
        {
            _refactorer        = refactorer;
            LineStart          = lineStart;
            LineEnd            = lineEnd;
            Parameter          = parameter;
            Editable           = editable;
            _querySyntaxHelper = parameter.GetQuerySyntaxHelper();

            var prototype = ConstantParameter.Parse(originalText, _querySyntaxHelper);

            if (prototype.Value != parameter.Value)
            {
                throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different Values");
            }

            if (prototype.ParameterSQL != parameter.ParameterSQL)
            {
                throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different ParameterSQL");
            }

            if (prototype.Comment != parameter.Comment)
            {
                throw new ArgumentException("Parameter " + parameter + " was inconsistent with the SQL passed to us based on QueryBuilder.DeconstructStringIntoParameter, they had different Comment");
            }
        }
Ejemplo n.º 4
0
        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof(DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int         size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter)instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return(mutablePicoContainer);
        }
Ejemplo n.º 5
0
        public void Test_ParameterManager_SimpleRename()
        {
            var p1 = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", new MicrosoftQuerySyntaxHelper());
            var p2 = new ConstantParameter("DECLARE @fish as int", "2", "fishes be here", new MicrosoftQuerySyntaxHelper());

            var pm1 = new ParameterManager();
            var pm2 = new ParameterManager();
            var pm3 = new ParameterManager();

            pm1.ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Add(p1);
            pm2.ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Add(p2);

            pm3.ImportAndElevateResolvedParametersFromSubquery(pm1, out Dictionary <string, string> renames1);
            pm3.ImportAndElevateResolvedParametersFromSubquery(pm2, out Dictionary <string, string> renames2);

            var final = pm3.GetFinalResolvedParametersList().ToArray();

            //the final composite parameters should have a rename in them
            Assert.AreEqual("@fish", final[0].ParameterName);
            Assert.AreEqual("@fish_2", final[1].ParameterName);

            Assert.IsEmpty(renames1);

            Assert.AreEqual("@fish", renames2.Single().Key);
            Assert.AreEqual("@fish_2", renames2.Single().Value);
        }
Ejemplo n.º 6
0
        public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer)
        {
            var dto = value switch
            {
                ConstantParameter constantParameter => new Dto(ParameterType.Constant, constantParameter.Value.Map <JToken>() ?? JValue.CreateNull()),
                VariableParameter variableParameter => new Dto(ParameterType.Variable, variableParameter.Path),
                ExpressionParameter expressionParameter => new Dto(ParameterType.Expression, expressionParameter.Code),
                _ => throw new NotImplementedException(),
            };

            serializer.Serialize(writer, dto);
        }
Ejemplo n.º 7
0
        public void ReadJsonShouldNotReturnParameterForNonParameterObject()
        {
            // Arrange
            var converter = new ParameterConverter();
            var type      = typeof(IParameter);
            var json      = @"{""asdf"":""1234""}";
            var expected  = new ConstantParameter(JToken.FromObject(new { asdf = "1234" }));

            using var reader = new JsonTextReader(new StringReader(json));
            var serializer = Mock.Of <JsonSerializer>();

            // Act
            var result = converter.ReadJson(reader, type, default, serializer);
Ejemplo n.º 8
0
        public void ParameterDeclarationAndDeconstruction()
        {
            var param = new ConstantParameter("DECLARE @Fish as int;", "3", "I've got a lovely bunch of coconuts", new MicrosoftQuerySyntaxHelper());
            var sql   = QueryBuilder.GetParameterDeclarationSQL(param);

            Assert.AreEqual(@"/*I've got a lovely bunch of coconuts*/
DECLARE @Fish as int;
SET @Fish=3;
", sql);

            var after = ConstantParameter.Parse(sql, new MicrosoftQuerySyntaxHelper());

            Assert.AreEqual(param.ParameterSQL, after.ParameterSQL);
            Assert.AreEqual(param.Value, after.Value);
            Assert.AreEqual(param.Comment, after.Comment);
        }
Ejemplo n.º 9
0
        public IStoreConfiguration <TState> UseReducer <TReducerType, TSectionType>(Expression <StateSubSectionSelectionDelegate <TState, TSectionType> > sectionSelector)
            where TReducerType : IReducer <TSectionType>
        {
            Type reducerType = typeof(ReducerSection <TState, TReducerType, TSectionType>);

            IParameter[] parameters = new IParameter[]
            {
                ConstantParameter.Create <ITypeRequest>("subReducer", new TypeRequest(typeof(TReducerType))),
                ConstantParameter.Create <Expression <StateSubSectionSelectionDelegate <TReducerType, TSectionType> > >(nameof(sectionSelector), sectionSelector)
            };

            TypeRequest typeRequest = new TypeRequest(reducerType, parameters);

            m_reducers.Add(typeRequest);
            return(this);
        }
Ejemplo n.º 10
0
        public void FindOverridenParameters_CaseSensitivityTest()
        {
            var baseParameter       = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", new MicrosoftQuerySyntaxHelper());
            var overridingParameter = new ConstantParameter("DECLARE @Fish as int", "3", "overriding value", new MicrosoftQuerySyntaxHelper());

            var pm = new ParameterManager();

            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(baseParameter);
            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Add(overridingParameter);

            var parameters = pm.GetFinalResolvedParametersList().ToArray();

            Assert.AreEqual(1, parameters.Count());

            var final = parameters.Single();

            Assert.AreEqual("@Fish", final.ParameterName);
            Assert.AreEqual("3", final.Value);
        }
Ejemplo n.º 11
0
        private void AddWHEREToBuilder_CategoryIsTOrNumberGreaterThan42(AggregateBuilder builder, DatabaseType type)
        {
            var syntaxHelper = new QuerySyntaxHelperFactory().Create(type);
            var declaration  = syntaxHelper.GetParameterDeclaration("@category", new DatabaseTypeRequest(typeof(string), 1));

            var repo = new MemoryCatalogueRepository();

            var ORContainer = new SpontaneouslyInventedFilterContainer(repo, null, null, FilterContainerOperation.OR);
            var constParam  = new ConstantParameter(declaration, "'T'", "T Category Only", syntaxHelper);

            //this is deliberately duplication, it tests that the parameter compiles as well as that any dynamic sql doesn't get thrown by quotes
            var filter1 = new SpontaneouslyInventedFilter(repo, ORContainer, "(Category=@category OR Category = 'T')", "Category Is @category",
                                                          "ensures the records belong to the category @category", new ISqlParameter[] { constParam });
            var filter2 = new SpontaneouslyInventedFilter(repo, ORContainer, "NumberInTrouble > 42",
                                                          "number in trouble greater than 42", "See above", null);

            ORContainer.AddChild(filter1);
            ORContainer.AddChild(filter2);

            builder.RootFilterContainer = ORContainer;
        }
Ejemplo n.º 12
0
        public void FindOverridenParameters_OneOnlyTest(ParameterLevel addAt, ParameterLevel overridingLevel)
        {
            var myParameter         = new ConstantParameter("DECLARE @fish as int", "1", "fishes be here", new MicrosoftQuerySyntaxHelper());
            var overridingParameter = new ConstantParameter("DECLARE @fish as int", "999", "overriding value", new MicrosoftQuerySyntaxHelper());

            var pm = new ParameterManager();

            pm.ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Add(myParameter);
            pm.ParametersFoundSoFarInQueryGeneration[overridingLevel].Add(overridingParameter);

            var overrides = pm.GetOverridenParameters().ToArray();

            Assert.IsNull(pm.GetOverrideIfAnyFor(overridingParameter));
            Assert.AreEqual(pm.GetOverrideIfAnyFor(myParameter), overridingParameter);

            Assert.AreEqual(1, overrides.Length);
            Assert.AreEqual(myParameter, overrides[0]);
            var final = pm.GetFinalResolvedParametersList().ToArray();

            Assert.AreEqual(1, final.Length);
            Assert.AreEqual(overridingParameter, final[0]);
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ConstantParameter obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 14
0
        public TStoreType CreateStore <TStoreType>() where TStoreType : IStore <TState>
        {
            if (m_activatorTypeRequest == null)
            {
                throw new MissingActivatorException();
            }

            List <IReducer <TState> > reducers    = new List <IReducer <TState> >();
            List <IMiddleware>        middlewares = new List <IMiddleware>();
            List <IParameter>         parameters  = new List <IParameter>();

            // Create activator
            IActivator activator = DefaultActivator.Get <IActivator>(m_activatorTypeRequest);

            parameters.Add(ConstantParameter.Create <IActivator>(nameof(activator), activator));

            // Logging
            ILog logger = activator.Get <ILog>(m_loggerTypeRequest);

            parameters.Add(new ConstantParameter("log", logger, typeof(ILog)));

            foreach (ITypeRequest singletonRequest in m_singletonTypeRequests)
            {
                object instance = activator.Get(singletonRequest, parameters);

                IParameter parameter = new ConstantParameter("", instance, singletonRequest.Type);

                parameters.Add(parameter);
            }

            foreach (ITypeRequest reducerTypeRequest in m_reducers)
            {
                IReducer <TState> reducer = activator.Get <IReducer <TState> >(reducerTypeRequest, parameters);
                reducers.Add(reducer);
            }

            ReducerMiddleware <TState> rootDispatcher = new ReducerMiddleware <TState>(reducers);

            ActionDispatchDelegate next = rootDispatcher.InvokeAsync;

            foreach (ITypeRequest middlewareTypeRequest in m_middleware)
            {
                IParameter          nextParameter      = ConstantParameter.Create <ActionDispatchDelegate>("next", next);
                IAbstractMiddleware abstractMiddleware = activator.Get <IAbstractMiddleware>(middlewareTypeRequest, parameters.Clone(nextParameter));
                switch (abstractMiddleware)
                {
                case IMiddleware middleware:
                    next = (p) => middleware.InvokeAsync(p);
                    break;

                case IMiddleware <TState> typedMiddleware:
                    next = (p) => typedMiddleware.InvokeAsync((ActionContext <TState>)p);
                    break;

                default:
                    throw new InvalidMiddlewareException(abstractMiddleware.GetType());
                }
            }

            IList <IParameter> storeParameters = parameters.Clone(
                ConstantParameter.Create <TState>("state", m_initialState),
                ConstantParameter.Create <ActionDispatchDelegate>("dispatch", next)
                );

            TypeRequest storeRequest = new TypeRequest(typeof(TStoreType));

            TStoreType store = DefaultActivator.Get <TStoreType>(storeRequest, storeParameters);

            return(store);
        }