public void CanMakeReportAndDetectEmptySelect()
        {
            // sometimes dependant selects can be empty at first
            // they are always query based though
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name                  = "ParamSelect";
            p1.Nullable              = false;
            p1.ParameterTypeName     = CrcReportDefinitionFactory.ReportServiceParameterTypes.String;
            p1.ValidValuesQueryBased = true;
            p1.ValidValues           = null;
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(1, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamSelect");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(CrcParameterType.Select, p1check.ParameterType);
        }
        public void RefreshParameter_CanHandleNulls()
        {
            var pd = new CrcParameterDefinition();

            pd.Name            = "TestParam";
            pd.ParameterChoice = new CrcParameterChoice(pd.Name);
            pd.ParameterChoice.Values.Add("Value1");
            pd.ParameterChoice.Values.Add("Value2");
            pd.ParameterChoice.Values.Add("Value3");

            var latestParam = new rws.ItemParameter();

            latestParam.Name          = "TestParam";
            latestParam.ValidValues   = null;
            latestParam.DefaultValues = null;


            var r = new CrcParameterRefresher();

            r.RefreshParameter(pd, latestParam);

            Assert.IsNotNull(pd);
            Assert.AreEqual("TestParam", pd.Name);
            Assert.AreEqual(0, pd.ParameterChoice.Values.Count());
        }
        public void CanMakeReportAndDetectNormalBoolField()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name                  = "ParamBool";
            p1.Nullable              = false;
            p1.ParameterTypeName     = CrcReportDefinitionFactory.ReportServiceParameterTypes.Boolean;
            p1.ValidValuesQueryBased = false;
            p1.ValidValues           = null;
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(1, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamBool");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(CrcParameterType.Boolean, p1check.ParameterType);
        }
        public void CanMakeReportAndApplyRequiredFromUserToDateParams()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name = "ParamWithDefault";
            p1.ParameterTypeName = CrcReportDefinitionFactory.ReportServiceParameterTypes.DateTime;
            p1.DefaultValues     = new string[] { "01/Jan/2011" };
            p1.Nullable          = false;
            rws.ItemParameter p2 = new rws.ItemParameter();
            p2.Name = "ParamWithoutDefault";
            p2.ParameterTypeName = CrcReportDefinitionFactory.ReportServiceParameterTypes.DateTime;
            p2.DefaultValues     = new string[] { };
            p2.Nullable          = false;
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1, p2 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(2, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamWithDefault");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(false, p1check.RequiredFromUser, "RequiredFromUser expected false");
            var p2check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamWithoutDefault");

            Assert.IsNotNull(p2check);
            Assert.AreEqual(true, p2check.RequiredFromUser, "RequiredFromUser expected true");
        }
Пример #5
0
 public void RefreshParameter(CrcParameterDefinition paramDefn, rws.ItemParameter latestParamDetails)
 {
     logger.DebugFormat("Updating {0} with {1} valid values", paramDefn.Name,
                        (latestParamDetails.ValidValues != null) ? latestParamDetails.ValidValues.Count().ToString() : "null");
     UpdateValidValues(paramDefn, latestParamDetails.ValidValues);
     if (!IsChoiceValid(paramDefn))
     {
         logger.DebugFormat("Param {0} choices are now invalid so applying {1} default values", paramDefn.Name,
                            (latestParamDetails.DefaultValues != null) ? latestParamDetails.DefaultValues.Count().ToString() : "null");
         UpdateDefaultValues(paramDefn, latestParamDetails.DefaultValues);
     }
 }
        public void CanMakeReportAndApplyRequiredFromUserToMultipicks()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name        = "ParamWithDefault";
            p1.ValidValues = new rws.ValidValue[] { new rws.ValidValue()
                                                    {
                                                        Label = "--All--", Value = "%%"
                                                    },
                                                    new rws.ValidValue()
                                                    {
                                                        Label = "Label1", Value = "Value1"
                                                    },
                                                    new rws.ValidValue()
                                                    {
                                                        Label = "Label2", Value = "Value2"
                                                    } };
            p1.DefaultValues = new string[] { "%%" };
            p1.Nullable      = false;
            rws.ItemParameter p2 = new rws.ItemParameter();
            p2.Name        = "ParamWithoutDefault";
            p2.ValidValues = new rws.ValidValue[] {
                new rws.ValidValue()
                {
                    Label = "Label3", Value = "Value3"
                },
                new rws.ValidValue()
                {
                    Label = "Label4", Value = "Value4"
                }
            };
            p2.DefaultValues = new string[] { };
            p2.Nullable      = false;
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1, p2 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(2, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamWithDefault");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(false, p1check.RequiredFromUser, "RequiredFromUser expected false");
            var p2check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamWithoutDefault");

            Assert.IsNotNull(p2check);
            Assert.AreEqual(true, p2check.RequiredFromUser, "RequiredFromUser expected true");
        }
        public void CanMakeReportAndDetectBoolFieldWithYesNoValues()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name                  = "ParamBool";
            p1.Nullable              = false;
            p1.ParameterTypeName     = CrcReportDefinitionFactory.ReportServiceParameterTypes.Boolean;
            p1.ValidValuesQueryBased = false;
            p1.ValidValues           = new rws.ValidValue[] {
                new rws.ValidValue()
                {
                    Label = "Yes", Value = "true"
                },
                new rws.ValidValue()
                {
                    Label = "No", Value = "false"
                }
            };
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(1, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamBool");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(CrcParameterType.Select, p1check.ParameterType);
            Assert.AreEqual(2, p1check.ValidValues.Count());
            var v1 = p1check.ValidValues.FirstOrDefault(v => v.Value == "true");

            Assert.IsNotNull(v1);
            Assert.AreEqual("Yes", v1.Label);
            var v2 = p1check.ValidValues.FirstOrDefault(v => v.Value == "false");

            Assert.IsNotNull(v2);
            Assert.AreEqual("No", v2.Label);
        }
        public void CanMakeReportWithNoReportConfigButIncludeDefaultEmptyEquivalents()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name        = "ParamOne";
            p1.ValidValues = new rws.ValidValue[] { new rws.ValidValue()
                                                    {
                                                        Label = "--All--", Value = "%%"
                                                    },
                                                    new rws.ValidValue()
                                                    {
                                                        Label = "Label1", Value = "Value1"
                                                    },
                                                    new rws.ValidValue()
                                                    {
                                                        Label = "Label2", Value = "Value2"
                                                    } };
            p1.DefaultValues = new string[] { };
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            configMock.Expect(m => m.DefaultEmptyEquivalentValues).Return(new List <string>()
            {
                "", "%%"
            });
            configMock.Expect(m => m.GetReportConfig(null)).IgnoreArguments().Return(null);

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(1, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamOne");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(3, p1check.ValidValues.Count());
            Assert.IsTrue(p1check.EmptyEquivalentValues.Count() > 0);
        }
        public void CanMakeReportAndDetectMultipickSelect()
        {
            rws.ItemParameter p1 = new rws.ItemParameter();
            p1.Name                  = "ParamSelect";
            p1.Nullable              = false;
            p1.ParameterTypeName     = CrcReportDefinitionFactory.ReportServiceParameterTypes.String;
            p1.ValidValuesQueryBased = false;
            p1.ValidValues           = new rws.ValidValue[] { new rws.ValidValue()
                                                              {
                                                                  Label = "--All--", Value = "%%"
                                                              },
                                                              new rws.ValidValue()
                                                              {
                                                                  Label = "Label1", Value = "Value1"
                                                              },
                                                              new rws.ValidValue()
                                                              {
                                                                  Label = "Label2", Value = "Value2"
                                                              } };
            p1.MultiValue = true;
            rws.ItemParameter[] paramArray = new rws.ItemParameter[] { p1 };

            var configMock = MockRepository.GenerateMock <CrcExtraConfiguration>();

            // make main service obj
            var factory = new CrcReportDefinitionFactory();
            var repDefn = factory.Create("TestReport", paramArray, configMock);


            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(1, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamSelect");

            Assert.IsNotNull(p1check);
            Assert.AreEqual(CrcParameterType.MultiSelect, p1check.ParameterType);
        }
Пример #10
0
        public void AddParameterDefinitions(rws.ItemParameter[] wsReportParameters, CrcReportDefinition repDef, CrcExtraConfiguration extraConfig, CrcReportConfig reportConfig)
        {
            List <string> showByDefault = new List <string>();

            if (reportConfig != null)
            {
                showByDefault = reportConfig.GetParamsToShowByDefault();
            }
            List <string> defaultEmptyEquivalents = new List <string>();

            if (extraConfig != null && extraConfig.DefaultEmptyEquivalentValues != null)
            {
                defaultEmptyEquivalents = extraConfig.DefaultEmptyEquivalentValues;
            }

            foreach (var paramLoop in wsReportParameters)
            {
                CrcReportConfig.CrcParamConfig paramConfig = null;
                // get extra config for parameter, if there is any
                if (reportConfig != null)
                {
                    paramConfig = reportConfig.CrcParamConfigs.FirstOrDefault(p => p.ParamName == paramLoop.Name);
                }

                var crcParam = new CrcParameterDefinition();
                crcParam.Name       = paramLoop.Name;
                crcParam.id         = "param_" + paramLoop.Name.Replace(" ", "_");
                crcParam.AllowNull  = paramLoop.Nullable;
                crcParam.AllowBlank = paramLoop.AllowBlank;

                if (string.IsNullOrEmpty(paramLoop.Prompt))
                {
                    // if Prompt is null or empty, it means Parameter is 'Hidden' in SSRS
                    crcParam.Hidden      = true;
                    crcParam.DisplayName = paramLoop.Name;
                }
                else
                {
                    crcParam.DisplayName = paramLoop.Prompt;
                }
                if (string.IsNullOrEmpty(crcParam.DisplayName))
                {
                    crcParam.DisplayName = crcParam.Name;
                }
                // if PromptUser is false then Parameter is 'Internal' in SSRS
                if (!paramLoop.PromptUser)
                {
                    crcParam.Hidden = true;
                }
                var a = new rws.ItemParameter();

                if (paramLoop.ParameterTypeName != null && paramLoop.ParameterTypeName.Equals(ReportServiceParameterTypes.DateTime))
                {
                    crcParam.ParameterType = CrcParameterType.Date;
                }
                else if ((paramLoop.ValidValues != null && paramLoop.ValidValues.Count() > 0) ||
                         paramLoop.ValidValuesQueryBased)
                {
                    if (paramLoop.MultiValue)
                    {
                        crcParam.ParameterType = CrcParameterType.MultiSelect;
                    }
                    else
                    {
                        crcParam.ParameterType = CrcParameterType.Select;
                    }
                }
                else if (paramLoop.ParameterTypeName != null && paramLoop.ParameterTypeName.Equals(ReportServiceParameterTypes.Boolean))
                {
                    crcParam.ParameterType = CrcParameterType.Boolean;
                }
                else
                {
                    crcParam.ParameterType = CrcParameterType.Text;
                }


                if (paramLoop.ValidValues != null)
                {
                    foreach (var valLoop in paramLoop.ValidValues)
                    {
                        crcParam.ValidValues.Add(new CrcValidValue()
                        {
                            Value = valLoop.Value, Label = valLoop.Label
                        });
                    }
                    if (crcParam.ValidValues.Count() > 10)
                    {
                        crcParam.AllowListSearch = true;
                    }
                }


                // check config for dependencies
                if (paramConfig != null && paramConfig.DependantParams != null && paramConfig.DependantParams.Count() > 0)
                {
                    logger.DebugFormat("Param {0} has extraconfig dependancies: {1}",
                                       paramLoop.Name, string.Join(", ", paramConfig.DependantParams.ToArray()));
                    foreach (string dpname in paramConfig.DependantParams)
                    {
                        crcParam.DependantParameterNames.Add(dpname);
                    }
                }



                foreach (string sloop in defaultEmptyEquivalents)
                {
                    AddEmptyEquivalent(crcParam, sloop);
                }

                // check for specific empty equivalents for this parameter
                if (paramConfig != null && paramConfig.EmptyEquivalentValues != null)
                {
                    foreach (string sloop in paramConfig.EmptyEquivalentValues)
                    {
                        AddEmptyEquivalent(crcParam, sloop);
                    }
                }



                if (showByDefault.Contains(crcParam.Name))
                {
                    crcParam.AlwaysShow = true;
                }

                repDef.ParameterDefinitions.Add(crcParam);
            }
        }