public void CanDetectDependantParams()
        {
            var repConfig = new CrcReportConfig();
            repConfig.Path = "TestReport";
            repConfig.CrcParamConfigs = new List<CrcReportConfig.CrcParamConfig>();
            repConfig.CrcParamConfigs.Add(new CrcReportConfig.CrcParamConfig()
            {
                ParamName = "ParamOne",
                DependantParams = new List<string>() { "ParamThree" }
            });

            Assert.IsTrue(repConfig.DependantParamsSpecified);
        }
        public void CanSerializeAndDeserializeConfig()
        {
            var confTest = new CrcExtraConfiguration();
            confTest.Version = 2;
            var repTest = new CrcReportConfig();
            repTest.Path = "Test";
            repTest.IsFeatured = true;
            confTest.CrcReportConfigs = new List<CrcReportConfig>();
            confTest.CrcReportConfigs.Add(repTest);
            CrcExtraConfiguration.Serialize("TestConfig.xml", confTest);

            var getItBack = CrcExtraConfiguration.Deserialize("TestConfig.xml");
            Assert.AreEqual(2, getItBack.Version);
            Assert.AreEqual(1, getItBack.CrcReportConfigs.Count());
            Assert.AreEqual("Test", getItBack.CrcReportConfigs[0].Path);
            Assert.AreEqual(true, getItBack.CrcReportConfigs[0].IsFeatured);
        }
        public void CanSerializeWithParams()
        {
            var confTest = new CrcExtraConfiguration();
            confTest.Version = 2;
            var repTest = new CrcReportConfig();
            repTest.Path = "Test";
            repTest.IsFeatured = true;
            var paramTest = new CrcReportConfig.CrcParamConfig();
            paramTest.ParamName = "TestParam";
            paramTest.ShowByDefault = true;
            repTest.CrcParamConfigs = new List<CrcReportConfig.CrcParamConfig>();
            repTest.CrcParamConfigs.Add(paramTest);
            confTest.CrcReportConfigs = new List<CrcReportConfig>();
            confTest.CrcReportConfigs.Add(repTest);

            CrcExtraConfiguration.Serialize("TestConfigWithParams.xml", confTest);
        }
        public void CanSerializeAndDeserializeConfigWithEmptyEquivalentValues()
        {
            var confTest = new CrcExtraConfiguration();
            confTest.Version = 2;
            var repTest = new CrcReportConfig();
            repTest.Path = "Test";
            repTest.IsFeatured = true;
            confTest.CrcReportConfigs = new List<CrcReportConfig>();
            confTest.CrcReportConfigs.Add(repTest);

            List<string> empties = new List<string>() { "", "%%", null };
            confTest.DefaultEmptyEquivalentValues = empties;

            CrcExtraConfiguration.Serialize("TestConfig2.xml", confTest);

            var getItBack = CrcExtraConfiguration.Deserialize("TestConfig2.xml");
            Assert.AreEqual(2, getItBack.Version);
            Assert.AreEqual(1, getItBack.CrcReportConfigs.Count());
            Assert.AreEqual("Test", getItBack.CrcReportConfigs[0].Path);
            Assert.AreEqual(true, getItBack.CrcReportConfigs[0].IsFeatured);
            Assert.AreEqual(3, getItBack.DefaultEmptyEquivalentValues.Count());
        }
        public void CanMakeReportWithHintFromExtraConfig()
        {
            var mf = new TestDoubles.MockSsrsWebServiceFactory();
            var paramArray = mf.MakeSimpleTestParameters();

            var configMock = MockRepository.GenerateMock<CrcExtraConfiguration>();
            var repConfig = new CrcReportConfig();
            repConfig.Path = "TestReport";
            repConfig.ReportHint = "This is a report hint";
            configMock.Expect(m => m.GetReportConfig(null)).IgnoreArguments().Return(repConfig);

            // 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("This is a report hint", repDefn.ReportHint);
        }
        public void CanMakeReportWithExtraConfigSpecificEmptyEquivalents()
        {
            var mf = new TestDoubles.MockSsrsWebServiceFactory();
            var paramArray = mf.MakeSimpleTestParameters();

            var extraConfig = new CrcExtraConfiguration();
            var repConfig = new CrcReportConfig();
            repConfig.Path = "TestReport";
            repConfig.CrcParamConfigs = new List<CrcReportConfig.CrcParamConfig>();
            repConfig.CrcParamConfigs.Add(new CrcReportConfig.CrcParamConfig()
            {
                ParamName = "ParamOne",
                EmptyEquivalentValues = new List<string>() { "Value1" }
            });
            extraConfig.CrcReportConfigs.Add(repConfig);

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

            Assert.IsNotNull(repDefn);
            Assert.AreEqual("TestReport", repDefn.ReportPath);
            Assert.AreEqual(2, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamOne");
            Assert.IsNotNull(p1check);
            Assert.AreEqual(1, p1check.EmptyEquivalentValues.Count());
            Assert.IsTrue(p1check.EmptyEquivalentValues.Contains("Value1"));
        }
        public void CanMakeReportWithExtraConfigDependants()
        {
            var mf = new TestDoubles.MockSsrsWebServiceFactory();
            var paramArray = mf.MakeDependantTestParameters();

            var configMock = MockRepository.GenerateMock<CrcExtraConfiguration>();
            var repConfig = new CrcReportConfig();
            repConfig.Path = "TestReport";
            repConfig.CrcParamConfigs = new List<CrcReportConfig.CrcParamConfig>();
            repConfig.CrcParamConfigs.Add(new CrcReportConfig.CrcParamConfig()
            {
                ParamName = "ParamOne",
                DependantParams = new List<string>() { "ParamThree" }
            });
            configMock.Expect(m => m.GetReportConfig(null)).IgnoreArguments().Return(repConfig);
            configMock.Expect(m => m.DefaultEmptyEquivalentValues).Return(new List<string>());

            // 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(3, repDefn.ParameterDefinitions.Count());
            var p1check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamOne");
            Assert.IsNotNull(p1check);
            Assert.AreEqual(1, p1check.DependantParameterNames.Count());
            Assert.IsTrue(p1check.DependantParameterNames.Contains("ParamThree"));

            var p2check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamTwo");
            Assert.IsNotNull(p2check);
            Assert.AreEqual(0, p2check.DependantParameterNames.Count());

            var p3check = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "ParamThree");
            Assert.IsNotNull(p3check);
            Assert.AreEqual(0, p3check.DependantParameterNames.Count());
        }
        public void AddParameterDefinitions(rws.ReportParameter[] 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;
                if (paramLoop.Type == rws.ParameterTypeEnum.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.Type == rws.ParameterTypeEnum.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);
            }
        }