Esempio n. 1
0
        private void CreateParameters(string param1Value, string param2Value)
        {
            container1 = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND);
            acDataset.RootFilterContainer_ID = container1.ID;
            acDataset.SaveToDatabase();

            AggregateFilter filter1 = new AggregateFilter(CatalogueRepository, "Filter1", container1);

            filter1.WhereSQL = "@bob = 'bob'";
            filter1.SaveToDatabase();

            var paramCreator = new ParameterCreator(filter1.GetFilterFactory(), null, null);

            paramCreator.CreateAll(filter1, null);

            container2 = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND);
            acCohort.RootFilterContainer_ID = container2.ID;
            acCohort.SaveToDatabase();

            AggregateFilter filter2 = new AggregateFilter(CatalogueRepository, "Filter2", container2);

            filter2.WhereSQL = "@bob = 'fish'";
            filter2.SaveToDatabase();

            paramCreator.CreateAll(filter2, null);

            parama1       = filter1.GetAllParameters()[0];
            parama1.Value = param1Value;
            parama1.SaveToDatabase();

            parama2       = filter2.GetAllParameters()[0];
            parama2.Value = param2Value;
            parama2.SaveToDatabase();
        }
Esempio n. 2
0
        public void SingleParameterTest_ParameterAlreadyExists_CreateNotCalled()
        {
            var p = new Mock <ISqlParameter>();//save should be called because there is no VAlue on the parameter

            p.Setup(m => m.SaveToDatabase());

            var existingParameter = Mock.Of <ISqlParameter>(x =>
                                                            x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper() &&
                                                            x.ParameterName == "@bob"
                                                            );

            var f = Mock.Of <IFilter>(x =>
                                      x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper() &&
                                      x.WhereSQL == "@bob = 'bob'" &&
                                      x.GetAllParameters() == new[] { existingParameter });

            var factory = new Mock <IFilterFactory>();

            var creator = new ParameterCreator(factory.Object, null, null);

            creator.CreateAll(f, null);
            creator.CreateAll(f, null);
            creator.CreateAll(f, null);//no matter how many times we call create it shouldn't make more because there is already one

            p.Verify(m => m.SaveToDatabase(), Times.Never);
            factory.Verify(m => m.CreateNewParameter(f, It.IsAny <string>()), Times.Never); //should never be called because the filter already has
        }
Esempio n. 3
0
        public void SingleParameterTest_Template_TemplateValuesUsed()
        {
            //The constructor returns
            var pstub = Mock.Of <ISqlParameter>();

            //The filter that requires that the parameters be created
            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            f.WhereSQL = "@bob = 'bob'";

            //The template which is an existing known about parameter from the master filter that is being duplicated.  This template will be spotted and used to make the new parameter match the cloned filter's one
            var template = Mock.Of <ISqlParameter>(x => x.ParameterName == "@bob");

            template.ParameterSQL = "DECLARE @bob AS int";
            template.Value        = "5";
            template.Comment      = "fish";

            var factory = new Mock <IFilterFactory>();

            factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS int")).Returns(pstub);

            var creator = new ParameterCreator(factory.Object, null, new [] { template });

            creator.CreateAll(f, null);

            Assert.AreEqual("5", pstub.Value);
            Assert.AreEqual("fish", pstub.Comment);

            factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS int"), Times.Once);
        }
Esempio n. 4
0
        private IFilter CreateFilter(Catalogue cata, string name, string parentExtractionInformation, string whereSql, string desc)
        {
            var filter = new ExtractionFilter(_repos.CatalogueRepository, name, GetExtractionInformation(cata, parentExtractionInformation));

            filter.WhereSQL    = whereSql;
            filter.Description = desc;
            filter.SaveToDatabase();

            var parameterCreator = new ParameterCreator(filter.GetFilterFactory(), null, null);

            parameterCreator.CreateAll(filter, null);

            return(filter);
        }
Esempio n. 5
0
        private bool BeforeSave(DatabaseEntity databaseEntity)
        {
            SubstituteQueryEditorTextIfContainsLineComments();
            OfferWrappingIfUserIncludesANDOrOR();

            //update SQL
            _extractionFilter.WhereSQL = QueryEditor.Text.TrimEnd();

            var creator = new ParameterCreator(_extractionFilter.GetFilterFactory(), GlobalFilterParameters, null);

            creator.CreateAll(_extractionFilter, null);

            return(true);
        }
Esempio n. 6
0
        public void SingleParameterTest_NullReturnFromConstruct_Throws()
        {
            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            f.WhereSQL = "@bob = 'bob'";

            var factory = Mock.Of <IFilterFactory>(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);") == null);

            var creator = new ParameterCreator(factory, null, null);

            var ex = Assert.Throws <NullReferenceException>(() => creator.CreateAll(f, null));

            Assert.IsTrue(ex.Message.StartsWith("Parameter construction method returned null"));
        }
Esempio n. 7
0
        public void NoParametersTest_CreateNotCalled()
        {
            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            var factory = new Mock <IFilterFactory>();

            factory.Verify(m => m.CreateNewParameter(It.IsAny <IFilter>(), It.IsAny <string>()), Times.Never);

            var creator = new ParameterCreator(factory.Object, new ISqlParameter[0], null);

            creator.CreateAll(f, null);

            factory.Verify();
        }
Esempio n. 8
0
        public void SingleParameterTest_GlobalButNotSameName_CreateCalled()
        {
            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            f.WhereSQL = "@bob = 'bob'";

            var global = Mock.Of <ISqlParameter>(x => x.ParameterName == "@bob");

            var factory = new Mock <IFilterFactory>();

            factory.Setup <ISqlParameter>(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);")).Returns(Mock.Of <ISqlParameter>);

            var creator = new ParameterCreator(factory.Object, null, null);

            creator.CreateAll(f, null);

            factory.Verify <ISqlParameter>(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);"), Times.Once);
        }
Esempio n. 9
0
        public void SingleParameterTest_GlobalOverrides_CreateNotCalled()
        {
            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            f.WhereSQL = "@bob = 'bob'";

            var global = Mock.Of <ISqlParameter>(x => x.ParameterName == "@bob");

            var factory = new Mock <IFilterFactory>();

            factory
            .Setup(m => m.CreateNewParameter(It.IsAny <IFilter>(), It.IsAny <string>()))
            .Throws <InvalidOperationException>();

            var creator = new ParameterCreator(factory.Object, new[] { global }, null);

            creator.CreateAll(f, null);

            factory.Verify();
        }
Esempio n. 10
0
        public void SingleParameterTest_OneParameter_CreateCalled()
        {
            var p = new Mock <ISqlParameter>();//save should be called because there is no VAlue on the parameter

            p.Setup(m => m.SaveToDatabase());

            var f = Mock.Of <IFilter>(x => x.GetQuerySyntaxHelper() == new MicrosoftQuerySyntaxHelper());

            f.WhereSQL = "@bob = 'bob'";

            var factory = new Mock <IFilterFactory>();

            factory.Setup(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);")).Returns(p.Object);

            var creator = new ParameterCreator(factory.Object, null, null);

            creator.CreateAll(f, null);

            p.Verify(m => m.SaveToDatabase(), Times.Once);
            p.Verify();
            factory.Verify(m => m.CreateNewParameter(f, "DECLARE @bob AS varchar(50);"), Times.Once);
        }