Ejemplo n.º 1
0
        public void MoreClosedBrackets()
        {
            string[] s1      = { "X", "Y", "Z" };
            string[] s2      = { "1", "2", "3" };
            var      string1 = new ParseStrings("noX}and{Y}and{X}w}ee}", s1, s2);

            Assert.IsTrue(false == string1.string_valid);
        }
Ejemplo n.º 2
0
        public void NoOpenBracket()
        {
            string[] s1      = { "X", "Y", "Z" };
            string[] s2      = { "1", "2", "3" };
            var      string1 = new ParseStrings("noX}and{Yand{X}we", s1, s2);

            Assert.IsTrue(false == string1.string_valid);
        }
Ejemplo n.º 3
0
        public void SimpleTest()
        {
            string[] s1      = { "X", "Y", "Z" };
            string[] s2      = { "1", "2", "3" };
            var      string1 = new ParseStrings("no{X}and{Y}and{Z}we", s1, s2);

            Assert.IsTrue("no1and2and3we" == string1.res);
        }
Ejemplo n.º 4
0
        public void NoClosedBracket()
        {
            string[] s1      = { "X", "Y", "Z" };
            string[] s2      = { "1", "2", "3" };
            var      string1 = new ParseStrings("no{XandYandXwe", s1, s2);

            Assert.IsTrue(false == string1.string_valid);
        }
Ejemplo n.º 5
0
        public void ArraysDifferentLength()
        {
            string[] s1      = { "X", "Y", "Z", "A" };
            string[] s2      = { "1", "2" };
            var      string1 = new ParseStrings("no{X}and{Y}awe", s1, s2);

            Assert.IsTrue(false == string1.arrays_valid);
        }
Ejemplo n.º 6
0
        public void NullSimpleTest()
        {
            string[] s1      = { "X", "Y", "Z" };
            string[] s2      = { "0", null, "3" };
            var      string1 = new ParseStrings("no{X}and{Y}and{X}we", s1, s2);

            Assert.IsTrue("no0andand0we" == string1.res);
        }
Ejemplo n.º 7
0
        public void ParseSplitDistanceStringTest()
        {
            // get test data
            string splitDistanceString = Convert.ToString(TestContext.DataRow["splitDistanceString"]);
            double expectedDistance    = Convert.ToDouble(TestContext.DataRow["distance"]);

            double distance = -1;

            // run test
            ParseStrings.ParseSplitDistanceString(splitDistanceString, ref distance);

            // validate results
            Assert.AreEqual(expectedDistance, distance, "distance differed.");
        }
Ejemplo n.º 8
0
        public void ParsePaceTypeTest()
        {
            // create a Data object
            Data expectedData = new Data();

            Data.PaceTypes actualPaceType = expectedData.PaceType;

            // get test data
            string paceType = Convert.ToString(TestContext.DataRow["PaceType"]);

            // determine the distanceType via helper methods below
            ConvertPaceTypeString(expectedData, paceType);

            // run test
            ParseStrings.ParsePaceType(paceType, ref actualPaceType);

            // validate results
            Assert.AreEqual(expectedData.PaceType, actualPaceType, "Distance types differed.");
        }
Ejemplo n.º 9
0
        public void CalculateTypeTestWithSplits()
        {
            WpfVM wpf = new WpfVM();

            // get data
            wpf.Time         = Convert.ToString(TestContext.DataRow["Time"]);
            wpf.Pace         = Convert.ToString(TestContext.DataRow["Pace"]);
            wpf.Distance     = Convert.ToString(TestContext.DataRow["Distance"]);
            wpf.DistanceType = Convert.ToString(TestContext.DataRow["DistanceType"]);
            wpf.PaceType     = Convert.ToString(TestContext.DataRow["PaceType"]);
            string calcType = Convert.ToString(TestContext.DataRow["CalcType"]);
            string expected = Convert.ToString(TestContext.DataRow["Expected"]);

            wpf.SplitDistance     = "1";
            wpf.SplitDistanceType = wpf.DistanceType;
            ConvertCalcType(wpf, calcType);

            // run test without many splits first
            wpf.ShowSplitsCommand.Execute(null);

            Assert.IsTrue(wpf.SplitList.Count > 1);

            int    hours   = 0;
            int    minutes = 0;
            double seconds = 0;

            ParseStrings.ParseTimeString(wpf.Time, ref hours, ref minutes, ref seconds);

            wpf.SplitDistance = Convert.ToString(TestContext.DataRow["SplitDistance"]);

            // run test second time to verify splits get recalculated
            wpf.CalculateTypeCommand.Execute(null);

            Assert.AreEqual(1, wpf.SplitList.Count);
            Assert.AreEqual(hours, wpf.SplitList[0].Hours);
            Assert.AreEqual(minutes, wpf.SplitList[0].Minutes);
            Assert.AreEqual(seconds, wpf.SplitList[0].Seconds);
        }
Ejemplo n.º 10
0
        public void ParseTimeStringTest()
        {
            // get test data
            string  timeString      = Convert.ToString(TestContext.DataRow["timeString"]);
            int     expectedHours   = Convert.ToInt32(TestContext.DataRow["hours"]);
            int     expectedMinutes = Convert.ToInt32(TestContext.DataRow["minutes"]);
            double  expectedSeconds = Convert.ToDouble(TestContext.DataRow["seconds"]);
            Boolean expectedPass    = Convert.ToBoolean(TestContext.DataRow["expectPass"]);

            int     hours   = -1;
            int     minutes = -1;
            double  seconds = -1;
            Boolean actualPass;

            // run test
            actualPass = ParseStrings.ParseTimeString(timeString, ref hours, ref minutes, ref seconds);

            // validate results
            Assert.AreEqual(expectedPass, actualPass);
            Assert.AreEqual(expectedHours, hours, "hours differed.");
            Assert.AreEqual(expectedMinutes, minutes, "minutes differed.");
            Assert.AreEqual(expectedSeconds, seconds, "seconds differed.");
        }
Ejemplo n.º 11
0
        public Stream Search(Stream streamData)
        {
            try
            {
                StreamReader reader = new StreamReader(streamData);

                string SearchTerm = reader.ReadToEnd();

                reader.Close();
                reader.Dispose();

                NameValueCollection returnValues = ParseStrings.ParseFromStream(SearchTerm);

                var s = new JavaScriptSerializer();

                string ISO2            = returnValues.Get("ISO2");
                string UserId          = returnValues.Get("UserId");
                string SearchProfileId = returnValues.Get("SearchProfileId");
                string Coordenates     = returnValues.Get("Location");

                if (!isGuid.IsMatch(UserId) || !isGuid.IsMatch(SearchProfileId))
                {
                    string error = s.Serialize("Error IDs");
                    return(new MemoryStream(Encoding.UTF8.GetBytes(error)));
                }

                SearchModel model = new SearchModel
                {
                    Coordenate    = Coordenates,
                    SearchProfile = new SearchProfileService().GetSearchProfile(new Guid(SearchProfileId), new Guid(UserId)),
                    Terms         = null
                };

                if (model.SearchProfile == null)
                {
                    model.SearchProfile = new SearchProfileService().GetDefaultSearchProfile(new Guid(UserId));
                }


                IList <PointModel>       pointsModel = new SearchService().Search(model);
                IList <PointSimpleModel> points      = new List <PointSimpleModel>();

                pointsModel.ToList().ForEach(x => points.Add(new PointSimpleModel
                {
                    Id          = x.Id,
                    Address     = x.Address,
                    Coordenate  = x.Coordenate,
                    Name        = x.Name,
                    PhoneNumber = x.PhoneNumber,
                    PostalCode  = x.PostalCode,
                    SourceURL   = x.SourceURL,
                    TopicId     = x.Topics.FirstOrDefault().Id.ToString(),
                    URL         = x.URL
                }));

                string jsonClient = s.Serialize(points);
                WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";

                return(new MemoryStream(Encoding.UTF8.GetBytes(jsonClient)));
            }
            catch (Exception ex)
            {
                JavaScriptSerializer s = new JavaScriptSerializer();
                string error           = s.Serialize((ex.InnerException != null ? ex.InnerException.Message : ex.Message));
                return(new MemoryStream(Encoding.UTF8.GetBytes(error)));
            }
        }
Ejemplo n.º 12
0
        public void IsValidString()
        {
            var string1 = new ParseStrings("no{X}and{Y}and{X}we", null, null);

            Assert.IsTrue(true == string1.string_valid);
        }
Ejemplo n.º 13
0
        public void AreNullInputs()
        {
            var string1 = new ParseStrings("no{X}and{Y}and{X}we", null, null);

            Assert.IsTrue(false == string1.arrays_valid);
        }