Exemple #1
0
        //[TestMethod]
        public async Task ICmdTest()
        {
            //Valid
            ICmd validICmd = new ICmd(testServer, ValidSerialNumbers.getAll()[0]);
            //Invalid
            ICmd invalidICmd = new ICmd(testServer, "No beef like dead beef");
            //Missing
            ICmd missingICmd = new ICmd(testServer, null);

            Test validTest   = new Test(validICmd);
            Test invalidTest = new Test(invalidICmd);
            Test missingTest = new Test(missingICmd);

            /*
             * DeviceScanJSON testJson = new DeviceScanJSON ();
             * testJson.i = ValidSerialNumbers.getAll()[1];
             * testJson.d = "ayyy lmao";
             * testJson.s = 4;
             * DeviceScan testDScan = new DeviceScan(testServer, testJson);
             * Test ayyyTest = new Test(testDScan);
             */

            List <Test> tests = new List <Test>();

            tests.Add(validTest);
            tests.Add(invalidTest);
            tests.Add(missingTest);

            await Program.buildTests(tests);

            foreach (Test nextTest in Program.tests)
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        //TODO: set up all param types
        //Unimplemented types will fail
        //Maybe make this throw an error of some sort if false?
        public bool isValid()
        {
            switch (param)
            {
            case QueryParameter.i:
                foreach (string nextSerialNumber in ValidSerialNumbers.getAll())
                {
                    if (value == null)
                    {
                        return(false);
                    }
                    if (value.Equals(nextSerialNumber))
                    {
                        return(true);
                    }
                }
                Console.WriteLine("Invalid device serial number");
                return(false);

            case QueryParameter.intId:
                Console.WriteLine("You didn't set this query type up yet...");
                return(false);

            case QueryParameter.locId:
                Console.WriteLine("You didn't set this query type up yet...");
                return(false);

            case QueryParameter.orgId:
                Console.WriteLine("You didn't set this query type up yet...");
                return(false);

            case QueryParameter.startDate:
                Console.WriteLine("You didn't set this query type up yet...");
                return(false);

            case QueryParameter.stopDate:
                Console.WriteLine("You didn't set this query type up yet...");
                return(false);

            default:
                Console.WriteLine("Query is not of a valid type!");
                return(false);
            }
        }
        public static async Task buildTests(List <Test> uTests)
        {
            //Init globals
            results       = new StreamWriter(outputFile);
            tests         = new List <Test>();
            serialNumbers = ValidSerialNumbers.getAll();

            //Setup vars
            seconds = 0;

            //Init tasks / asynchronous magic
            Task t;

            //Timer ticks once every decisecond (100 miliseconds)
            time = new Timer(100);
            // Hook up the Elapsed event for the timer.
            time.Elapsed += OnTimedEvent;
            time.Enabled  = true;

            //Load and run all test cases
            tests = uTests;

            foreach (Test nextTest in tests)
            {
                Console.WriteLine("Test #" + tests.IndexOf(nextTest) + ":");
                results.WriteLine("Test #" + tests.IndexOf(nextTest) + ":");
                await runTest(nextTest);
            }

            //Shut 'er down!
            Console.WriteLine("Tests complete!");
            //Hold up at the end so console output can actually be read. Also not crash everything because async is balls
            //Console.ReadLine();
            Console.WriteLine("Closing writer...");
            results.Close();
            Console.WriteLine("Writer closed!");
        }
Exemple #4
0
        //Unimplemented types will fail
        //Maybe make this throw an error of some sort if false?
        public bool isValid()
        {
            switch (param)
            {
            //TODO: Find out a better way to determine IDs - existence != validity
            case QueryParameter.i:
                foreach (string nextSerialNumber in ValidSerialNumbers.getAll())
                {
                    if (value == null)
                    {
                        return(false);
                    }
                    if (value.Equals(nextSerialNumber))
                    {
                        return(true);
                    }
                }
                Console.WriteLine("Invalid device serial number");
                return(false);

            case QueryParameter.intId:
                foreach (string nextId in ValidIntIds.getAll())
                {
                    if (value == null)
                    {
                        return(false);
                    }
                    if (value.Equals(nextId))
                    {
                        return(true);
                    }
                }
                return(false);

            case QueryParameter.locId:
                foreach (string nextId in ValidLocIds.getAll())
                {
                    if (value == null)
                    {
                        return(false);
                    }
                    if (value.Equals(nextId))
                    {
                        return(true);
                    }
                }
                return(false);

            case QueryParameter.orgId:
                foreach (string nextId in ValidOrgIds.getAll())
                {
                    if (value == null)
                    {
                        return(false);
                    }
                    if (value.Equals(nextId))
                    {
                        return(true);
                    }
                }
                return(false);

            default:
                Console.WriteLine("Query is not of a valid type!");
                return(false);
            }
        }