Esempio n. 1
0
        public void ProcessRequest(HttpContext context)
        {
            var queryStringConverter = new QueryStringConverter();
            var parameters = queryStringConverter
                                .ConvertToParameters(context.Request.QueryString);

            string procedure = queryStringConverter.StoredProcedure;
            string connectionName = queryStringConverter.ConnectionName;

            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;

            List<SourceTarget> sourceTargets = context.Application["SourceTargets"] as List<SourceTarget>;

            //  Does this procedure and connection combo exist
            var matchedSourceTarget = FetchMatchingSourceTarget(procedure,
                                    connectionName,
                                    sourceTargets);

            if (matchedSourceTarget != null)
            {
                var dataProvider = new DataProvider(matchedSourceTarget.ConnectionString, procedure);
                var records = dataProvider.SetParameters(parameters)
                                            .ExecuteStoredProcedure();

                context.Response.Write(JsonConvert.SerializeObject(records));
            }
            else
            {
                context.Response.Write(string.Empty);
            }
        }
Esempio n. 2
0
        public void CanConvertStringOfDatesToString()
        {
            string theDateString = @"12/31/2012,1/1/2011";
            var nvCollection = new NameValueCollection();
            nvCollection.Add("DateString", theDateString);

            var queryStringConverter = new QueryStringConverter();
            var results = queryStringConverter.ConvertToParameters(nvCollection);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(theDateString, results["DateString"].ToString());
        }
Esempio n. 3
0
        public void CanConvertDelimitedStringToParameters()
        {
            //  15,'07/01/09','06/30/10','pai,app'
            string parameterSource = @"AgentID=15;StartDate=07/01/09;EndDate=06/30/10;StatusList=pai,app";

            var queryStringConverter = new QueryStringConverter();
            var converted = queryStringConverter.ConvertToParameters(parameterSource);

            Assert.AreEqual(15, converted["AgentID"]);
        }
Esempio n. 4
0
        public void CanExecProceWithConvertedParms()
        {
            //  15,'07/01/09','06/30/10','pai,app'
            int agentId = 15;
            DateTime startDate = new DateTime(2009, 7, 1);
            DateTime endDate = new DateTime(2010, 6, 30);
            string statusList = "pai,app";

            string procedure = "sp_Report_Agent_Wity_Listing";
            var dataProvider = new DataProvider(connection, procedure);

            var nvCollection = new NameValueCollection();
            nvCollection.Add("AgentId", agentId.ToString());
            nvCollection.Add("StartDate", startDate.ToShortDateString());
            nvCollection.Add("EndDate", endDate.ToShortDateString());
            nvCollection.Add("StatusList", statusList);

            var queryStringConverter = new QueryStringConverter();
            var parameters = queryStringConverter.ConvertToParameters(nvCollection);
            var results = dataProvider.SetParameters(parameters)
                                        .ExecuteStoredProcedure();

            Assert.AreEqual(36, results.Count);
        }
Esempio n. 5
0
        public void CanExcludeProcedureAndConnectionFromConversion()
        {
            string theDateString = @"12/31/2012,1/1/2011";
            var nvCollection = new NameValueCollection();
            nvCollection.Add("DateString", theDateString);
            nvCollection.Add("procedure", "sp_procedure");
            nvCollection.Add("Connection", "the connection");

            var queryStringConverter = new QueryStringConverter();
            var results = queryStringConverter.ConvertToParameters(nvCollection);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(theDateString, results["DateString"].ToString());
            Assert.AreEqual("sp_procedure", queryStringConverter.StoredProcedure);
            Assert.AreEqual("the connection", queryStringConverter.ConnectionName);
        }
Esempio n. 6
0
        public void CanConvertStringToInt()
        {
            var queryStringConverter = new QueryStringConverter();

            var nvCollection = new NameValueCollection();
            nvCollection.Add("TheInteger", "32");

            var results = queryStringConverter.ConvertToParameters(nvCollection);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(32, results["TheInteger"]);
        }
Esempio n. 7
0
        public void CanConvertStringToDateTime()
        {
            var queryStringConverter = new QueryStringConverter();

            var nvCollection = new NameValueCollection();
            var theDate = new DateTime(2012, 12, 31);
            nvCollection.Add("TheDate", theDate.ToShortDateString());

            var results = queryStringConverter.ConvertToParameters(nvCollection);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(theDate, results["TheDate"]);
        }