Ejemplo n.º 1
0
        public void SimpleApiTest()
        {
            var stream    = new InputStream(SIMPLE_API);
            var tokenizer = new Tokenizer(stream);
            var parser    = new NebulaParser(tokenizer);
            var result    = parser.Parse("sampleModule");

            var apiNode = result.SearchByType <ApiNode>().FirstOrDefault();

            Assert.NotNull(apiNode);
            Assert.AreEqual("SimpleApi", apiNode.Name);

            var config = apiNode.SearchByType <ConfigNode>().FirstOrDefault();

            Assert.NotNull(config);
            var configNodes = config.Nodes;

            Assert.AreEqual(3, configNodes.Count);

            var functions = apiNode.SearchByType <FunctionNode>();

            Assert.AreEqual(1, functions.Count);

            var func = functions.FirstOrDefault();

            Assert.NotNull(func);
            Assert.AreEqual("getDevices", func.Name);
            Assert.AreEqual(TokenType.GetFunction, func.Method);
            Assert.AreEqual("/devices", func.Url);
            Assert.AreEqual("array", func.ReturnType.Name);
            Assert.IsTrue(func.ReturnType.Generic);
            Assert.AreEqual("Device", func.ReturnType.GenericType);
        }
Ejemplo n.º 2
0
        private ModuleNode BuildModule(string inputFile)
        {
            _buildCount++;
            _buildProgress = Math.Floor((_buildCount / _totalFiles) * 100);
            Console.WriteLine($"[{_buildCount}/{_totalFiles} ({_buildProgress}%)] Processing {inputFile}");
            var moduleName   = inputFile.Replace(Path.DirectorySeparatorChar, '.').Replace(".neb", "");
            var absoluteFile = Path.Combine(_currentProject.SourceDirectory, inputFile);
            var parser       = new NebulaParser(absoluteFile);

            return(parser.Parse(moduleName));
        }
Ejemplo n.º 3
0
        public void EntityFieldTest()
        {
            var stream    = new InputStream(SIMPLE_ENTITY);
            var tokenizer = new Tokenizer(stream);
            var parser    = new NebulaParser(tokenizer);
            var result    = parser.Parse("sampleModule");

            var fields = result.SearchByType <ArgumentNode>();

            Assert.AreEqual(1, fields.Count);
        }
Ejemplo n.º 4
0
        public void ComplexEntityTest()
        {
            var stream    = new InputStream(COMPLEX_ENTITIES);
            var tokenizer = new Tokenizer(stream);
            var parser    = new NebulaParser(tokenizer);
            var result    = parser.Parse("sampleModule");

            var entities = result.SearchByType <EntityNode>();

            Assert.AreEqual(2, entities.Count);
            var complexDeviceNode = entities.FirstOrDefault(e => e.Name == "ComplexDevice");

            Assert.NotNull(complexDeviceNode);
            Assert.AreEqual(4, complexDeviceNode.Fields.Count);
            var complexDeviceHistoryNode = entities.FirstOrDefault(e => e.Name == "ComplexDeviceHistory");

            Assert.NotNull(complexDeviceHistoryNode);
            Assert.AreEqual(2, complexDeviceHistoryNode.Fields.Count);
        }
Ejemplo n.º 5
0
        public void ComplexApiTest()
        {
            var stream    = new InputStream(COMPLEX_API);
            var tokenizer = new Tokenizer(stream);
            var parser    = new NebulaParser(tokenizer);
            var result    = parser.Parse("sampleModule");

            var api = result.SearchByType <ApiNode>().FirstOrDefault();

            Assert.NotNull(api);
            var funcs = result.SearchByType <FunctionNode>();

            Assert.AreEqual(3, funcs.Count);
            var getDevicesFunc = funcs.FirstOrDefault(f => f.Name == "getDevices");

            Assert.NotNull(getDevicesFunc);
            Assert.AreEqual("/devices", getDevicesFunc.Url);
            Assert.AreEqual(TokenType.GetFunction, getDevicesFunc.Method);
        }
Ejemplo n.º 6
0
        public void SimpleEntityTest()
        {
            var stream    = new InputStream(SIMPLE_ENTITY);
            var tokenizer = new Tokenizer(stream);
            var parser    = new NebulaParser(tokenizer);
            var result    = parser.Parse("sampleModule");

            Assert.IsAssignableFrom(typeof(ModuleNode), result);
            Assert.AreEqual("sampleModule", result.Name);

            var entityNodes = result.SearchByType <EntityNode>();

            Assert.AreEqual(1, entityNodes.Count);
            Assert.IsAssignableFrom(typeof(EntityNode), entityNodes.FirstOrDefault());

            var deviceNode = entityNodes.FirstOrDefault();

            Assert.NotNull(deviceNode);
        }