Ejemplo n.º 1
0
        public static int Run(string[] args)
        {
            var sw = Stopwatch.StartNew();

            int loadResult = LoadOptions(args);

            if (loadResult != 0)
            {
                return(loadResult);
            }

            _basePath = AbsolutePath(_options.Source);
            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;            // Look in the base path for referenced .dll files instead of the startup path

            Console.Write("Scanning for DTO objects in {0}...  ", _basePath);
            var apiControllers   = GetApiControllers(_basePath);
            var controllerModels = new HashSet <Type>(apiControllers.SelectMany(GetModelsFromController));           // return and parameter models
            var allModels        = GetAllModelsToGenerate(controllerModels);

            Console.WriteLine("Found {0}", allModels.Count);

            var targetPath = AbsolutePath(_options.Destination);
            // Invoke all generators and pass the results to the index generator
            var allGeneratedNames = IndexGenerator.Generate(targetPath,
                                                            EntityGenerator.Generate(targetPath, allModels, _options),
                                                            DataServiceGenerator.Generate(apiControllers, controllerModels, targetPath, _options)
                                                            );

            RemoveNonGeneratedFiles(targetPath, allGeneratedNames);

            Console.WriteLine("Done in {0:N3}s", sw.Elapsed.TotalSeconds);
            return(0);
        }
Ejemplo n.º 2
0
        public void ExpandFromUriParameters_DatesConsideredPrimitives()
        {
            // Note: There was a bug where ([FromUri] DateTime dt) parameters would be expanded to have all of the DateTime properties
            //       This was not the desired behavior and was especially bad when there were two DateTime parameters (e.g. startDate, endDate)
            //       because it would cause all of those property names to be duplicated which would cause the TypeScript build to fail.
            //       This test ensures that only a single parameter will be emitted.

            ParameterInfo[] parameters = typeof(ExpandUriParametersClass).GetMethod("Foo").GetParameters();

            var result = DataServiceGenerator.ExpandFromUriParameters(parameters);

            Assert.AreEqual(1, result.Length, "Expected one result");
            Assert.AreEqual(typeof(DateTime), result[0].ParameterType, nameof(DataServiceGenerator.ParameterEssentials.ParameterType));
        }