public void TestQuerableParameters()
        {
            string code = @"
select faFlightID
from GetFlightId
where ident = 'DAL503' and departuretime = '2020-3-7 9:15'
";

            var mock = new Mock <IHttpExecutor>();

            mock.Setup(x => x.GetFlightID(It.IsAny <HttpExecuteArg>())).Callback <HttpExecuteArg>(args =>
            {
                Assert.IsTrue(args.Variables.Count() == 2);
                var start = args.Variables.Where(x => x.Variable == "ident").SingleOrDefault();
                Assert.IsTrue(start != null);
                Assert.IsTrue(start.Value == "DAL503");

                var end = args.Variables.Where(x => x.Variable == "departureTime").SingleOrDefault();
                Assert.IsTrue(end.Value == "1583572500");
            }).Returns(() => new ApiExecuteResult <GetFlightId>(new GetFlightId()));

            var context = RunContext.CreateSemanticContext(code, mock.Object);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 0);
            mock.Verify(v => v.GetFlightID(It.IsAny <HttpExecuteArg>()), Times.Once());
        }
        public void TestDepartureTimeGreaterThanPropertyLeft()
        {
            string code = @"
select arrivaltime, aircrafttype
from AirlineFlightSchedules a
where departuretime > '2020-3-7 9:15'
";
            var    mock = new Mock <IHttpExecutorRaw>();

            mock.Setup(x => x.GetAirlineFlightSchedule(It.IsAny <HttpExecuteArg>())).Callback <HttpExecuteArg>(args =>
            {
                Assert.IsTrue(args.Variables.Count() == 2);
                var start = args.Variables.Where(x => x.Variable == "startDate").SingleOrDefault();
                Assert.IsTrue(start != null);
                Assert.IsTrue(start.Value == "1583572500");

                var end = args.Variables.Where(x => x.Variable == "endDate").SingleOrDefault();
                Assert.IsTrue(end.Value == "1584177300");
            });

            var context = RunContext.CreateSemanticContext(code, new HttpExecutor(mock.Object));

            context.Run();

            mock.Verify(v => v.GetAirlineFlightSchedule(It.IsAny <HttpExecuteArg>()), Times.Once());
        }
        public void TestQuerableParameters()
        {
            string code = @"
select diverted
from FlightInfoEx
where faFlightID = 'some-flight-number'
";

            var mock = new Mock <IHttpExecutor>();

            mock.Setup(x => x.GetFlightInfoEx(It.IsAny <HttpExecuteArg>())).Callback <HttpExecuteArg>(args =>
            {
                Assert.IsTrue(args.Variables.Count() == 1);
                var ident = args.Variables.Where(x => x.Variable == "ident").SingleOrDefault();
                Assert.IsTrue(ident != null);
                Assert.IsTrue(ident.Value == "some-flight-number");
            }).Returns(() => new ApiExecuteResult <IEnumerable <FlightInfoEx> >(new FlightInfoEx[] { new FlightInfoEx() }));

            var context = RunContext.CreateSemanticContext(code, mock.Object);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 0);
            mock.Verify(x => x.GetFlightInfoEx(It.IsAny <HttpExecuteArg>()), Times.Once());
        }
示例#4
0
        public void NoFrom()
        {
            string code = @"
select * asdfsad
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
        }
示例#5
0
        public void WrongSelectParamsSytax()
        {
            string code = @"
select asdf, 
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
        }
        public void TestMissingRequired()
        {
            string code    = @"
select faFlightID
from GetFlightId
where ident = 'DAL503'
";
            var    context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "departureTime is required");
        }
        public void TestMissingRequired()
        {
            string code    = @"
select diverted
from FlightInfoEx
where filed_ete = 'whatever'
";
            var    context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "faFlightID is required");
        }
示例#8
0
        public void TestRequiredAirportCode()
        {
            string code = @"
select location
from AirportInfo 
where location = 'kaus'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "airportCode is required");
        }
        public void TestRequiredDepartureTime()
        {
            string code = @"
select arrivaltime, aircrafttype
from AirlineFlightSchedules
where origin = 'katl'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "departuretime is required");
        }
示例#10
0
        public void TestAmbiguousVariableInJoin()
        {
            string code = @"
select a.ident, faFlightID
from AirlineFlightSchedules a
join GetFlightId f on ident = a.ident and f.departureTime = a.departureTime 
where a.departuretime < '2020-3-7 9:15' and a.origin = 'katl'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 2);
            Assert.IsTrue(context.Errors[0].Message == "ident is ambiguous at line=4, column=22");
        }
示例#11
0
        public void TestInvalidAliasinSelect()
        {
            string code = @"
select f.ident, f.departuretime, f.arrivaltime, a.airportCode
from airlineflightschedules f
join airportinfo d on d.airportCode = f.destination
where f.departuretime > '2020-4-13 2:8' and f.origin = 'kaus'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "a variable not found at line=2, column=48");
        }
示例#12
0
        public void TestAmbiguousVariableInWhere()
        {
            string code = @"
select a.ident, o.faFlightID
from airlineflightschedules a
join getflightid o on o.ident = a.ident and o.departuretime = a.departuretime
where departuretime > '2020-4-10 1:00' and origin = 'kaus'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "departuretime is ambiguous at line=5, column=6");
        }
示例#13
0
        public void TestJoinConditionInWhereNoError()
        {
            string code = @"
select *
from airlineflightschedules a
join getflightid f on f.departureTime = a.departuretime and f.ident = a.ident
join flightinfoex e on e.faFlightID = f.faFlightID 
where a.departuretime > '2020-4-14 1:31' and a.origin = 'kaus' and e.actualarrivaltime = 0 and e.actualdeparturetime != 0
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 0);
        }
        public void FlightIdRequiredJoin()
        {
            string code = @"
select *   
from airlineflightschedules a
join getflightid i on i.departureTime = a.departuretime and a.ident = i.ident
join FlightInfoEx f on i.faFlightID = f.destination
where a.departuretime > '2020-4-10 8:00' and a.origin = 'kaus'
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();
            Assert.IsTrue(context.Errors.Count == 1);
            Assert.IsTrue(context.Errors[0].Message == "faFlightID is required");
        }
示例#15
0
        public void TestInvalidWhereVariable()
        {
            string code = @"
select arrivaltime, aircrafttype
from AirlineFlightSchedules
where blah < 55
";

            var context = RunContext.CreateSemanticContext(code);

            context.Run();

            Assert.IsTrue(context.Errors.Count == 2);

            Assert.IsTrue(context.Errors[0].Message == "departuretime is required");
            Assert.IsTrue(context.Errors[1].Message == "blah variable not found at line=4, column=6");
        }
        public void TestQuerableParameters()
        {
            string code = @"
select arrivaltime, aircrafttype
from AirlineFlightSchedules a
where '2020-3-7 9:15' > a.departuretime and origin = 'kaus' and destination = 'kpdx' and ident = 'UAL6879'
";
            var    mock = new Mock <IHttpExecutorRaw>();

            mock.Setup(x => x.GetAirlineFlightSchedule(It.IsAny <HttpExecuteArg>())).Callback <HttpExecuteArg>(args =>
            {
                Assert.IsTrue(args.Variables.Count() == 6);
                var start = args.Variables.Where(x => x.Variable == "startDate").SingleOrDefault();
                Assert.IsTrue(start != null);
                Assert.IsTrue(start.Value == "1582967700");

                var end = args.Variables.Where(x => x.Variable == "endDate").SingleOrDefault();
                Assert.IsTrue(end.Value == "1583572500");

                Assert.IsTrue(args.Variables.Where(x => x.Variable == "origin").Count() == 1);
                Assert.IsTrue(args.Variables.Where(x => x.Variable == "origin").Select(x => x.Value).Single() == "KAUS");

                Assert.IsTrue(args.Variables.Where(x => x.Variable == "destination").Count() == 1);
                Assert.IsTrue(args.Variables.Where(x => x.Variable == "destination").Select(x => x.Value).Single() == "KPDX");

                Assert.IsTrue(args.Variables.Where(x => x.Variable == "airline").Count() == 1);
                Assert.IsTrue(args.Variables.Where(x => x.Variable == "airline").Select(x => x.Value).Single() == "UAL");

                Assert.IsTrue(args.Variables.Where(x => x.Variable == "flightno").Count() == 1);
                Assert.IsTrue(args.Variables.Where(x => x.Variable == "flightno").Select(x => x.Value).Single() == "6879");
            });

            var context = RunContext.CreateSemanticContext(code, new HttpExecutor(mock.Object));

            context.Run();

            mock.Verify(v => v.GetAirlineFlightSchedule(It.IsAny <HttpExecuteArg>()), Times.Once());
        }